2 * Copyright (c) 1990,1993 Regents of The University of Michigan.
3 * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
4 * All Rights Reserved. See COPYRIGHT.
9 #endif /* HAVE_CONFIG_H */
11 #if defined (USE_PAM) && defined (UAM_DHX2)
15 #include <atalk/logger.h>
19 #endif /* HAVE_UNISTD_H */
21 #ifdef HAVE_SECURITY_PAM_APPL_H
22 #include <security/pam_appl.h>
24 #ifdef HAVE_PAM_PAM_APPL_H
25 #include <pam/pam_appl.h>
31 #endif /* HAVE_LIBGCRYPT */
33 #include <atalk/afp.h>
34 #include <atalk/uam.h>
35 #include <atalk/globals.h>
37 /* Number of bits for p which we generate. Everybode out there uses 512, so we beet them */
38 #define PRIMEBITS 1024
40 /* hash a number to a 16-bit quantity */
41 #define dhxhash(a) ((((unsigned long) (a) >> 8) ^ \
42 (unsigned long) (a)) & 0xffff)
44 /* Some parameters need be maintained across calls */
45 static gcry_mpi_t p, g, Ra;
46 static gcry_mpi_t serverNonce;
47 static char *K_MD5hash = NULL;
48 static int K_hash_len;
51 /* The initialization vectors for CAST128 are fixed by Apple. */
52 static unsigned char dhx_c2siv[] = { 'L', 'W', 'a', 'l', 'l', 'a', 'c', 'e' };
53 static unsigned char dhx_s2civ[] = { 'C', 'J', 'a', 'l', 'b', 'e', 'r', 't' };
55 /* Static variables used to communicate between the conversation function
56 * and the server_login function */
57 static pam_handle_t *pamh = NULL;
58 static char *PAM_username;
59 static char *PAM_password;
60 static struct passwd *dhxpwd;
62 /*********************************************************
63 * Crypto helper func to generate p and g for use in DH.
64 * libgcrypt doesn't provide one directly.
65 * Algorithm taken from GNUTLS:gnutls_dh_primes.c
66 *********************************************************/
69 * This function will generate a new pair of prime and generator for use in
70 * the Diffie-Hellman key exchange.
71 * The bits value should be one of 768, 1024, 2048, 3072 or 4096.
73 static int dh_params_generate (unsigned int bits) {
75 int result, times = 0, qbits;
76 gcry_mpi_t *factors = NULL;
79 /* Version check should be the very first call because it
80 makes sure that important subsystems are intialized. */
81 if (!gcry_check_version (GCRYPT_VERSION)) {
82 LOG(log_error, logtype_uams, "PAM DHX2: libgcrypt versions mismatch. Need: %s", GCRYPT_VERSION);
90 qbits = (bits / 40) + 105;
92 if (qbits & 1) /* better have an even number */
95 /* find a prime number of size bits. */
99 gcry_prime_release_factors (factors);
101 err = gcry_prime_generate(&p, bits, qbits, &factors, NULL, NULL,
102 GCRY_STRONG_RANDOM, GCRY_PRIME_FLAG_SPECIAL_FACTOR);
104 result = AFPERR_MISC;
107 err = gcry_prime_check(p, 0);
109 } while (err != 0 && times < 10);
112 result = AFPERR_MISC;
116 /* generate the group generator. */
117 err = gcry_prime_group_generator(&g, p, factors, NULL);
119 result = AFPERR_MISC;
123 gcry_prime_release_factors(factors);
128 gcry_prime_release_factors(factors);
134 /* PAM conversation function
135 * Here we assume (for now, at least) that echo on means login name, and
136 * echo off means password.
138 static int PAM_conv (int num_msg,
139 const struct pam_message **msg,
140 struct pam_response **resp,
141 void *appdata_ptr _U_) {
143 struct pam_response *reply;
145 #define COPY_STRING(s) (s) ? strdup(s) : NULL
151 LOG(log_info, logtype_uams, "PAM DHX2 Conversation Err -- %s",
157 reply = (struct pam_response *)
158 calloc(num_msg, sizeof(struct pam_response));
162 LOG(log_info, logtype_uams, "PAM DHX2: Conversation Err -- %s",
168 for (count = 0; count < num_msg; count++) {
171 switch (msg[count]->msg_style) {
172 case PAM_PROMPT_ECHO_ON:
173 if (!(string = COPY_STRING(PAM_username))) {
175 LOG(log_info, logtype_uams, "PAM DHX2: username failure -- %s",
181 case PAM_PROMPT_ECHO_OFF:
182 if (!(string = COPY_STRING(PAM_password))) {
184 LOG(log_info, logtype_uams, "PAM DHX2: passwd failure: --: %s",
191 #ifdef PAM_BINARY_PROMPT
192 case PAM_BINARY_PROMPT:
193 #endif /* PAM_BINARY_PROMPT */
198 LOG(log_info, logtype_uams, "PAM DHX2: Binary_Prompt -- %s", strerror(errno));
203 reply[count].resp_retcode = 0;
204 reply[count].resp = string;
210 LOG(log_info, logtype_uams, "PAM DHX2: PAM Success");
214 for (count = 0; count < num_msg; count++) {
215 if (!reply[count].resp)
217 switch (msg[count]->msg_style) {
218 case PAM_PROMPT_ECHO_OFF:
219 case PAM_PROMPT_ECHO_ON:
220 free(reply[count].resp);
226 LOG(log_info, logtype_uams, "PAM DHX2: Conversation Err -- %s",
232 static struct pam_conv PAM_conversation = {
238 static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
239 char *rbuf, size_t *rbuflen)
244 char *Ra_binary = NULL;
248 Ra = gcry_mpi_new(0);
249 Ma = gcry_mpi_new(0);
251 /* Generate our random number Ra. */
252 Ra_binary = calloc(1, PRIMEBITS/8);
253 if (Ra_binary == NULL) {
257 gcry_randomize(Ra_binary, PRIMEBITS/8, GCRY_STRONG_RANDOM);
258 gcry_mpi_scan(&Ra, GCRYMPI_FMT_USG, Ra_binary, PRIMEBITS/8, NULL);
262 /* Ma = g^Ra mod p. This is our "public" key */
263 gcry_mpi_powm(Ma, g, Ra, p);
265 /* ------- DH Init done ------ */
266 /* Start building reply packet */
268 /* Session ID first */
270 *(u_int16_t *)rbuf = htons(ID);
275 gcry_mpi_print( GCRYMPI_FMT_USG, (unsigned char *)rbuf, 4, &nwritten, g);
277 memmove( rbuf+4-nwritten, rbuf, nwritten);
278 memset( rbuf, 0, 4-nwritten);
283 /* len = length of p = PRIMEBITS/8 */
284 *(u_int16_t *)rbuf = htons((u_int16_t) PRIMEBITS/8);
289 gcry_mpi_print( GCRYMPI_FMT_USG, (unsigned char *)rbuf, PRIMEBITS/8, NULL, p);
291 *rbuflen += PRIMEBITS/8;
294 gcry_mpi_print( GCRYMPI_FMT_USG, (unsigned char *)rbuf, PRIMEBITS/8, &nwritten, Ma);
295 if (nwritten < PRIMEBITS/8) {
296 memmove(rbuf + (PRIMEBITS/8) - nwritten, rbuf, nwritten);
297 memset(rbuf, 0, (PRIMEBITS/8) - nwritten);
300 *rbuflen += PRIMEBITS/8;
302 ret = AFPERR_AUTHCONT;
304 error: /* We exit here anyway */
305 /* We will need Ra later, but mustn't forget to release it ! */
306 gcry_mpi_release(Ma);
310 /* -------------------------------- */
311 static int login(void *obj, char *username, int ulen, struct passwd **uam_pwd _U_,
312 char *ibuf, size_t ibuflen,
313 char *rbuf, size_t *rbuflen)
315 if (( dhxpwd = uam_getname(obj, username, ulen)) == NULL ) {
316 LOG(log_info, logtype_uams, "DHX2: unknown username");
317 return AFPERR_NOTAUTH;
320 PAM_username = username;
321 LOG(log_info, logtype_uams, "DHX2 login: %s", username);
322 return dhx2_setup(obj, ibuf, ibuflen, rbuf, rbuflen);
325 /* -------------------------------- */
326 /* dhx login: things are done in a slightly bizarre order to avoid
327 * having to clean things up if there's an error. */
328 static int pam_login(void *obj, struct passwd **uam_pwd,
329 char *ibuf, size_t ibuflen,
330 char *rbuf, size_t *rbuflen)
337 /* grab some of the options */
338 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, (void *) &username, &ulen) < 0) {
339 LOG(log_info, logtype_uams, "DHX2: uam_afpserver_option didn't meet uam_option_username -- %s",
344 len = (unsigned char) *ibuf++;
346 LOG(log_info, logtype_uams, "DHX2: Signature Retieval Failure -- %s",
351 memcpy(username, ibuf, len );
353 username[ len ] = '\0';
355 if ((unsigned long) ibuf & 1) /* pad to even boundary */
358 return (login(obj, username, ulen, uam_pwd, ibuf, ibuflen, rbuf, rbuflen));
361 /* ----------------------------- */
362 static int pam_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
363 char *ibuf, size_t ibuflen,
364 char *rbuf, size_t *rbuflen)
372 /* grab some of the options */
373 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, (void *) &username, &ulen) < 0) {
374 LOG(log_info, logtype_uams, "DHX2: uam_afpserver_option didn't meet uam_option_username -- %s",
382 memcpy(&temp16, uname, sizeof(temp16));
385 if ( !len || len > ulen ) {
386 LOG(log_info, logtype_uams, "DHX2: Signature Retrieval Failure -- %s",
390 memcpy(username, uname +2, len );
391 username[ len ] = '\0';
393 return (login(obj, username, ulen, uam_pwd, ibuf, ibuflen, rbuf, rbuflen));
396 /* -------------------------------- */
397 static int logincont1(void *obj _U_, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
401 gcry_mpi_t Mb, K, clientNonce;
402 unsigned char *K_bin = NULL;
403 char serverNonce_bin[16];
404 gcry_cipher_hd_t ctx;
405 gcry_error_t ctxerror;
409 Mb = gcry_mpi_new(0);
411 clientNonce = gcry_mpi_new(0);
412 serverNonce = gcry_mpi_new(0);
414 /* Packet size should be: Session ID + Ma + Encrypted client nonce */
415 if (ibuflen != 2 + PRIMEBITS/8 + 16) {
416 LOG(log_error, logtype_uams, "DHX2: Paket length not correct");
421 /* Skip session id */
424 /* Extract Mb, client's "public" key */
425 gcry_mpi_scan(&Mb, GCRYMPI_FMT_USG, ibuf, PRIMEBITS/8, NULL);
428 /* Now finally generate the Key: K = Mb^Ra mod p */
429 gcry_mpi_powm(K, Mb, Ra, p);
431 /* We need K in binary form in order to ... */
432 K_bin = calloc(1, PRIMEBITS/8);
437 gcry_mpi_print(GCRYMPI_FMT_USG, K_bin, PRIMEBITS/8, &nwritten, K);
438 if (nwritten < PRIMEBITS/8) {
439 memmove(K_bin + PRIMEBITS/8 - nwritten, K_bin, nwritten);
440 memset(K_bin, 0, PRIMEBITS/8 - nwritten);
443 /* ... generate the MD5 hash of K. K_MD5hash is what we actually use ! */
444 K_MD5hash = calloc(1, K_hash_len = gcry_md_get_algo_dlen(GCRY_MD_MD5));
445 if (K_MD5hash == NULL) {
449 gcry_md_hash_buffer(GCRY_MD_MD5, K_MD5hash, K_bin, PRIMEBITS/8);
453 /* FIXME: To support the Reconnect UAM, we need to store this key somewhere */
455 /* Set up our encryption context. */
456 ctxerror = gcry_cipher_open( &ctx, GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_CBC, 0);
457 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
462 ctxerror = gcry_cipher_setkey(ctx, K_MD5hash, K_hash_len);
463 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
467 /* Set the initialization vector for client->server transfer. */
468 ctxerror = gcry_cipher_setiv(ctx, dhx_c2siv, sizeof(dhx_c2siv));
469 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
473 /* Finally: decrypt client's md5_K(client nonce, C2SIV) inplace */
474 ctxerror = gcry_cipher_decrypt(ctx, ibuf, 16, NULL, 0);
475 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
479 /* Pull out clients nonce */
480 gcry_mpi_scan(&clientNonce, GCRYMPI_FMT_USG, ibuf, 16, NULL);
481 /* Increment nonce */
482 gcry_mpi_add_ui(clientNonce, clientNonce, 1);
484 /* Generate our nonce and remember it for Logincont2 */
485 gcry_create_nonce(serverNonce_bin, 16); /* We'll use this here */
486 gcry_mpi_scan(&serverNonce, GCRYMPI_FMT_USG, serverNonce_bin, 16, NULL); /* For use in Logincont2 */
488 /* ---- Start building reply packet ---- */
490 /* Session ID + 1 first */
491 *(u_int16_t *)rbuf = htons(ID+1);
495 /* Client nonce + 1 */
496 gcry_mpi_print(GCRYMPI_FMT_USG, (unsigned char *)rbuf, PRIMEBITS/8, NULL, clientNonce);
498 memcpy(rbuf+16, serverNonce_bin, 16);
500 /* Set the initialization vector for server->client transfer. */
501 ctxerror = gcry_cipher_setiv(ctx, dhx_s2civ, sizeof(dhx_s2civ));
502 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
506 /* Encrypt md5_K(clientNonce+1, serverNonce) inplace */
507 ctxerror = gcry_cipher_encrypt(ctx, rbuf, 32, NULL, 0);
508 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
515 ret = AFPERR_AUTHCONT;
519 gcry_cipher_close(ctx);
521 gcry_mpi_release(serverNonce);
526 gcry_mpi_release(Mb);
527 gcry_mpi_release(Ra);
528 gcry_mpi_release(clientNonce);
532 static int logincont2(void *obj, struct passwd **uam_pwd,
533 char *ibuf, size_t ibuflen,
534 char *rbuf _U_, size_t *rbuflen)
538 const char *hostname = NULL;
539 gcry_mpi_t retServerNonce;
540 gcry_cipher_hd_t ctx;
541 gcry_error_t ctxerror;
545 /* Packet size should be: Session ID + ServerNonce + Passwd buffer (evantually +10 extra bytes, see Apples Docs) */
546 if ((ibuflen != 2 + 16 + 256) && (ibuflen != 2 + 16 + 256 + 10)) {
547 LOG(log_error, logtype_uams, "DHX2: Paket length not correct: %u. Should be 274 or 284.", ibuflen);
552 retServerNonce = gcry_mpi_new(0);
555 uam_afpserver_option(obj, UAM_OPTION_CLIENTNAME, (void *) &hostname, NULL);
557 /* Set up our encryption context. */
558 ctxerror = gcry_cipher_open( &ctx, GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_CBC, 0);
559 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
564 ctxerror = gcry_cipher_setkey(ctx, K_MD5hash, K_hash_len);
565 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
569 /* Set the initialization vector for client->server transfer. */
570 ctxerror = gcry_cipher_setiv(ctx, dhx_c2siv, sizeof(dhx_c2siv));
571 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
576 /* Skip Session ID */
579 /* Finally: decrypt client's md5_K(serverNonce+1, passwor, C2SIV) inplace */
580 ctxerror = gcry_cipher_decrypt(ctx, ibuf, 16+256, NULL, 0);
581 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
585 /* Pull out nonce. Should be serverNonce+1 */
586 gcry_mpi_scan(&retServerNonce, GCRYMPI_FMT_USG, ibuf, 16, NULL);
587 gcry_mpi_sub_ui(retServerNonce, retServerNonce, 1);
588 if ( gcry_mpi_cmp( serverNonce, retServerNonce) != 0) {
590 ret = AFPERR_NOTAUTH;
595 /* ---- Start authentication with PAM --- */
597 /* Set these things up for the conv function */
600 ret = AFPERR_NOTAUTH;
601 PAM_error = pam_start("netatalk", PAM_username, &PAM_conversation, &pamh);
602 if (PAM_error != PAM_SUCCESS) {
603 LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
604 pam_strerror(pamh,PAM_error));
608 /* solaris craps out if PAM_TTY and PAM_RHOST aren't set. */
609 pam_set_item(pamh, PAM_TTY, "afpd");
610 pam_set_item(pamh, PAM_RHOST, hostname);
611 PAM_error = pam_authenticate(pamh, 0);
612 if (PAM_error != PAM_SUCCESS) {
613 if (PAM_error == PAM_MAXTRIES)
614 ret = AFPERR_PWDEXPR;
615 LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
616 pam_strerror(pamh, PAM_error));
620 PAM_error = pam_acct_mgmt(pamh, 0);
621 if (PAM_error != PAM_SUCCESS ) {
622 LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
623 pam_strerror(pamh, PAM_error));
624 if (PAM_error == PAM_NEW_AUTHTOK_REQD) /* password expired */
625 ret = AFPERR_PWDEXPR;
626 #ifdef PAM_AUTHTOKEN_REQD
627 else if (PAM_error == PAM_AUTHTOKEN_REQD)
628 ret = AFPERR_PWDCHNG;
634 #ifndef PAM_CRED_ESTABLISH
635 #define PAM_CRED_ESTABLISH PAM_ESTABLISH_CRED
637 PAM_error = pam_setcred(pamh, PAM_CRED_ESTABLISH);
638 if (PAM_error != PAM_SUCCESS) {
639 LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
640 pam_strerror(pamh, PAM_error));
644 PAM_error = pam_open_session(pamh, 0);
645 if (PAM_error != PAM_SUCCESS) {
646 LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
647 pam_strerror(pamh, PAM_error));
651 memset(ibuf, 0, 256); /* zero out the password */
653 LOG(log_info, logtype_uams, "DHX2: PAM Auth OK!");
654 if ( ret == AFPERR_PWDEXPR)
659 gcry_cipher_close(ctx);
663 gcry_mpi_release(serverNonce);
664 gcry_mpi_release(retServerNonce);
668 static int pam_logincont(void *obj, struct passwd **uam_pwd,
669 char *ibuf, size_t ibuflen,
670 char *rbuf, size_t *rbuflen)
675 /* check for session id */
676 retID = ntohs(*(u_int16_t *)ibuf);
678 ret = logincont1(obj, ibuf, ibuflen, rbuf, rbuflen);
679 else if (retID == ID+1)
680 ret = logincont2(obj, uam_pwd, ibuf,ibuflen, rbuf, rbuflen);
682 LOG(log_info, logtype_uams, "DHX2: Session ID Mismatch");
690 static void pam_logout(void) {
691 pam_close_session(pamh, 0);
696 /****************************
697 * --- Change pwd stuff --- */
699 static int changepw_1(void *obj, char *uname,
700 char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
704 /* Remember it now, use it in changepw_3 */
705 PAM_username = uname;
706 return( dhx2_setup(obj, ibuf, ibuflen, rbuf, rbuflen) );
709 static int changepw_2(void *obj,
710 char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
712 return( logincont1(obj, ibuf, ibuflen, rbuf, rbuflen) );
715 static int changepw_3(void *obj _U_,
716 char *ibuf, size_t ibuflen _U_,
717 char *rbuf _U_, size_t *rbuflen _U_)
723 const char *hostname = NULL;
724 gcry_mpi_t retServerNonce;
725 gcry_cipher_hd_t ctx;
726 gcry_error_t ctxerror;
730 LOG(log_error, logtype_uams, "DHX2 ChangePW: packet 3 processing");
732 /* Packet size should be: Session ID + ServerNonce + 2*Passwd buffer */
733 if (ibuflen != 2 + 16 + 2*256) {
734 LOG(log_error, logtype_uams, "DHX2: Paket length not correct");
739 retServerNonce = gcry_mpi_new(0);
742 uam_afpserver_option(obj, UAM_OPTION_CLIENTNAME, (void *) &hostname, NULL);
744 /* Set up our encryption context. */
745 ctxerror = gcry_cipher_open( &ctx, GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_CBC, 0);
746 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
751 ctxerror = gcry_cipher_setkey(ctx, K_MD5hash, K_hash_len);
752 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
757 /* Set the initialization vector for client->server transfer. */
758 ctxerror = gcry_cipher_setiv(ctx, dhx_c2siv, sizeof(dhx_c2siv));
759 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
764 /* Skip Session ID */
767 /* Finally: decrypt client's md5_K(serverNonce+1, 2*password, C2SIV) inplace */
768 ctxerror = gcry_cipher_decrypt(ctx, ibuf, 16+2*256, NULL, 0);
769 if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
773 /* Pull out nonce. Should be serverNonce+1 */
774 gcry_mpi_scan(&retServerNonce, GCRYMPI_FMT_USG, ibuf, 16, NULL);
775 gcry_mpi_sub_ui(retServerNonce, retServerNonce, 1);
776 if ( gcry_mpi_cmp( serverNonce, retServerNonce) != 0) {
778 ret = AFPERR_NOTAUTH;
783 /* ---- Start pwd changing with PAM --- */
784 ibuf[255] = '\0'; /* For safety */
787 /* check if new and old password are equal */
788 if (memcmp(ibuf, ibuf + 256, 255) == 0) {
789 LOG(log_info, logtype_uams, "DHX2 Chgpwd: new and old password are equal");
790 ret = AFPERR_PWDSAME;
794 /* Set these things up for the conv function. PAM_username was set in changepw_1 */
795 PAM_password = ibuf + 256;
796 PAM_error = pam_start("netatalk", PAM_username, &PAM_conversation, &lpamh);
797 if (PAM_error != PAM_SUCCESS) {
798 LOG(log_info, logtype_uams, "DHX2 Chgpwd: PAM error in pam_start");
802 pam_set_item(lpamh, PAM_TTY, "afpd");
803 uam_afpserver_option(obj, UAM_OPTION_CLIENTNAME, (void *) &hostname, NULL);
804 pam_set_item(lpamh, PAM_RHOST, hostname);
807 PAM_error = pam_authenticate(lpamh,0);
808 if (PAM_error != PAM_SUCCESS) {
809 LOG(log_info, logtype_uams, "DHX2 Chgpwd: error authenticating with PAM");
811 pam_end(lpamh, PAM_error);
812 ret = AFPERR_NOTAUTH;
816 PAM_error = pam_chauthtok(lpamh, 0);
817 seteuid(uid); /* un-root ourselves. */
818 memset(ibuf, 0, 512);
819 if (PAM_error != PAM_SUCCESS) {
820 LOG(log_info, logtype_uams, "DHX2 Chgpwd: error changing pw with PAM");
821 pam_end(lpamh, PAM_error);
829 gcry_cipher_close(ctx);
833 gcry_mpi_release(serverNonce);
834 gcry_mpi_release(retServerNonce);
838 static int dhx2_changepw(void *obj _U_, char *uname,
839 struct passwd *pwd _U_, char *ibuf, size_t ibuflen _U_,
840 char *rbuf _U_, size_t *rbuflen _U_)
842 /* We use this to serialize the three incoming FPChangePassword calls */
843 static int dhx2_changepw_status = 1;
845 int ret = AFPERR_NOTAUTH; /* gcc can't figure out it's always initialized */
847 switch (dhx2_changepw_status) {
849 ret = changepw_1( obj, uname, ibuf, ibuflen, rbuf, rbuflen);
850 if ( ret == AFPERR_AUTHCONT)
851 dhx2_changepw_status = 2;
854 ret = changepw_2( obj, ibuf, ibuflen, rbuf, rbuflen);
855 if ( ret == AFPERR_AUTHCONT)
856 dhx2_changepw_status = 3;
858 dhx2_changepw_status = 1;
861 ret = changepw_3( obj, ibuf, ibuflen, rbuf, rbuflen);
862 dhx2_changepw_status = 1; /* Whether is was succesfull or not: we
869 static int uam_setup(const char *path)
871 if (uam_register(UAM_SERVER_LOGIN_EXT, path, "DHX2", pam_login,
872 pam_logincont, pam_logout, pam_login_ext) < 0)
874 if (uam_register(UAM_SERVER_CHANGEPW, path, "DHX2", dhx2_changepw) < 0)
880 LOG(log_debug, logtype_uams, "DHX2: generating mersenne primes");
881 /* Generate p and g for DH */
882 if (dh_params_generate(PRIMEBITS) != 0) {
883 LOG(log_error, logtype_uams, "DHX2: Couldn't generate p and g");
890 static void uam_cleanup(void)
892 uam_unregister(UAM_SERVER_LOGIN, "DHX2");
893 uam_unregister(UAM_SERVER_CHANGEPW, "DHX2");
900 UAM_MODULE_EXPORT struct uam_export uams_dhx2 = {
903 uam_setup, uam_cleanup
907 UAM_MODULE_EXPORT struct uam_export uams_dhx2_pam = {
910 uam_setup, uam_cleanup
913 #endif /* USE_PAM && UAM_DHX2 */