1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
|
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <sasl.h>
static int err; /* Our last error code */
static int
not_here(char *s)
{
croak("%s not implemented on this architecture", s);
return -1;
}
static int _sasl_callback(void *context, int id, const char **result, unsigned *len)
{
const char *value = (const char *)context;
if (! result)
return SASL_BADPARAM;
switch (id) {
case SASL_CB_USER:
*result = value;
if (len)
*len = value ? strlen(value) : 0;
break;
default:
return SASL_BADPARAM;
}
return SASL_OK;
}
static int _sasl_getpass(sasl_conn_t *conn,
void *context, int id,
sasl_secret_t **secret) {
if (id != SASL_CB_PASS) return SASL_BADPARAM;
return SASL_FAIL;
}
static double
constant(char *name, int arg)
{
errno = 0;
switch (*name) {
case 'A':
break;
case 'B':
break;
case 'C':
break;
case 'D':
break;
case 'E':
break;
case 'F':
break;
case 'G':
break;
case 'H':
break;
case 'I':
break;
case 'J':
break;
case 'K':
break;
case 'L':
break;
case 'M':
break;
case 'N':
break;
case 'O':
break;
case 'P':
break;
case 'Q':
break;
case 'R':
break;
case 'S':
if (strEQ(name, "SASL_BADAUTH"))
#ifdef SASL_BADAUTH
return SASL_BADAUTH;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_BADMAC"))
#ifdef SASL_BADMAC
return SASL_BADMAC;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_BADPARAM"))
#ifdef SASL_BADPARAM
return SASL_BADPARAM;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_BADPROT"))
#ifdef SASL_BADPROT
return SASL_BADPROT;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_BADSERV"))
#ifdef SASL_BADSERV
return SASL_BADSERV;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_BADVERS"))
#ifdef SASL_BADVERS
return SASL_BADVERS;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_BUFOVER"))
#ifdef SASL_BUFOVER
return SASL_BUFOVER;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_AUTHNAME"))
#ifdef SASL_CB_AUTHNAME
return SASL_CB_AUTHNAME;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_ECHOPROMPT"))
#ifdef SASL_CB_ECHOPROMPT
return SASL_CB_ECHOPROMPT;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_GETOPT"))
#ifdef SASL_CB_GETOPT
return SASL_CB_GETOPT;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_GETPATH"))
#ifdef SASL_CB_GETPATH
return SASL_CB_GETPATH;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_GETREALM"))
#ifdef SASL_CB_GETREALM
return SASL_CB_GETREALM;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_LANGUAGE"))
#ifdef SASL_CB_LANGUAGE
return SASL_CB_LANGUAGE;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_LIST_END"))
#ifdef SASL_CB_LIST_END
return SASL_CB_LIST_END;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_LOG"))
#ifdef SASL_CB_LOG
return SASL_CB_LOG;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_NOECHOPROMPT"))
#ifdef SASL_CB_NOECHOPROMPT
return SASL_CB_NOECHOPROMPT;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_PASS"))
#ifdef SASL_CB_PASS
return SASL_CB_PASS;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_PROXY_POLICY"))
#ifdef SASL_CB_PROXY_POLICY
return SASL_CB_PROXY_POLICY;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_SERVER_GETSECRET"))
#ifdef SASL_CB_SERVER_GETSECRET
return SASL_CB_SERVER_GETSECRET;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_SERVER_PUTSECRET"))
#ifdef SASL_CB_SERVER_PUTSECRET
return SASL_CB_SERVER_PUTSECRET;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_USER"))
#ifdef SASL_CB_USER
return SASL_CB_USER;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CB_VERIFYFILE"))
#ifdef SASL_CB_VERIFYFILE
return SASL_CB_VERIFYFILE;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_CONTINUE"))
#ifdef SASL_CONTINUE
return SASL_CONTINUE;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_DISABLED"))
#ifdef SASL_DISABLED
return SASL_DISABLED;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_ENCRYPT"))
#ifdef SASL_ENCRYPT
return SASL_ENCRYPT;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_EXPIRED"))
#ifdef SASL_EXPIRED
return SASL_EXPIRED;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_FAIL"))
#ifdef SASL_FAIL
return SASL_FAIL;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_GETOPTCTX"))
#ifdef SASL_GETOPTCTX
return SASL_GETOPTCTX;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_H"))
#ifdef SASL_H
return SASL_H;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_INTERACT"))
#ifdef SASL_INTERACT
return SASL_INTERACT;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_IP_LOCAL"))
#ifdef SASL_IP_LOCAL
return SASL_IP_LOCAL;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_IP_REMOTE"))
#ifdef SASL_IP_REMOTE
return SASL_IP_REMOTE;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_LOG_ERR"))
#ifdef SASL_LOG_ERR
return SASL_LOG_ERR;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_LOG_INFO"))
#ifdef SASL_LOG_INFO
return SASL_LOG_INFO;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_LOG_WARNING"))
#ifdef SASL_LOG_WARNING
return SASL_LOG_WARNING;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_MAXOUTBUF"))
#ifdef SASL_MAXOUTBUF
return SASL_MAXOUTBUF;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_MECHNAMEMAX"))
#ifdef SASL_MECHNAMEMAX
return SASL_MECHNAMEMAX;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_NEWSECRET"))
#ifdef SASL_NEWSECRET
return SASL_NEWSECRET;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_NOAUTHZ"))
#ifdef SASL_NOAUTHZ
return SASL_NOAUTHZ;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_NOCHANGE"))
#ifdef SASL_NOCHANGE
return SASL_NOCHANGE;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_NOMECH"))
#ifdef SASL_NOMECH
return SASL_NOMECH;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_NOMEM"))
#ifdef SASL_NOMEM
return SASL_NOMEM;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_NOPATH"))
#ifdef SASL_NOPATH
return SASL_NOPATH;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_NOTDONE"))
#ifdef SASL_NOTDONE
return SASL_NOTDONE;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_NOUSER"))
#ifdef SASL_NOUSER
return SASL_NOUSER;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_OK"))
#ifdef SASL_OK
return SASL_OK;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_PWLOCK"))
#ifdef SASL_PWLOCK
return SASL_PWLOCK;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_REALM"))
#ifdef SASL_REALM
return SASL_REALM;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SECURITY_LAYER"))
#ifdef SASL_SECURITY_LAYER
return SASL_SECURITY_LAYER;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SEC_FORWARD_SECRECY"))
#ifdef SASL_SEC_FORWARD_SECRECY
return SASL_SEC_FORWARD_SECRECY;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SEC_NOACTIVE"))
#ifdef SASL_SEC_NOACTIVE
return SASL_SEC_NOACTIVE;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SEC_NOANONYMOUS"))
#ifdef SASL_SEC_NOANONYMOUS
return SASL_SEC_NOANONYMOUS;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SEC_NODICTIONARY"))
#ifdef SASL_SEC_NODICTIONARY
return SASL_SEC_NODICTIONARY;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SEC_NOPLAINTEXT"))
#ifdef SASL_SEC_NOPLAINTEXT
return SASL_SEC_NOPLAINTEXT;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SEC_PASS_CREDENTIALS"))
#ifdef SASL_SEC_PASS_CREDENTIALS
return SASL_SEC_PASS_CREDENTIALS;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SEC_PROPS"))
#ifdef SASL_SEC_PROPS
return SASL_SEC_PROPS;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SET_CREATE"))
#ifdef SASL_SET_CREATE
return SASL_SET_CREATE;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SET_DISABLE"))
#ifdef SASL_SET_DISABLE
return SASL_SET_DISABLE;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SSF"))
#ifdef SASL_SSF
return SASL_SSF;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_SSF_EXTERNAL"))
#ifdef SASL_SSF_EXTERNAL
return SASL_SSF_EXTERNAL;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_TOOWEAK"))
#ifdef SASL_TOOWEAK
return SASL_TOOWEAK;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_TRANS"))
#ifdef SASL_TRANS
return SASL_TRANS;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_TRYAGAIN"))
#ifdef SASL_TRYAGAIN
return SASL_TRYAGAIN;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_USERNAME"))
#ifdef SASL_USERNAME
return SASL_USERNAME;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_VERSION_MAJOR"))
#ifdef SASL_VERSION_MAJOR
return SASL_VERSION_MAJOR;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_VERSION_MINOR"))
#ifdef SASL_VERSION_MINOR
return SASL_VERSION_MINOR;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_VERSION_STEP"))
#ifdef SASL_VERSION_STEP
return SASL_VERSION_STEP;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_VRFY_CONF"))
#ifdef SASL_VRFY_CONF
return SASL_VRFY_CONF;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_VRFY_OTHER"))
#ifdef SASL_VRFY_OTHER
return SASL_VRFY_OTHER;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_VRFY_PASSWD"))
#ifdef SASL_VRFY_PASSWD
return SASL_VRFY_PASSWD;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_VRFY_PLUGIN"))
#ifdef SASL_VRFY_PLUGIN
return SASL_VRFY_PLUGIN;
#else
goto not_there;
#endif
if (strEQ(name, "SASL_WRONGMECH"))
#ifdef SASL_WRONGMECH
return SASL_WRONGMECH;
#else
goto not_there;
#endif
break;
case 'T':
break;
case 'U':
break;
case 'V':
break;
case 'W':
break;
case 'X':
break;
case 'Y':
break;
case 'Z':
break;
}
errno = EINVAL;
return 0;
not_there:
errno = ENOENT;
return 0;
}
/* D'Oh - Callbacks must be global, or allocated statically in the
* initialition procedure, as they seem to be incorporated by reference
* This sucks!
*/
static sasl_callback_t callbacks[4], *callback;
typedef sasl_conn_t *Authen__SASL__Cyrus__Connection;
MODULE = Authen::SASL::Cyrus PACKAGE = Authen::SASL::Cyrus
PROTOTYPES: DISABLE
double
constant(name,arg)
char * name
int arg
void
error()
CODE:
ST(0) = sv_2mortal(newSVpv((char *)sasl_errstring(err,NULL,NULL), 0));
SvUPGRADE(ST(0), SVt_PVIV);
SvIVX(ST(0)) = err;
SvIOK_on(ST(0));
Authen::SASL::Cyrus::Connection
init_connection(service, server, user)
char *service
char *server
char *user
PREINIT:
sasl_conn_t *conn = NULL;
char *out = NULL;
unsigned outlen;
const char *mech;
CODE:
callback = callbacks;
/* Remember to increment the size of the array before adding to
these */
callback->id = SASL_CB_USER;
callback->proc = &_sasl_callback;
callback->context = strdup(user);
++callback;
callback->id = SASL_CB_PASS;
callback->proc = &_sasl_getpass;
callback->context = NULL;
++callback;
callback->id = SASL_CB_LIST_END;
callback->proc = NULL;
callback->context = NULL;
++callback;
err = sasl_client_init(callbacks);
if (err != SASL_OK) XSRETURN_UNDEF;
err = sasl_client_new(service,server,NULL,0,&conn);
if (err != SASL_OK) XSRETURN_UNDEF;
RETVAL=conn;
OUTPUT:
RETVAL
SV *
start(conn, mechanism)
Authen::SASL::Cyrus::Connection conn
char *mechanism
PREINIT:
char *out;
unsigned outlen;
const char *mech;
CODE:
err = sasl_client_start(conn, mechanism, NULL, NULL,
&out, &outlen, &mech);
if (err!=SASL_CONTINUE && err!=SASL_OK) XSRETURN_UNDEF;
if (outlen==0) {
RETVAL = newSVpv("",0);
} else {
RETVAL = newSVpv(out,outlen);
}
OUTPUT:
RETVAL
SV *
respond(conn, insv)
Authen::SASL::Cyrus::Connection conn
SV *insv
PREINIT:
char *out, *in;
unsigned outlen, inlen;
sasl_interact_t *client_interact=NULL;
CODE:
in=SvPV(insv,inlen);
err = sasl_client_step(conn, in, inlen, NULL,
&out, &outlen);
if (err!=SASL_CONTINUE && err!=SASL_OK) XSRETURN_UNDEF;
if (outlen==0) {
RETVAL = newSVpv("",0);
} else {
RETVAL = newSVpv(out,outlen);
}
OUTPUT:
RETVAL
|