2 * $Id: auth.c,v 1.44.2.3.2.15.2.2 2005-01-31 17:00:41 didg Exp $
4 * Copyright (c) 1990,1993 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
17 #endif /* HAVE_UNISTD_H */
18 #include <sys/types.h>
19 #include <sys/param.h>
21 #include <netatalk/endian.h>
22 #include <atalk/afp.h>
23 #include <atalk/compat.h>
24 #include <atalk/util.h>
31 #include <atalk/logger.h>
32 #include <atalk/server_ipc.h>
36 #include <arpa/inet.h>
40 extern void afp_get_cmdline( int *ac, char ***av );
52 static int afp_version_index;
56 #if defined( sun ) && !defined( __svr4__ ) || defined( ultrix )
59 #define GROUPS_SIZE sizeof(int)
61 #else /* sun __svr4__ ultrix */
64 #define GROUPS_SIZE sizeof(gid_t)
65 #endif /* sun ultrix */
70 * These numbers are scattered throughout the code.
72 static struct afp_versions afp_versions[] = {
73 { "AFPVersion 1.1", 11 },
74 { "AFPVersion 2.0", 20 },
75 { "AFPVersion 2.1", 21 },
83 static struct uam_mod uam_modules = {NULL, NULL, &uam_modules, &uam_modules};
84 static struct uam_obj uam_login = {"", "", 0, {{NULL}}, &uam_login,
86 static struct uam_obj uam_changepw = {"", "", 0, {{NULL}}, &uam_changepw,
89 static struct uam_obj *afp_uam = NULL;
92 void status_versions( data )
99 memcpy(&status, start + AFPSTATUS_VERSOFF, sizeof(status));
100 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
101 data += ntohs( status );
103 for ( i = 0; i < num; i++ ) {
104 len = strlen( afp_versions[ i ].av_name );
106 memcpy( data, afp_versions[ i ].av_name , len );
109 status = htons( data - start );
110 memcpy(start + AFPSTATUS_UAMSOFF, &status, sizeof(status));
113 void status_uams(char *data, const char *authlist)
117 struct uam_obj *uams;
120 memcpy(&status, start + AFPSTATUS_UAMSOFF, sizeof(status));
122 while ((uams = uams->uam_prev) != &uam_login) {
123 if (strstr(authlist, uams->uam_path))
127 data += ntohs( status );
129 while ((uams = uams->uam_prev) != &uam_login) {
130 if (strstr(authlist, uams->uam_path)) {
131 LOG(log_info, logtype_afpd, "uam: \"%s\" available", uams->uam_name);
132 len = strlen( uams->uam_name);
134 memcpy( data, uams->uam_name, len );
140 status = htons(data - start);
141 memcpy(start + AFPSTATUS_ICONOFF, &status, sizeof(status));
144 /* handle errors by closing the connection. this is only needed
145 * by the afp_* functions. */
146 static int send_reply(const AFPObj *obj, const int err)
148 if ((err == AFP_OK) || (err == AFPERR_AUTHCONT))
151 obj->reply(obj->handle, err);
158 static int afp_errpwdexpired(obj, ibuf, ibuflen, rbuf, rbuflen )
161 int ibuflen, *rbuflen;
164 return AFPERR_PWDEXPR;
168 static int set_auth_switch(AFPObj *obj, int expired)
174 * BF: expired password handling
175 * to allow the user to change his/her password we have to allow login
176 * but every following call except for FPChangePassword will be thrown
177 * away with an AFPERR_PWDEXPR error. (thanks to Leland Wallace from Apple
178 * for clarifying this)
181 for (i=0; i<=0xff; i++) {
182 uam_afpserver_action(i, UAM_AFPSERVER_PREAUTH, afp_errpwdexpired, NULL);
184 uam_afpserver_action(AFP_LOGOUT, UAM_AFPSERVER_PREAUTH, afp_logout, NULL);
185 uam_afpserver_action(AFP_CHANGEPW, UAM_AFPSERVER_PREAUTH, afp_changepw, NULL);
188 afp_switch = postauth_switch;
189 switch (afp_version) {
191 uam_afpserver_action(AFP_ENUMERATE_EXT2, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext2, NULL);
193 uam_afpserver_action(AFP_ENUMERATE_EXT, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext, NULL);
194 uam_afpserver_action(AFP_BYTELOCK_EXT, UAM_AFPSERVER_POSTAUTH, afp_bytelock_ext, NULL);
195 /* catsearch_ext uses the same packet as catsearch FIXME double check this, it wasn't true for enue
197 uam_afpserver_action(AFP_CATSEARCH_EXT, UAM_AFPSERVER_POSTAUTH, afp_catsearch_ext, NULL);
198 uam_afpserver_action(AFP_GETSESSTOKEN, UAM_AFPSERVER_POSTAUTH, afp_getsession, NULL);
199 uam_afpserver_action(AFP_READ_EXT, UAM_AFPSERVER_POSTAUTH, afp_read_ext, NULL);
200 uam_afpserver_action(AFP_WRITE_EXT, UAM_AFPSERVER_POSTAUTH, afp_write_ext, NULL);
201 uam_afpserver_action(AFP_DISCTOLDSESS, UAM_AFPSERVER_POSTAUTH, afp_disconnect, NULL);
205 * If first connection to a server is done in classic AFP2.2 version is used
206 * but OSX uses AFP3.x FPzzz command !
208 uam_afpserver_action(AFP_ZZZ, UAM_AFPSERVER_POSTAUTH, afp_zzz, NULL);
216 static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expired)
220 #endif /* ADMIN_GRP */
222 /* UAM had syslog control; afpd needs to reassert itself */
223 set_processname("afpd");
224 syslog_setup(log_debug, logtype_default, logoption_ndelay|logoption_pid, logfacility_daemon);
226 if ( pwd->pw_uid == 0 ) { /* don't allow root login */
227 LOG(log_error, logtype_afpd, "login: root login denied!" );
228 return AFPERR_NOTAUTH;
231 LOG(log_info, logtype_afpd, "login %s (uid %d, gid %d) %s", pwd->pw_name,
232 pwd->pw_uid, pwd->pw_gid , afp_versions[afp_version_index].av_name);
235 if (obj->proto == AFPPROTO_ASP) {
236 ASP asp = obj->handle;
237 int addr_net = ntohs( asp->asp_sat.sat_addr.s_net );
238 int addr_node = asp->asp_sat.sat_addr.s_node;
240 if (obj->options.authprintdir) {
241 if(addr_net && addr_node) { /* Do we have a valid Appletalk address? */
244 int mypid = getpid();
245 struct stat stat_buf;
247 sprintf(nodename, "%s/net%d.%dnode%d", obj->options.authprintdir,
248 addr_net / 256, addr_net % 256, addr_node);
249 LOG(log_info, logtype_afpd, "registering %s (uid %d) on %u.%u as %s",
250 pwd->pw_name, pwd->pw_uid, addr_net, addr_node, nodename);
252 if (stat(nodename, &stat_buf) == 0) { /* file exists */
253 if (S_ISREG(stat_buf.st_mode)) { /* normal file */
255 fp = fopen(nodename, "w");
256 fprintf(fp, "%s:%d\n", pwd->pw_name, mypid);
258 chown( nodename, pwd->pw_uid, -1 );
259 } else { /* somebody is messing with us */
260 LOG(log_error, logtype_afpd, "print authfile %s is not a normal file, it will not be modified", nodename );
262 } else { /* file 'nodename' does not exist */
263 fp = fopen(nodename, "w");
264 fprintf(fp, "%s:%d\n", pwd->pw_name, mypid);
266 chown( nodename, pwd->pw_uid, -1 );
268 } /* if (addr_net && addr_node ) */
269 } /* if (options->authprintdir) */
270 } /* if (obj->proto == AFPPROTO_ASP) */
273 if (initgroups( pwd->pw_name, pwd->pw_gid ) < 0) {
275 LOG(log_info, logtype_afpd, "running with uid %d", geteuid());
276 #else /* RUN_AS_USER */
277 LOG(log_error, logtype_afpd, "login: %s", strerror(errno));
278 return AFPERR_BADUAM;
279 #endif /* RUN_AS_USER */
283 /* Basically if the user is in the admin group, we stay root */
285 if (( ngroups = getgroups( 0, NULL )) < 0 ) {
286 LOG(log_error, logtype_afpd, "login: %s getgroups: %s", pwd->pw_name, strerror(errno) );
287 return AFPERR_BADUAM;
290 if ( NULL == (groups = calloc(ngroups, GROUPS_SIZE)) ) {
291 LOG(log_error, logtype_afpd, "login: %s calloc: %d", ngroups);
292 return AFPERR_BADUAM;
295 if (( ngroups = getgroups( ngroups, groups )) < 0 ) {
296 LOG(log_error, logtype_afpd, "login: %s getgroups: %s", pwd->pw_name, strerror(errno) );
297 return AFPERR_BADUAM;
302 LOG(log_info, logtype_afpd, "obj->options.admingid == %d", obj->options.admingid);
304 if (obj->options.admingid != 0) {
306 for (i = 0; i < ngroups; i++) {
307 if (groups[i] == obj->options.admingid) admin = 1;
312 LOG(log_info, logtype_afpd, "admin login -- %s", pwd->pw_name );
318 struct DSI *dsi = obj->handle;
325 afp_get_cmdline( &argc, &argv );
327 hp = gethostbyaddr( (char *) &dsi->client.sin_addr,
328 sizeof( struct in_addr ),
329 dsi->client.sin_family );
332 clientname = hp->h_name;
334 clientname = inet_ntoa( dsi->client.sin_addr );
336 sprintf( hostname, "%s@%s", pwd->pw_name, clientname );
338 if( sia_become_user( NULL, argc, argv, hostname, pwd->pw_name,
339 NULL, FALSE, NULL, NULL,
340 SIA_BEU_REALLOGIN ) != SIASUCCESS )
341 return AFPERR_BADUAM;
343 LOG(log_info, logtype_afpd, "session from %s (%s)", hostname,
344 inet_ntoa( dsi->client.sin_addr ) );
346 if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
347 LOG(log_error, logtype_afpd, "login: %s %s", pwd->pw_name, strerror(errno) );
348 return AFPERR_BADUAM;
352 if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
353 LOG(log_error, logtype_afpd, "login: %s %s", pwd->pw_name, strerror(errno) );
354 return AFPERR_BADUAM;
358 /* There's probably a better way to do this, but for now, we just
364 #endif /* ADMIN_GRP */
367 set_auth_switch(obj, expired);
369 obj->logout = logout;
373 save_uidgid ( &obj->uidgid );
379 /* ---------------------- */
380 int afp_zzz (obj, ibuf, ibuflen, rbuf, rbuflen ) /* Function 122 */
383 unsigned int ibuflen, *rbuflen;
389 retdata = obj->options.sleep /120;
393 *rbuflen = sizeof(retdata);
394 retdata = htonl(retdata);
395 memcpy(rbuf, &retdata, sizeof(retdata));
398 rbuf += sizeof(retdata);
402 /* ---------------------- */
403 static int create_session_token(AFPObj *obj)
407 /* use 8 bytes for token as OSX, don't know if it helps */
408 if ( sizeof(pid_t) > SESSIONTOKEN_LEN) {
409 LOG(log_error, logtype_afpd, "sizeof(pid_t) > %u", SESSIONTOKEN_LEN );
413 if ( NULL == (obj->sinfo.sessiontoken = malloc(SESSIONTOKEN_LEN)) )
416 memset(obj->sinfo.sessiontoken, 0, SESSIONTOKEN_LEN);
417 obj->sinfo.sessiontoken_len = SESSIONTOKEN_LEN;
419 memcpy(obj->sinfo.sessiontoken, &pid, sizeof(pid_t));
424 static int create_session_key(AFPObj *obj)
426 /* create session key */
427 if (obj->sinfo.sessionkey == NULL) {
428 if (NULL == (obj->sinfo.sessionkey = malloc(SESSIONKEY_LEN)) )
430 uam_random_string(obj, obj->sinfo.sessionkey, SESSIONKEY_LEN);
431 obj->sinfo.sessionkey_len = SESSIONKEY_LEN;
437 /* ---------------------- */
438 int afp_getsession(obj, ibuf, ibuflen, rbuf, rbuflen )
441 unsigned int ibuflen, *rbuflen;
456 memcpy(&type, ibuf, sizeof(type));
458 ibuf += sizeof(type);
459 ibuflen -= sizeof(type);
461 if ( obj->sinfo.sessiontoken == NULL ) {
462 if ( create_session_token( obj ) )
470 case 0: /* old version ?*/
471 tklen = obj->sinfo.sessiontoken_len;
472 token = obj->sinfo.sessiontoken;
474 case 1: /* disconnect */
475 case 2: /* reconnect update id */
476 if (ibuflen >= sizeof(idlen)) {
477 memcpy(&idlen, ibuf, sizeof(idlen));
478 idlen = ntohl(idlen);
479 ibuf += sizeof(idlen);
480 ibuflen -= sizeof(idlen);
481 if (ibuflen < idlen) {
484 /* memcpy (id, ibuf, idlen) */
485 tklen = obj->sinfo.sessiontoken_len;
486 token = obj->sinfo.sessiontoken;
493 memcpy( &idlen, ibuf, sizeof(idlen));
494 idlen = ntohl(idlen);
495 ibuf += sizeof(idlen);
496 ibuflen -= sizeof(idlen);
497 ibuf += sizeof(boottime);
498 ibuflen -= sizeof(boottime);
499 if (ibuflen < idlen || idlen > (90-10)) {
502 server_ipc_write(IPC_GETSESSION, idlen+8, p );
503 tklen = obj->sinfo.sessiontoken_len;
504 token = obj->sinfo.sessiontoken;
507 case 8: /* Panther Kerberos Token */
508 tklen = obj->sinfo.cryptedkey_len;
509 token = obj->sinfo.cryptedkey;
521 memcpy(rbuf, &tp, sizeof(tklen));
522 rbuf += sizeof(tklen);
523 *rbuflen += sizeof(tklen);
525 memcpy(rbuf, token, tklen);
531 /* ---------------------- */
532 int afp_disconnect(obj, ibuf, ibuflen, rbuf, rbuflen )
535 int ibuflen, *rbuflen;
547 /* check for guest user */
548 if ( 0 == (strcasecmp(obj->username, obj->options.guest)) ) {
553 memcpy(&type, ibuf, sizeof(type));
555 ibuf += sizeof(type);
557 memcpy(&tklen, ibuf, sizeof(tklen));
558 tklen = ntohl(tklen);
559 ibuf += sizeof(tklen);
561 if ( sizeof(pid_t) > SESSIONTOKEN_LEN) {
562 LOG(log_error, logtype_afpd, "sizeof(pid_t) > %u", SESSIONTOKEN_LEN );
565 if (tklen != SESSIONTOKEN_LEN) {
568 tklen = sizeof(pid_t);
569 memcpy(&token, ibuf, tklen);
571 /* our stuff is pid + zero pad */
573 for (i = tklen; i < SESSIONTOKEN_LEN; i++, ibuf++) {
579 /* killed old session, not easy */
580 server_ipc_write(IPC_KILLTOKEN, tklen, &token);
583 return AFPERR_SESSCLOS; /* was AFP_OK */
586 /* ---------------------- */
587 static int get_version(obj, ibuf, ibuflen, len)
595 if (!len || len > ibuflen)
596 return AFPERR_BADVERS;
598 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ]);
599 for ( i = 0; i < num; i++ ) {
600 if ( strncmp( ibuf, afp_versions[ i ].av_name , len ) == 0 ) {
601 afp_version = afp_versions[ i ].av_number;
602 afp_version_index = i;
606 if ( i == num ) /* An inappropo version */
607 return AFPERR_BADVERS ;
609 if (afp_version >= 30 && obj->proto != AFPPROTO_DSI)
610 return AFPERR_BADVERS ;
613 if (afp_version >= 30 && sizeof(off_t) != 8) {
614 LOG(log_error, logtype_afpd, "get_version: no LARGE_FILE support recompile!" );
615 return AFPERR_BADVERS ;
621 /* ---------------------- */
622 int afp_login(obj, ibuf, ibuflen, rbuf, rbuflen )
625 int ibuflen, *rbuflen;
627 struct passwd *pwd = NULL;
633 return send_reply(obj, AFPERR_SHUTDOWN );
636 return send_reply(obj, AFPERR_BADVERS );
639 len = (unsigned char) *ibuf++;
642 i = get_version(obj, ibuf, ibuflen, len);
644 return send_reply(obj, i );
650 return send_reply(obj, AFPERR_BADUAM);
652 len = (unsigned char) *ibuf++;
655 if (!len || len > ibuflen)
656 return send_reply(obj, AFPERR_BADUAM);
658 if (NULL == (afp_uam = auth_uamfind(UAM_SERVER_LOGIN, ibuf, len)) )
659 return send_reply(obj, AFPERR_BADUAM);
663 if (AFP_OK != (i = create_session_key(obj)) )
664 return send_reply(obj, i);
666 i = afp_uam->u.uam_login.login(obj, &pwd, ibuf, ibuflen, rbuf, rbuflen);
668 if (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
669 return send_reply(obj, i);
671 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((i==AFPERR_PWDEXPR)?1:0)));
674 /* ---------------------- */
675 int afp_login_ext(obj, ibuf, ibuflen, rbuf, rbuflen )
678 unsigned int ibuflen, *rbuflen;
680 struct passwd *pwd = NULL;
690 return send_reply(obj, AFPERR_SHUTDOWN );
693 return send_reply(obj, AFPERR_BADVERS );
699 len = (unsigned char) *ibuf;
703 i = get_version(obj, ibuf, ibuflen, len);
705 return send_reply(obj, i );
711 return send_reply(obj, AFPERR_BADUAM);
713 len = (unsigned char) *ibuf;
717 if (!len || len > ibuflen)
718 return send_reply(obj, AFPERR_BADUAM);
720 if ((afp_uam = auth_uamfind(UAM_SERVER_LOGIN, ibuf, len)) == NULL)
721 return send_reply(obj, AFPERR_BADUAM);
725 if (!afp_uam->u.uam_login.login_ext) {
726 LOG(log_error, logtype_afpd, "login_ext: uam %s not AFP 3 ready!", afp_uam->uam_name );
727 return send_reply(obj, AFPERR_BADUAM);
730 if (len <= 1 +sizeof(len16))
731 return send_reply(obj, AFPERR_PARAM);
737 return send_reply(obj, AFPERR_PARAM);
739 memcpy(&len16, ibuf, sizeof(len16));
740 ibuf += sizeof(len16);
741 ibuflen -= sizeof(len16);
744 return send_reply(obj, AFPERR_PARAM);
748 /* directory service name */
750 return send_reply(obj, AFPERR_PARAM);
759 return send_reply(obj, AFPERR_PARAM);
760 len = (unsigned char) *ibuf;
765 /* With "No User Authen" it is equal */
766 if (ibuflen < sizeof(len16))
767 return send_reply(obj, AFPERR_PARAM);
768 memcpy(&len16, ibuf, sizeof(len16));
769 ibuf += sizeof(len16);
770 ibuflen -= sizeof(len16);
774 return send_reply(obj, AFPERR_PARAM);
778 LOG(log_error, logtype_afpd, "login_ext: directory service path not null!" );
779 return send_reply(obj, AFPERR_PARAM);
786 if (ibuflen && ((unsigned long) ibuf & 1)) { /* pad character */
791 if (AFP_OK != (i = create_session_key(obj)) ) {
792 return send_reply(obj, i);
795 /* FIXME user name are in UTF8 */
796 i = afp_uam->u.uam_login.login_ext(obj, username, &pwd, ibuf, ibuflen, rbuf, rbuflen);
798 if (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
799 return send_reply(obj, i);
801 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((i==AFPERR_PWDEXPR)?1:0)));
804 /* ---------------------- */
805 int afp_logincont(obj, ibuf, ibuflen, rbuf, rbuflen)
808 int ibuflen, *rbuflen;
810 struct passwd *pwd = NULL;
813 if ( afp_uam == NULL || afp_uam->u.uam_login.logincont == NULL ) {
815 return send_reply(obj, AFPERR_NOTAUTH );
818 ibuf += 2; ibuflen -= 2;
819 err = afp_uam->u.uam_login.logincont(obj, &pwd, ibuf, ibuflen,
821 if (!pwd || ( err != AFP_OK && err != AFPERR_PWDEXPR))
822 return send_reply(obj, err);
824 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((err==AFPERR_PWDEXPR)?1:0)));
828 int afp_logout(obj, ibuf, ibuflen, rbuf, rbuflen)
831 int ibuflen, *rbuflen;
833 LOG(log_info, logtype_afpd, "logout %s", obj->username);
841 /* change password --
842 * NOTE: an FPLogin must already have completed successfully for this
843 * to work. this also does a little pre-processing before it hands
846 int afp_changepw(obj, ibuf, ibuflen, rbuf, rbuflen )
849 int ibuflen, *rbuflen;
851 char username[MACFILELEN + 1], *start = ibuf;
860 /* check if password change is allowed, OS-X ignores the flag.
861 * we shouldn't trust the client on this anyway.
862 * not sure about the "right" error code, NOOP for now */
863 if (!(obj->options.passwdbits & PASSWD_SET))
866 /* make sure we can deal w/ this uam */
867 len = (unsigned char) *ibuf++;
868 if ((uam = auth_uamfind(UAM_SERVER_CHANGEPW, ibuf, len)) == NULL)
869 return AFPERR_BADUAM;
872 if ((len + 1) & 1) /* pad byte */
875 if ( afp_version < 30) {
876 len = (unsigned char) *ibuf++;
877 if ( len > sizeof(username) - 1) {
880 memcpy(username, ibuf, len);
881 username[ len ] = '\0';
883 if ((len + 1) & 1) /* pad byte */
886 /* AFP > 3.0 doesn't pass the username, APF 3.1 specs page 124 */
887 if ( ibuf[0] != '\0' || ibuf[1] != '\0')
890 len = MIN(sizeof(username), strlen(obj->username));
891 memcpy(username, obj->username, len);
892 username[ len ] = '\0';
896 LOG(log_info, logtype_afpd, "changing password for <%s>", username);
898 if (( pwd = uam_getname( obj, username, sizeof(username))) == NULL )
901 /* send it off to the uam. we really don't use ibuflen right now. */
902 ibuflen -= (ibuf - start);
903 ret = uam->u.uam_changepw(obj, username, pwd, ibuf, ibuflen,
905 LOG(log_info, logtype_afpd, "password change %s.",
906 (ret == AFPERR_AUTHCONT) ? "continued" :
907 (ret ? "failed" : "succeeded"));
909 set_auth_switch(obj, 0);
916 int afp_getuserinfo(obj, ibuf, ibuflen, rbuf, rbuflen )
919 int ibuflen, *rbuflen;
928 ibuf += sizeof(id); /* userid is not used in AFP 2.0 */
929 memcpy(&bitmap, ibuf, sizeof(bitmap));
930 bitmap = ntohs(bitmap);
932 /* deal with error cases. we don't have to worry about
933 * AFPERR_ACCESS or AFPERR_NOITEM as geteuid and getegid always
937 if ((bitmap & USERIBIT_ALL) != bitmap)
938 return AFPERR_BITMAP;
940 /* copy the bitmap back to reply buffer */
941 memcpy(rbuf, ibuf, sizeof(bitmap));
942 rbuf += sizeof(bitmap);
943 *rbuflen = sizeof(bitmap);
945 /* copy the user/group info */
946 if (bitmap & USERIBIT_USER) {
947 id = htonl(geteuid());
948 memcpy(rbuf, &id, sizeof(id));
950 *rbuflen += sizeof(id);
953 if (bitmap & USERIBIT_GROUP) {
954 id = htonl(getegid());
955 memcpy(rbuf, &id, sizeof(id));
957 *rbuflen += sizeof(id);
963 #define UAM_LIST(type) (((type) == UAM_SERVER_LOGIN || (type) == UAM_SERVER_LOGIN_EXT) ? &uam_login : \
964 (((type) == UAM_SERVER_CHANGEPW) ? \
965 &uam_changepw : NULL))
967 /* just do a linked list search. this could be sped up with a hashed
968 * list, but i doubt anyone's going to have enough uams to matter. */
969 struct uam_obj *auth_uamfind(const int type, const char *name,
972 struct uam_obj *prev, *start;
974 if (!name || !(start = UAM_LIST(type)))
978 while ((prev = prev->uam_prev) != start)
979 if (strndiacasecmp(prev->uam_name, name, len) == 0)
985 int auth_register(const int type, struct uam_obj *uam)
987 struct uam_obj *start;
989 if (!uam || !uam->uam_name || (*uam->uam_name == '\0'))
992 if (!(start = UAM_LIST(type)))
993 return 1; /* we don't know what to do with it, caller must free it */
995 uam_attach(start, uam);
999 /* load all of the modules */
1000 int auth_load(const char *path, const char *list)
1002 char name[MAXPATHLEN + 1], buf[MAXPATHLEN + 1], *p;
1003 struct uam_mod *mod;
1007 if (!path || !*path || !list || (len = strlen(path)) > sizeof(name) - 2)
1010 strlcpy(buf, list, sizeof(buf));
1011 if ((p = strtok(buf, ",")) == NULL)
1015 if (name[len - 1] != '/') {
1021 strlcpy(name + len, p, sizeof(name) - len);
1022 LOG(log_debug, logtype_afpd, "uam: loading (%s)", name);
1024 if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) {
1026 if (stat(name, &st) == 0) {
1027 if ((mod = uam_load(name, p))) {
1028 uam_attach(&uam_modules, mod);
1029 LOG(log_info, logtype_afpd, "uam: %s loaded", p);
1031 LOG(log_info, logtype_afpd, "uam: %s load failure",p);
1034 LOG(log_info, logtype_afpd, "uam: uam not found (status=%d)", stat(name, &st));
1036 p = strtok(NULL, ",");
1042 /* get rid of all of the uams */
1045 struct uam_mod *mod, *prev, *start = &uam_modules;
1047 prev = start->uam_prev;
1048 while ((mod = prev) != start) {
1049 prev = prev->uam_prev;