]> arthur.barton.de Git - netatalk.git/blob - etc/uams/uams_dhx_pam.c
changed all LOG messages using logtype_default to use logtype_uams
[netatalk.git] / etc / uams / uams_dhx_pam.c
1 /*
2  * $Id: uams_dhx_pam.c,v 1.22 2002-09-29 23:30:20 sibaz Exp $
3  *
4  * Copyright (c) 1990,1993 Regents of The University of Michigan.
5  * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu) 
6  * All Rights Reserved.  See COPYRIGHT.
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif /* HAVE_CONFIG_H */
12
13 #if defined(USE_PAM) && defined(UAM_DHX)
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <atalk/logger.h>
18
19 #ifdef HAVE_UNISTD_H
20 #include <unistd.h>
21 #endif /* HAVE_UNISTD_H */
22 #include <errno.h>
23
24 #include <security/pam_appl.h>
25
26 #ifdef OPENSSL_DHX
27 #include <openssl/bn.h>
28 #include <openssl/dh.h>
29 #include <openssl/cast.h>
30 #else /* OPENSSL_DHX */
31 #include <bn.h>
32 #include <dh.h>
33 #include <cast.h>
34 #endif /* OPENSSL_DHX */
35
36 #include <atalk/afp.h>
37 #include <atalk/uam.h>
38
39 #define KEYSIZE 16
40 #define PASSWDLEN 64
41 #define CRYPTBUFLEN  (KEYSIZE*2)
42 #define CRYPT2BUFLEN (KEYSIZE + PASSWDLEN)
43 #define CHANGEPWBUFLEN (KEYSIZE + 2*PASSWDLEN)
44
45 /* hash a number to a 16-bit quantity */
46 #define dhxhash(a) ((((unsigned long) (a) >> 8) ^ \
47                      (unsigned long) (a)) & 0xffff)
48
49 /* the secret key */
50 static CAST_KEY castkey;
51 static struct passwd *dhxpwd;
52 static u_int8_t randbuf[KEYSIZE];
53
54 /* diffie-hellman bits */
55 static unsigned char msg2_iv[] = "CJalbert";
56 static unsigned char msg3_iv[] = "LWallace";
57 static const u_int8_t p[] = {0xBA, 0x28, 0x73, 0xDF, 0xB0, 0x60, 0x57, 0xD4,
58                              0x3F, 0x20, 0x24, 0x74, 0x4C, 0xEE, 0xE7, 0x5B};
59 static const u_int8_t g = 0x07;
60
61
62 /* Static variables used to communicate between the conversation function
63  * and the server_login function
64  */
65 static pam_handle_t *pamh = NULL; 
66 static char *PAM_username;
67 static char *PAM_password;
68
69 /* PAM conversation function
70  * Here we assume (for now, at least) that echo on means login name, and
71  * echo off means password.
72  */
73 static int PAM_conv (int num_msg,
74                      const struct pam_message **msg,
75                      struct pam_response **resp,
76                      void *appdata_ptr) {
77   int count = 0;
78   struct pam_response *reply;
79   
80 #define COPY_STRING(s) (s) ? strdup(s) : NULL
81   
82   errno = 0;
83
84   if (num_msg < 1) {
85     /* Log Entry */
86            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM DHX Conversation Err -- %s",
87                   strerror(errno));
88     /* Log Entry */
89     return PAM_CONV_ERR;
90   }
91
92   reply = (struct pam_response *) 
93     calloc(num_msg, sizeof(struct pam_response));
94
95   if (!reply) {
96     /* Log Entry */
97            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM DHX Conversation Err -- %s",
98                   strerror(errno));
99     /* Log Entry */
100     return PAM_CONV_ERR;
101   }
102
103   for (count = 0; count < num_msg; count++) {
104     char *string = NULL;
105
106     switch (msg[count]->msg_style) {
107     case PAM_PROMPT_ECHO_ON:
108       if (!(string = COPY_STRING(PAM_username))) {
109     /* Log Entry */
110            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: username failure -- %s",
111                   strerror(errno));
112     /* Log Entry */
113         goto pam_fail_conv;
114       }
115       break;
116     case PAM_PROMPT_ECHO_OFF:
117       if (!(string = COPY_STRING(PAM_password))) {
118     /* Log Entry */
119            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: passwd failure: --: %s",
120                   strerror(errno));
121     /* Log Entry */
122         goto pam_fail_conv;
123       }
124       break;
125     case PAM_TEXT_INFO:
126 #ifdef PAM_BINARY_PROMPT
127     case PAM_BINARY_PROMPT:
128 #endif /* PAM_BINARY_PROMPT */
129       /* ignore it... */
130       break;
131     case PAM_ERROR_MSG:
132     default:
133     /* Log Entry */
134            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Binary_Prompt -- %s",
135                   strerror(errno));
136     /* Log Entry */
137       goto pam_fail_conv;
138     }
139
140     if (string) {  
141       reply[count].resp_retcode = 0;
142       reply[count].resp = string;
143       string = NULL;
144     }
145   }
146
147   *resp = reply;
148     /* Log Entry */
149            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: PAM Success -- %s",
150                   strerror(errno));
151     /* Log Entry */
152   return PAM_SUCCESS;
153
154 pam_fail_conv:
155   for (count = 0; count < num_msg; count++) {
156     if (!reply[count].resp)
157         continue;
158     switch (msg[count]->msg_style) {
159     case PAM_PROMPT_ECHO_OFF:
160     case PAM_PROMPT_ECHO_ON:
161       free(reply[count].resp);
162       break;      
163     }
164   }
165   free(reply);
166     /* Log Entry */
167            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM DHX Conversation Err -- %s",
168                   strerror(errno));
169     /* Log Entry */
170     return PAM_CONV_ERR;
171 }
172
173 static struct pam_conv PAM_conversation = {
174   &PAM_conv,
175   NULL
176 };
177
178
179 static int dhx_setup(void *obj, char *ibuf, int ibuflen, 
180                      char *rbuf, int *rbuflen)
181 {
182     u_int16_t sessid;
183     int i;
184     BIGNUM *bn, *gbn, *pbn;
185     DH *dh;
186
187     /* TODO: seed dhx_setup properly... this is a hack */
188 #ifdef sun
189         /* *SEVERE* hack... fix */
190         RAND_load_file("/var/adm/messages", KEYSIZE);
191 #endif /* sun */
192
193     /* get the client's public key */
194     if (!(bn = BN_bin2bn(ibuf, KEYSIZE, NULL))) {
195     /* Log Entry */
196            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM No Public Key -- %s",
197                   strerror(errno));
198     /* Log Entry */
199       return AFPERR_PARAM;
200     }
201
202     /* get our primes */
203     if (!(gbn = BN_bin2bn(&g, sizeof(g), NULL))) {
204       BN_clear_free(bn);
205     /* Log Entry */
206            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM No Primes: GBN -- %s",
207                   strerror(errno));
208     /* Log Entry */
209       return AFPERR_PARAM;
210     }
211
212     if (!(pbn = BN_bin2bn(p, sizeof(p), NULL))) {
213       BN_free(gbn);
214       BN_clear_free(bn);
215     /* Log Entry */
216            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM No Primes: PBN -- %s",
217                   strerror(errno));
218     /* Log Entry */
219       return AFPERR_PARAM;
220     }
221
222     /* okay, we're ready */
223     if (!(dh = DH_new())) {
224       BN_free(pbn);
225       BN_free(gbn);
226       BN_clear_free(bn);
227     /* Log Entry */
228            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM DH was equal to DH_New... Go figure... -- %s",
229                   strerror(errno));
230     /* Log Entry */
231       return AFPERR_PARAM;
232     }
233
234     /* generate key and make sure that we have enough space */
235     dh->p = pbn;
236     dh->g = gbn;
237     if (!DH_generate_key(dh) || (BN_num_bytes(dh->pub_key) > KEYSIZE)) {
238     /* Log Entry */
239            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Err Generating Key -- Not enough Space? -- %s",
240                   strerror(errno));
241     /* Log Entry */
242     goto pam_fail;
243     }
244
245     /* figure out the key. store the key in rbuf for now. */
246     i = DH_compute_key(rbuf, bn, dh);
247     
248     /* set the key */
249     CAST_set_key(&castkey, i, rbuf);
250     
251     /* session id. it's just a hashed version of the object pointer. */
252     sessid = dhxhash(obj);
253     memcpy(rbuf, &sessid, sizeof(sessid));
254     rbuf += sizeof(sessid);
255     *rbuflen += sizeof(sessid);
256     
257     /* public key */
258     BN_bn2bin(dh->pub_key, rbuf); 
259     rbuf += KEYSIZE;
260     *rbuflen += KEYSIZE;
261
262     /* buffer to be encrypted */
263     i = sizeof(randbuf);
264     if (uam_afpserver_option(obj, UAM_OPTION_RANDNUM, (void *) randbuf,
265                              &i) < 0) {
266       *rbuflen = 0;
267     /* Log Entry */
268            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Buffer Encryption Err. -- %s",
269                   strerror(errno));
270     /* Log Entry */
271       goto pam_fail;
272     }    
273     memcpy(rbuf, &randbuf, sizeof(randbuf));
274
275     /* get the signature. it's always 16 bytes. */
276 #if 0
277     if (uam_afpserver_option(obj, UAM_OPTION_SIGNATURE, 
278                              (void *) &buf, NULL) < 0) {
279       *rbuflen = 0;
280     /* Log Entry */
281            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Signature Retieval Failure -- %s",
282                   strerror(errno));
283     /* Log Entry */
284       goto pam_fail;
285     }
286     memcpy(rbuf + KEYSIZE, buf, KEYSIZE); 
287 #else /* 0 */
288     memset(rbuf + KEYSIZE, 0, KEYSIZE); 
289 #endif /* 0 */
290
291     /* encrypt using cast */
292     CAST_cbc_encrypt(rbuf, rbuf, CRYPTBUFLEN, &castkey, msg2_iv, 
293                      CAST_ENCRYPT);
294     *rbuflen += CRYPTBUFLEN;
295     BN_free(bn);
296     DH_free(dh);
297     return AFPERR_AUTHCONT;
298
299 pam_fail:
300     BN_free(bn);
301     DH_free(dh);
302     /* Log Entry */
303            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Fail - Cast Encryption -- %s",
304                   strerror(errno));
305     /* Log Entry */
306     return AFPERR_PARAM;
307 }
308
309
310 /* dhx login: things are done in a slightly bizarre order to avoid
311  * having to clean things up if there's an error. */
312 static int pam_login(void *obj, struct passwd **uam_pwd,
313                      char *ibuf, int ibuflen,
314                      char *rbuf, int *rbuflen)
315 {
316     char *buf;
317     int len, i;
318
319     *rbuflen = 0;
320
321     /* grab some of the options */
322     if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, (void *) &buf,
323                              &i) < 0) {
324     /* Log Entry */
325            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: uam_afpserver_option didn't meet uam_option_username  -- %s",
326                   strerror(errno));
327     /* Log Entry */
328       return AFPERR_PARAM;
329     }
330
331     len = (unsigned char) *ibuf++;
332     if ( len > i ) {
333     /* Log Entry */
334            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Signature Retieval Failure -- %s",
335                   strerror(errno));
336     /* Log Entry */
337         return( AFPERR_PARAM );
338     }
339
340     memcpy(buf, ibuf, len );
341     ibuf += len;
342     buf[ len ] = '\0';
343     if ((unsigned long) ibuf & 1) /* pad to even boundary */
344       ++ibuf;
345
346     if (( dhxpwd = uam_getname(buf, i)) == NULL ) {
347     /* Log Entry */
348            LOG(log_info, logtype_uams, "uams_dhx_pam.c: unknown username");
349     /* Log Entry */
350         return AFPERR_PARAM;
351     }
352
353     PAM_username = buf;
354     LOG(log_info, logtype_uams, "dhx login: %s", buf);
355     return dhx_setup(obj, ibuf, ibuflen, rbuf, rbuflen);
356 }
357
358
359 static int pam_logincont(void *obj, struct passwd **uam_pwd,
360                          char *ibuf, int ibuflen, 
361                          char *rbuf, int *rbuflen)
362 {
363     char *hostname;
364     BIGNUM *bn1, *bn2, *bn3;
365     u_int16_t sessid;
366     int err, PAM_error;
367
368     *rbuflen = 0;
369
370     /* check for session id */
371     memcpy(&sessid, ibuf, sizeof(sessid));
372     if (sessid != dhxhash(obj)) {
373     /* Log Entry */
374            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM Session ID - DHXHash Mismatch -- %s",
375                   strerror(errno));
376     /* Log Entry */
377       return AFPERR_PARAM;
378     }
379     ibuf += sizeof(sessid);
380     
381     if (uam_afpserver_option(obj, UAM_OPTION_CLIENTNAME,
382                              (void *) &hostname, NULL) < 0)
383         {
384         LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: unable to retrieve client hostname");
385         hostname = NULL;
386         }
387
388     CAST_cbc_encrypt(ibuf, rbuf, CRYPT2BUFLEN, &castkey,
389                      msg3_iv, CAST_DECRYPT);
390     memset(&castkey, 0, sizeof(castkey));
391
392     /* check to make sure that the random number is the same. we
393      * get sent back an incremented random number. */
394     if (!(bn1 = BN_bin2bn(rbuf, KEYSIZE, NULL)))
395       return AFPERR_PARAM;
396
397     if (!(bn2 = BN_bin2bn(randbuf, sizeof(randbuf), NULL))) {
398       BN_free(bn1);
399       return AFPERR_PARAM;
400     }
401       
402     /* zero out the random number */
403     memset(rbuf, 0, sizeof(randbuf));
404     memset(randbuf, 0, sizeof(randbuf));
405     rbuf += KEYSIZE;
406
407     if (!(bn3 = BN_new())) {
408       BN_free(bn2);
409       BN_free(bn1);
410       return AFPERR_PARAM;
411     }
412
413     BN_sub(bn3, bn1, bn2);
414     BN_free(bn2);
415     BN_free(bn1);
416
417     /* okay. is it one more? */
418     if (!BN_is_one(bn3)) {
419       BN_free(bn3);
420       return AFPERR_PARAM;
421     }
422     BN_free(bn3);
423
424     /* Set these things up for the conv function */
425     rbuf[PASSWDLEN] = '\0';
426     PAM_password = rbuf;
427
428     err = AFPERR_NOTAUTH;
429     PAM_error = pam_start("netatalk", PAM_username, &PAM_conversation,
430                           &pamh);
431     if (PAM_error != PAM_SUCCESS) {
432     /* Log Entry */
433            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: PAM_Error: %s",
434                   pam_strerror(pamh,PAM_error));
435     /* Log Entry */
436       goto logincont_err;
437     }
438
439     /* solaris craps out if PAM_TTY and PAM_RHOST aren't set. */
440     pam_set_item(pamh, PAM_TTY, "afpd");
441     pam_set_item(pamh, PAM_RHOST, hostname);
442     PAM_error = pam_authenticate(pamh,0);
443     if (PAM_error != PAM_SUCCESS) {
444       if (PAM_error == PAM_MAXTRIES) 
445         err = AFPERR_PWDEXPR;
446     /* Log Entry */
447            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: PAM_Error: %s",
448                   pam_strerror(pamh, PAM_error));
449     /* Log Entry */
450       goto logincont_err;
451     }      
452
453     PAM_error = pam_acct_mgmt(pamh, 0);
454     if (PAM_error != PAM_SUCCESS) {
455       if (PAM_error == PAM_ACCT_EXPIRED)
456         err = AFPERR_PWDEXPR;
457 #ifdef PAM_AUTHTOKEN_REQD
458       else if (PAM_error == PAM_AUTHTOKEN_REQD) 
459         err = AFPERR_PWDCHNG;
460 #endif
461     /* Log Entry */
462            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: PAM_Error: %s",
463                   pam_strerror(pamh, PAM_error));
464     /* Log Entry */
465       goto logincont_err;
466     }
467
468 #ifndef PAM_CRED_ESTABLISH
469 #define PAM_CRED_ESTABLISH PAM_ESTABLISH_CRED
470 #endif
471     PAM_error = pam_setcred(pamh, PAM_CRED_ESTABLISH);
472     if (PAM_error != PAM_SUCCESS) {
473     /* Log Entry */
474            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: PAM_Error: %s",
475                   pam_strerror(pamh, PAM_error));
476     /* Log Entry */
477       goto logincont_err;
478     }
479
480     PAM_error = pam_open_session(pamh, 0);
481     if (PAM_error != PAM_SUCCESS) {
482     /* Log Entry */
483            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: PAM_Error: %s",
484                   pam_strerror(pamh, PAM_error));
485     /* Log Entry */
486       goto logincont_err;
487     }
488
489     memset(rbuf, 0, PASSWDLEN); /* zero out the password */
490     *uam_pwd = dhxpwd;
491     /* Log Entry */
492            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: PAM Auth OK!");
493     /* Log Entry */
494     return AFP_OK;
495
496 logincont_err:
497     pam_end(pamh, PAM_error);
498     pamh = NULL;
499     memset(rbuf, 0, CRYPT2BUFLEN);
500     return err;
501 }
502
503 /* logout */
504 static void pam_logout() {
505     pam_close_session(pamh, 0);
506     pam_end(pamh, 0);
507     pamh = NULL;
508 }
509
510
511 /* change pw for dhx needs a couple passes to get everything all
512  * right. basically, it's like the login/logincont sequence */
513 static int pam_changepw(void *obj, char *username,
514                         struct passwd *pwd, char *ibuf, int ibuflen,
515                         char *rbuf, int *rbuflen)
516 {
517     BIGNUM *bn1, *bn2, *bn3;
518
519     char *hostname;
520     pam_handle_t *lpamh;
521     uid_t uid;
522     u_int16_t sessid;
523     int PAM_error;
524
525     /* grab the id */
526     memcpy(&sessid, ibuf, sizeof(sessid));
527     ibuf += sizeof(sessid);
528     
529     if (!sessid) {  /* no sessid -> initialization phase */
530       PAM_username = username;
531       ibuflen -= sizeof(sessid);
532       return dhx_setup(obj, ibuf, ibuflen, rbuf, rbuflen);
533     }
534
535
536     /* otherwise, it's like logincont but different. */
537
538     /* check out the session id */
539     if (sessid != dhxhash(obj)) {
540     /* Log Entry */
541            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Session ID not Equal to DHX Hash -- %s",
542                   strerror(errno));
543     /* Log Entry */
544       return AFPERR_PARAM;
545     }
546
547     /* we need this for pam */
548     if (uam_afpserver_option(obj, UAM_OPTION_HOSTNAME,
549                              (void *) &hostname, NULL) < 0) {
550     /* Log Entry */
551            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Hostname Null?? -- %s",
552                   strerror(errno));
553     /* Log Entry */
554       return AFPERR_MISC;
555     }
556
557     /* grab the client's nonce, old password, and new password. */
558     CAST_cbc_encrypt(ibuf, ibuf, CHANGEPWBUFLEN, &castkey,
559                      msg3_iv, CAST_DECRYPT);
560     memset(&castkey, 0, sizeof(castkey));
561
562     /* check to make sure that the random number is the same. we
563      * get sent back an incremented random number. */
564     if (!(bn1 = BN_bin2bn(ibuf, KEYSIZE, NULL))) {
565     /* Log Entry */
566            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Random Number Not the same or not incremented-- %s",
567                   strerror(errno));
568     /* Log Entry */
569       return AFPERR_PARAM;
570     }
571
572     if (!(bn2 = BN_bin2bn(randbuf, sizeof(randbuf), NULL))) {
573       BN_free(bn1);
574     /* Log Entry */
575            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Random Number Not the same or not incremented -- %s",
576                   strerror(errno));
577     /* Log Entry */
578       return AFPERR_PARAM;
579     }
580       
581     /* zero out the random number */
582     memset(rbuf, 0, sizeof(randbuf));
583     memset(randbuf, 0, sizeof(randbuf));
584
585     if (!(bn3 = BN_new())) {
586       BN_free(bn2);
587       BN_free(bn1);
588     /* Log Entry */
589            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Random Number did not Zero -- %s",
590                   strerror(errno));
591     /* Log Entry */
592       return AFPERR_PARAM;
593     }
594
595     BN_sub(bn3, bn1, bn2);
596     BN_free(bn2);
597     BN_free(bn1);
598
599     /* okay. is it one more? */
600 #if 0
601     if (!BN_is_one(bn3)) {
602       BN_free(bn3);
603     /* Log Entry */
604            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: After Random Number not Zero, is it one more? -- %s",
605                   strerror(errno));
606     /* Log Entry */
607       return AFPERR_PARAM;
608     }
609 #endif
610     BN_free(bn3);
611
612     /* Set these things up for the conv function. the old password
613      * is at the end. */
614     ibuf += KEYSIZE;
615     ibuf[PASSWDLEN + PASSWDLEN] = '\0';
616     PAM_password = ibuf + PASSWDLEN;
617
618     PAM_error = pam_start("netatalk", username, &PAM_conversation,
619                           &lpamh);
620     if (PAM_error != PAM_SUCCESS) {
621     /* Log Entry */
622            LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Needless to say, PAM_error is != to PAM_SUCCESS -- %s",
623                   strerror(errno));
624     /* Log Entry */
625       return AFPERR_PARAM;
626     }
627     pam_set_item(lpamh, PAM_TTY, "afpd");
628     pam_set_item(lpamh, PAM_RHOST, hostname);
629
630     /* we might need to do this as root */
631     uid = geteuid();
632     seteuid(0);
633     PAM_error = pam_authenticate(lpamh, 0);
634     if (PAM_error != PAM_SUCCESS) {
635       seteuid(uid);
636       pam_end(lpamh, PAM_error);
637       return AFPERR_NOTAUTH;
638     }
639
640     /* clear out old passwd */
641     memset(ibuf + PASSWDLEN, 0, PASSWDLEN);
642
643     /* new password */
644     PAM_password = ibuf;
645     ibuf[PASSWDLEN] = '\0';
646
647     /* this really does need to be done as root */
648     PAM_error = pam_chauthtok(lpamh, 0);
649     seteuid(uid); /* un-root ourselves. */
650     memset(ibuf, 0, PASSWDLEN);
651     if (PAM_error != PAM_SUCCESS) {
652       pam_end(lpamh, PAM_error);
653       return AFPERR_ACCESS;
654     }
655
656     pam_end(lpamh, 0);
657     return AFP_OK;
658 }
659
660
661 static int uam_setup(const char *path)
662 {
663   if (uam_register(UAM_SERVER_LOGIN, path, "DHCAST128", pam_login, 
664                    pam_logincont, pam_logout) < 0)
665     return -1;
666
667   if (uam_register(UAM_SERVER_CHANGEPW, path, "DHCAST128", 
668                    pam_changepw) < 0) {
669     uam_unregister(UAM_SERVER_LOGIN, "DHCAST128");
670     return -1;
671   }
672
673   /*uam_register(UAM_SERVER_PRINTAUTH, path, "DHCAST128",
674     pam_printer);*/
675
676   return 0;
677 }
678
679 static void uam_cleanup(void)
680 {
681   uam_unregister(UAM_SERVER_LOGIN, "DHCAST128");
682   uam_unregister(UAM_SERVER_CHANGEPW, "DHCAST128");
683   /*uam_unregister(UAM_SERVER_PRINTAUTH, "DHCAST128"); */
684 }
685
686 UAM_MODULE_EXPORT struct uam_export uams_dhx = {
687   UAM_MODULE_SERVER,
688   UAM_MODULE_VERSION,
689   uam_setup, uam_cleanup
690 };
691
692 UAM_MODULE_EXPORT struct uam_export uams_dhx_pam = {
693   UAM_MODULE_SERVER,
694   UAM_MODULE_VERSION,
695   uam_setup, uam_cleanup
696 };
697
698 #endif /* USE_PAM && UAM_DHX */
699