Authen-SASL-Cyrus

 view release on metacpan or  search on metacpan

Cyrus.xs  view on Meta::CPAN

     }
   }

    sasl_client_init(NULL);
#ifdef SASL2
    sasl->code = sasl_client_new(sasl->service, sasl->server, 0, 0, sasl->callbacks, 1, &sasl->conn);
#else
    sasl->code = sasl_client_new(sasl->service, sasl->server, sasl->callbacks, 1, &sasl->conn);
#endif

    if (sasl->code != SASL_OK) {
      if (!sasl->errormsg) sasl->errormsg = SASL_ERR("sasl_client_new failed");
    }
    else {
#ifdef SASL2
      sasl->code = sasl_client_start(sasl->conn, sasl->mech, NULL, &init, &initlen, &mech);
#else
      sasl->code = sasl_client_start(sasl->conn, sasl->mech, NULL, NULL, &init, &initlen, &mech);
#endif
      if (sasl->code == SASL_NOMECH) {
        if (!sasl->errormsg)
          sasl->errormsg = "No mechanisms available (did you set all needed callbacks?)";
      }
      else if ((sasl->code != SASL_OK) && (sasl->code != SASL_CONTINUE)) {
        if (!sasl->errormsg) sasl->errormsg = SASL_ERR("sasl_client_start failed");
      }
      else {
#ifdef SASL2
        memset(&ssp, 0, sizeof(ssp));
        ssp.maxbufsize = 0xFFFF;
        ssp.max_ssf = 0xFF;
        sasl_setprop(sasl->conn, SASL_SEC_PROPS, &ssp);
#endif
        if (init) {
          New(23, sasl->initstring, initlen, char);
          if (sasl->initstring) {
            memcpy(sasl->initstring, init, initlen);
            sasl->initstringlen = initlen;
          }
          else {
            sasl->code = SASL_FAIL;
            if (!sasl->errormsg) sasl->errormsg = "Out of memory in client_new()";
            sasl->initstringlen = 0;
          }
        }
      }
    }
    RETVAL = sasl;
  }
  OUTPUT:
    RETVAL






char *
client_start(sasl)
    struct authensasl *sasl
  PPCODE:
  {
    XPUSHp(sasl->initstring, sasl->initstringlen);
  }





char *
client_step(sasl, instring)
    struct authensasl *sasl
    char *instring
  PPCODE:
  {
    SASLCONST char *outstring=NULL;
    unsigned int inlen, outlen=0;

    if (sasl->errormsg) {
      XSRETURN_EMPTY;
    }
    SvPV(ST(1),inlen);
    sasl->code = sasl_client_step(sasl->conn, instring, inlen, NULL, &outstring, &outlen);
    if (sasl->code == SASL_OK) {
      sasl->errormsg = NULL;
    }
    else if (sasl->code != SASL_CONTINUE) {
      if (!sasl->errormsg) sasl->errormsg = SASL_ERR("sasl_client_step failed");
      XSRETURN_EMPTY;
    }
    XPUSHp(outstring, outlen);
  }




char *
encode(sasl, instring)
    struct authensasl *sasl
    char *instring
  PPCODE:
  {
    SASLCONST char *outstring=NULL;
    unsigned int inlen, outlen=0;


    if (sasl->errormsg) {
      XSRETURN_UNDEF;
    }
    instring = SvPV(ST(1),inlen);

    sasl->code = sasl_encode(sasl->conn, instring, inlen, &outstring, &outlen);
    if (sasl->code != SASL_OK) {
      if (!sasl->errormsg) sasl->errormsg = SASL_ERR("sasl_encode failed");
      XSRETURN_UNDEF;
    }
    XPUSHp(outstring, outlen);
  }




char *
decode(sasl, instring)
    struct authensasl *sasl
    char *instring
  PPCODE:
  {
    SASLCONST char *outstring=NULL;
    unsigned int inlen, outlen=0;


    if (sasl->errormsg) {
       XSRETURN_UNDEF;
    }

    instring = SvPV(ST(1),inlen);
    sasl->code = sasl_decode(sasl->conn, instring, inlen, &outstring, &outlen);
    if (sasl->code != SASL_OK) {
      if (!sasl->errormsg) sasl->errormsg = SASL_ERR("sasl_decode failed");
      XSRETURN_UNDEF;
    }
    XPUSHp(outstring, outlen);
  }





int
callback(sasl, ...)
    struct authensasl *sasl
  CODE:
  {
    SV *action;
    char *name;
    int x, count;
    struct _perlcontext *pcb;


    /* Asking if a given callback exists */
    if (items == 2) {
      RETVAL = 0;
      if (sasl->callbacks) {
        name = SvPV_nolen(ST(1));
        x = CallbackNumber(name);

        /* Check the installed callbacks for the requested ID */
        for (count=0; sasl->callbacks[count].id != SASL_CB_LIST_END; count++) {
          if (sasl->callbacks[count].id == x) {
            RETVAL = 1;
            break;
          }
        }
      }
    }
    else {
      /* Prepare space for the callback list */
      free_callbacks(sasl);
      count = (items - 1) / 2;
      pcb = alloc_callbacks(sasl, count);

      /* Fill in the callbacks */
      for(x=0; x<count; x++) {
        /* Convert the callback name into a SASL ID number */
        if (SvTYPE(ST(1+x*2)) != SVt_PV) {
          croak("callbacks: Unknown key given in position %d\n", x);

Cyrus.xs  view on Meta::CPAN

  OUTPUT:
    RETVAL


char *
mechanism(sasl)
    struct authensasl *sasl
  CODE:
    RETVAL = sasl->mech;
  OUTPUT:
    RETVAL



char *
host(sasl, ...)
    struct authensasl *sasl
  CODE:
    if (items > 1) {
      if (sasl->server) Safefree(sasl->server);
      sasl->server = savepv(SvPV_nolen(ST(1)));
    }
    RETVAL = sasl->server;
  OUTPUT:
    RETVAL



char *
user(sasl, ...)
    struct authensasl *sasl
  CODE:
    if (items > 1) {
      if (sasl->user) Safefree(sasl->user);
      sasl->user = savepv(SvPV_nolen(ST(1)));
    }
    RETVAL = sasl->user;
  OUTPUT:
    RETVAL



char *
service(sasl, ...)
    struct authensasl *sasl
  CODE:
    if (items > 1) {
      if (sasl->service) Safefree(sasl->service);
      sasl->service = savepv(SvPV_nolen(ST(1)));
    }
    RETVAL = sasl->service;
  OUTPUT:
    RETVAL




int
property(sasl, ...)
    struct authensasl *sasl
  PPCODE:
  {
    SASLCONST void *value=NULL;
    STRLEN proplen;
    char *name, buf[32];
    int x, propnum=-1;
    SV *prop;


    RETVAL = 0;

    if (!sasl->conn) {
      if (!sasl->errormsg) sasl->errormsg="sasl_setproperty called on uninitialized connection";
      RETVAL = 1;
      items = 0;
    }

    /* Querying the value of a property */
    if (items == 2) {
      name = SvPV_nolen(ST(1));
      propnum = PropertyNumber(name);
      sasl->code = sasl_getprop(sasl->conn, propnum, &value);
      if (sasl->code != SASL_OK) XSRETURN_UNDEF;
      switch(propnum){
        case SASL_USERNAME:
#ifdef SASL2
        case SASL_DEFUSERREALM:
#else
        case SASL_REALM:
#endif
          XPUSHp( (char *)value, strlen((char *)value));
          break;
        case SASL_SSF:
        case SASL_MAXOUTBUF:
          XPUSHi(*(int *)value);
          break;
#ifdef SASL2
        case SASL_IPLOCALPORT:
        case SASL_IPREMOTEPORT:
          XPUSHp( (char *)value, strlen((char *)value));
          break;
#else
        case SASL_IP_LOCAL:
        case SASL_IP_REMOTE:
          XPUSHp( (char *)value, sizeof(struct sockaddr_in));
          break;
#endif
        default:
          XPUSHi(-1);
      }
      XSRETURN(1);
    }

    /* Fill in the properties */
    for(x=1; x<items; x+=2) {

      prop = ST(x);
      value = (void *)SvPV( ST(x+1), proplen );

      if (SvTYPE(prop) == SVt_IV) {
        propnum = SvIV(prop);



( run in 1.302 second using v1.01-cache-2.11-cpan-71847e10f99 )