Re: imclient_authenticate wrong prompt order.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



mandag den 26. september 2016 15.51.45 CEST skrev Dan White:
On 09/24/16 17:28 +0200, jesper--- via Info-cyrus wrote:
The following sample prompts for entering the password after ones actually
did enter the password. 1) Why is that e.g why does this sample write
"please enter your password: " after the password is entered, and then
exits?

The authentication works. Only the prompting is a problem. ...

Have a look at doc/programming.html#callbacks_interactions within the cyrus
sasl source.
Thanks for the hint.
Can you provide an example which includes callbacks that is
not working as expected?
No I could not.

For reference I came up with the following:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <cyrus/imclient.h>

static int getsecret_func(sasl_conn_t *conn,
     void *context __attribute__((unused)),
     int id,
     sasl_secret_t **psecret);
static struct imclient *imclient;

   static int getauthname_func(void *context,
                               int id,
                               const char **result,
                               unsigned *len);
void fatal(const char *s, int code)
{
 fprintf(stderr, "Fatal error: %s\n", s);
} /* callbacks we support. This is a global variable at the top of the program */
   static sasl_callback_t callbacks[] = {
   {
SASL_CB_GETREALM, NULL, NULL/* we'll just use an interaction if this comes up */
   }, {
SASL_CB_USER, NULL, NULL /* we'll just use an interaction if this comes up */
   }, {
SASL_CB_AUTHNAME, &getauthname_func, NULL /*A mechanism should call getauthname_func if it needs the authentication name */ },{ SASL_CB_PASS, &getsecret_func, NULL /* Call getsecret_func if need secret */
   }, {
     SASL_CB_LIST_END, NULL, NULL
   }
   };


   static int getsecret_func(sasl_conn_t *conn,
     void *context __attribute__((unused)),
     int id,
     sasl_secret_t **psecret)
   {
   *psecret = malloc(sizeof(sasl_secret_t)+7);

  char * secret = "cyrus\0";
*psecret = malloc(sizeof(sasl_secret_t*)+strlen(secret)+1);
      static sasl_secret_t *x;

x = (sasl_secret_t *) realloc(x, sizeof(sasl_secret_t) + strlen(secret)); memcpy(x->data,secret,sizeof(sasl_secret_t)+strlen(secret)+1); x->len=strlen(secret);
   *psecret = x;
return SASL_OK;
   }

   static int getauthname_func(void *context,
                               int id,
                               const char **result,
                               unsigned *len)
   {
      if (id!=SASL_CB_AUTHNAME) return SASL_FAIL;

      char *authname = "cyrus\0";
      *result = malloc(sizeof(char)*strlen(authname)+1);
      *result = authname;
       unsigned length =strlen(authname); ;	
        len=&length;
return SASL_OK;
    }


char server[] = "localhost" ;
char port[] = "imap";
char mech[] ="CRAM-MD5";
char service[] = "imap";

int main() {
    if(imclient_connect(&imclient, server, port,callbacks)) {
    fprintf(stderr,
    "error: Couldn't connect to %s %s\n",
     server, port);
    }
if(imclient_authenticate(imclient, mech,service,NULL, 0,256)) {
    fprintf(stderr,
    "error: Authentication failed");
}

return 0;
}



----
Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus



[Index of Archives]     [Cyrus SASL]     [Squirrel Mail]     [Asterisk PBX]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [KDE]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux