2 * $Id: auth.c,v 1.55 2009-02-03 14:20:44 franklahm 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>
33 #include <atalk/uuid.h>
37 #include <arpa/inet.h>
41 extern void afp_get_cmdline( int *ac, char ***av );
50 #ifdef HAVE_NFSv4_ACLS
55 static int afp_version_index;
59 #if defined( sun ) && !defined( __svr4__ ) || defined( ultrix )
62 #define GROUPS_SIZE sizeof(int)
64 #else /* sun __svr4__ ultrix */
67 #define GROUPS_SIZE sizeof(gid_t)
68 #endif /* sun ultrix */
73 * These numbers are scattered throughout the code.
75 static struct afp_versions afp_versions[] = {
76 { "AFPVersion 1.1", 11 },
77 { "AFPVersion 2.0", 20 },
78 { "AFPVersion 2.1", 21 },
87 static struct uam_mod uam_modules = {NULL, NULL, &uam_modules, &uam_modules};
88 static struct uam_obj uam_login = {"", "", 0, {{NULL, NULL, NULL, NULL }}, &uam_login,
90 static struct uam_obj uam_changepw = {"", "", 0, {{NULL, NULL, NULL, NULL}}, &uam_changepw,
93 static struct uam_obj *afp_uam = NULL;
96 void status_versions( data )
103 memcpy(&status, start + AFPSTATUS_VERSOFF, sizeof(status));
104 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
105 data += ntohs( status );
107 for ( i = 0; i < num; i++ ) {
108 len = strlen( afp_versions[ i ].av_name );
110 memcpy( data, afp_versions[ i ].av_name , len );
113 status = htons( data - start );
114 memcpy(start + AFPSTATUS_UAMSOFF, &status, sizeof(status));
117 void status_uams(char *data, const char *authlist)
121 struct uam_obj *uams;
124 memcpy(&status, start + AFPSTATUS_UAMSOFF, sizeof(status));
126 while ((uams = uams->uam_prev) != &uam_login) {
127 if (strstr(authlist, uams->uam_path))
131 data += ntohs( status );
133 while ((uams = uams->uam_prev) != &uam_login) {
134 if (strstr(authlist, uams->uam_path)) {
135 LOG(log_info, logtype_afpd, "uam: \"%s\" available", uams->uam_name);
136 len = strlen( uams->uam_name);
138 memcpy( data, uams->uam_name, len );
144 status = htons(data - start);
145 memcpy(start + AFPSTATUS_ICONOFF, &status, sizeof(status));
148 /* handle errors by closing the connection. this is only needed
149 * by the afp_* functions. */
150 static int send_reply(const AFPObj *obj, const int err)
152 if ((err == AFP_OK) || (err == AFPERR_AUTHCONT))
155 obj->reply(obj->handle, err);
161 static int afp_errpwdexpired(obj, ibuf, ibuflen, rbuf, rbuflen )
163 char *ibuf _U_, *rbuf _U_;
164 int ibuflen _U_, *rbuflen;
167 return AFPERR_PWDEXPR;
171 static int set_auth_switch(int expired)
177 * BF: expired password handling
178 * to allow the user to change his/her password we have to allow login
179 * but every following call except for FPChangePassword will be thrown
180 * away with an AFPERR_PWDEXPR error. (thanks to Leland Wallace from Apple
181 * for clarifying this)
184 for (i=0; i<=0xff; i++) {
185 uam_afpserver_action(i, UAM_AFPSERVER_PREAUTH, afp_errpwdexpired, NULL);
187 uam_afpserver_action(AFP_LOGOUT, UAM_AFPSERVER_PREAUTH, afp_logout, NULL);
188 uam_afpserver_action(AFP_CHANGEPW, UAM_AFPSERVER_PREAUTH, afp_changepw, NULL);
191 afp_switch = postauth_switch;
192 switch (afp_version) {
194 #ifdef HAVE_NFSv4_ACLS
195 uam_afpserver_action(73, UAM_AFPSERVER_POSTAUTH, afp_getacl, NULL);
196 uam_afpserver_action(74, UAM_AFPSERVER_POSTAUTH, afp_setacl, NULL);
197 uam_afpserver_action(75, UAM_AFPSERVER_POSTAUTH, afp_access, NULL);
200 uam_afpserver_action(AFP_ENUMERATE_EXT2, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext2, NULL);
202 uam_afpserver_action(AFP_ENUMERATE_EXT, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext, NULL);
203 uam_afpserver_action(AFP_BYTELOCK_EXT, UAM_AFPSERVER_POSTAUTH, afp_bytelock_ext, NULL);
204 /* catsearch_ext uses the same packet as catsearch FIXME double check this, it wasn't true for enue
206 uam_afpserver_action(AFP_CATSEARCH_EXT, UAM_AFPSERVER_POSTAUTH, afp_catsearch_ext, NULL);
207 uam_afpserver_action(AFP_GETSESSTOKEN, UAM_AFPSERVER_POSTAUTH, afp_getsession, NULL);
208 uam_afpserver_action(AFP_READ_EXT, UAM_AFPSERVER_POSTAUTH, afp_read_ext, NULL);
209 uam_afpserver_action(AFP_WRITE_EXT, UAM_AFPSERVER_POSTAUTH, afp_write_ext, NULL);
210 uam_afpserver_action(AFP_DISCTOLDSESS, UAM_AFPSERVER_POSTAUTH, afp_disconnect, NULL);
214 * If first connection to a server is done in classic AFP2.2 version is used
215 * but OSX uses AFP3.x FPzzz command !
217 uam_afpserver_action(AFP_ZZZ, UAM_AFPSERVER_POSTAUTH, afp_zzz, NULL);
225 static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expired)
229 #endif /* ADMIN_GRP */
231 /* UAM had syslog control; afpd needs to reassert itself */
232 set_processname("afpd");
233 syslog_setup(log_debug, logtype_default, logoption_ndelay|logoption_pid, logfacility_daemon);
235 if ( pwd->pw_uid == 0 ) { /* don't allow root login */
236 LOG(log_error, logtype_afpd, "login: root login denied!" );
237 return AFPERR_NOTAUTH;
240 LOG(log_info, logtype_afpd, "login %s (uid %d, gid %d) %s", pwd->pw_name,
241 pwd->pw_uid, pwd->pw_gid , afp_versions[afp_version_index].av_name);
244 if (obj->proto == AFPPROTO_ASP) {
245 ASP asp = obj->handle;
246 int addr_net = ntohs( asp->asp_sat.sat_addr.s_net );
247 int addr_node = asp->asp_sat.sat_addr.s_node;
249 if (obj->options.authprintdir) {
250 if(addr_net && addr_node) { /* Do we have a valid Appletalk address? */
253 int mypid = getpid();
254 struct stat stat_buf;
256 sprintf(nodename, "%s/net%d.%dnode%d", obj->options.authprintdir,
257 addr_net / 256, addr_net % 256, addr_node);
258 LOG(log_info, logtype_afpd, "registering %s (uid %d) on %u.%u as %s",
259 pwd->pw_name, pwd->pw_uid, addr_net, addr_node, nodename);
261 if (stat(nodename, &stat_buf) == 0) { /* file exists */
262 if (S_ISREG(stat_buf.st_mode)) { /* normal file */
264 fp = fopen(nodename, "w");
265 fprintf(fp, "%s:%d\n", pwd->pw_name, mypid);
267 chown( nodename, pwd->pw_uid, -1 );
268 } else { /* somebody is messing with us */
269 LOG(log_error, logtype_afpd, "print authfile %s is not a normal file, it will not be modified", nodename );
271 } else { /* file 'nodename' does not exist */
272 fp = fopen(nodename, "w");
273 fprintf(fp, "%s:%d\n", pwd->pw_name, mypid);
275 chown( nodename, pwd->pw_uid, -1 );
277 } /* if (addr_net && addr_node ) */
278 } /* if (options->authprintdir) */
279 } /* if (obj->proto == AFPPROTO_ASP) */
282 if (initgroups( pwd->pw_name, pwd->pw_gid ) < 0) {
284 LOG(log_info, logtype_afpd, "running with uid %d", geteuid());
285 #else /* RUN_AS_USER */
286 LOG(log_error, logtype_afpd, "login: %s", strerror(errno));
287 return AFPERR_BADUAM;
288 #endif /* RUN_AS_USER */
292 /* Basically if the user is in the admin group, we stay root */
294 if (( ngroups = getgroups( 0, NULL )) < 0 ) {
295 LOG(log_error, logtype_afpd, "login: %s getgroups: %s", pwd->pw_name, strerror(errno) );
296 return AFPERR_BADUAM;
299 if ( NULL == (groups = calloc(ngroups, GROUPS_SIZE)) ) {
300 LOG(log_error, logtype_afpd, "login: %s calloc: %d", ngroups);
301 return AFPERR_BADUAM;
304 if (( ngroups = getgroups( ngroups, groups )) < 0 ) {
305 LOG(log_error, logtype_afpd, "login: %s getgroups: %s", pwd->pw_name, strerror(errno) );
306 return AFPERR_BADUAM;
311 LOG(log_info, logtype_afpd, "obj->options.admingid == %d", obj->options.admingid);
313 if (obj->options.admingid != 0) {
315 for (i = 0; i < ngroups; i++) {
316 if (groups[i] == obj->options.admingid) admin = 1;
321 LOG(log_info, logtype_afpd, "admin login -- %s", pwd->pw_name );
327 struct DSI *dsi = obj->handle;
334 afp_get_cmdline( &argc, &argv );
336 hp = gethostbyaddr( (char *) &dsi->client.sin_addr,
337 sizeof( struct in_addr ),
338 dsi->client.sin_family );
341 clientname = hp->h_name;
343 clientname = inet_ntoa( dsi->client.sin_addr );
345 sprintf( hostname, "%s@%s", pwd->pw_name, clientname );
347 if( sia_become_user( NULL, argc, argv, hostname, pwd->pw_name,
348 NULL, FALSE, NULL, NULL,
349 SIA_BEU_REALLOGIN ) != SIASUCCESS )
350 return AFPERR_BADUAM;
352 LOG(log_info, logtype_afpd, "session from %s (%s)", hostname,
353 inet_ntoa( dsi->client.sin_addr ) );
355 if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
356 LOG(log_error, logtype_afpd, "login: %s %s", pwd->pw_name, strerror(errno) );
357 return AFPERR_BADUAM;
361 if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
362 LOG(log_error, logtype_afpd, "login: %s %s", pwd->pw_name, strerror(errno) );
363 return AFPERR_BADUAM;
367 /* There's probably a better way to do this, but for now, we just
373 #endif /* ADMIN_GRP */
376 set_auth_switch(expired);
378 obj->logout = logout;
382 save_uidgid ( &obj->uidgid );
388 /* ---------------------- */
389 int afp_zzz (obj, ibuf, ibuflen, rbuf, rbuflen ) /* Function 122 */
391 char *ibuf _U_, *rbuf;
392 unsigned int ibuflen _U_, *rbuflen;
398 retdata = obj->options.sleep /120;
402 *rbuflen = sizeof(retdata);
403 retdata = htonl(retdata);
404 memcpy(rbuf, &retdata, sizeof(retdata));
407 rbuf += sizeof(retdata);
411 /* ---------------------- */
412 static int create_session_token(AFPObj *obj)
416 /* use 8 bytes for token as OSX, don't know if it helps */
417 if ( sizeof(pid_t) > SESSIONTOKEN_LEN) {
418 LOG(log_error, logtype_afpd, "sizeof(pid_t) > %u", SESSIONTOKEN_LEN );
422 if ( NULL == (obj->sinfo.sessiontoken = malloc(SESSIONTOKEN_LEN)) )
425 memset(obj->sinfo.sessiontoken, 0, SESSIONTOKEN_LEN);
426 obj->sinfo.sessiontoken_len = SESSIONTOKEN_LEN;
428 memcpy(obj->sinfo.sessiontoken, &pid, sizeof(pid_t));
433 static int create_session_key(AFPObj *obj)
435 /* create session key */
436 if (obj->sinfo.sessionkey == NULL) {
437 if (NULL == (obj->sinfo.sessionkey = malloc(SESSIONKEY_LEN)) )
439 uam_random_string(obj, obj->sinfo.sessionkey, SESSIONKEY_LEN);
440 obj->sinfo.sessionkey_len = SESSIONKEY_LEN;
446 /* ---------------------- */
447 int afp_getsession(obj, ibuf, ibuflen, rbuf, rbuflen )
450 unsigned int ibuflen, *rbuflen;
465 memcpy(&type, ibuf, sizeof(type));
467 ibuf += sizeof(type);
468 ibuflen -= sizeof(type);
470 if ( obj->sinfo.sessiontoken == NULL ) {
471 if ( create_session_token( obj ) )
479 case 0: /* old version ?*/
480 tklen = obj->sinfo.sessiontoken_len;
481 token = obj->sinfo.sessiontoken;
483 case 1: /* disconnect */
484 case 2: /* reconnect update id */
485 if (ibuflen >= sizeof(idlen)) {
486 memcpy(&idlen, ibuf, sizeof(idlen));
487 idlen = ntohl(idlen);
488 ibuf += sizeof(idlen);
489 ibuflen -= sizeof(idlen);
490 if (ibuflen < idlen) {
493 /* memcpy (id, ibuf, idlen) */
494 tklen = obj->sinfo.sessiontoken_len;
495 token = obj->sinfo.sessiontoken;
502 memcpy( &idlen, ibuf, sizeof(idlen));
503 idlen = ntohl(idlen);
504 ibuf += sizeof(idlen);
505 ibuflen -= sizeof(idlen);
506 ibuf += sizeof(boottime);
507 ibuflen -= sizeof(boottime);
508 if (ibuflen < idlen || idlen > (90-10)) {
511 server_ipc_write(IPC_GETSESSION, idlen+8, p );
512 tklen = obj->sinfo.sessiontoken_len;
513 token = obj->sinfo.sessiontoken;
516 case 8: /* Panther Kerberos Token */
517 tklen = obj->sinfo.cryptedkey_len;
518 token = obj->sinfo.cryptedkey;
530 memcpy(rbuf, &tp, sizeof(tklen));
531 rbuf += sizeof(tklen);
532 *rbuflen += sizeof(tklen);
534 memcpy(rbuf, token, tklen);
540 /* ---------------------- */
541 int afp_disconnect(obj, ibuf, ibuflen, rbuf, rbuflen )
543 char *ibuf, *rbuf _U_;
544 int ibuflen _U_, *rbuflen;
556 /* check for guest user */
557 if ( 0 == (strcasecmp(obj->username, obj->options.guest)) ) {
562 memcpy(&type, ibuf, sizeof(type));
564 ibuf += sizeof(type);
566 memcpy(&tklen, ibuf, sizeof(tklen));
567 tklen = ntohl(tklen);
568 ibuf += sizeof(tklen);
570 if ( sizeof(pid_t) > SESSIONTOKEN_LEN) {
571 LOG(log_error, logtype_afpd, "sizeof(pid_t) > %u", SESSIONTOKEN_LEN );
574 if (tklen != SESSIONTOKEN_LEN) {
577 tklen = sizeof(pid_t);
578 memcpy(&token, ibuf, tklen);
580 /* our stuff is pid + zero pad */
582 for (i = tklen; i < SESSIONTOKEN_LEN; i++, ibuf++) {
588 /* killed old session, not easy */
589 server_ipc_write(IPC_KILLTOKEN, tklen, &token);
592 return AFPERR_SESSCLOS; /* was AFP_OK */
595 /* ---------------------- */
596 static int get_version(obj, ibuf, ibuflen, len)
604 if (!len || len > ibuflen)
605 return AFPERR_BADVERS;
607 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ]);
608 for ( i = 0; i < num; i++ ) {
609 if ( strncmp( ibuf, afp_versions[ i ].av_name , len ) == 0 ) {
610 afp_version = afp_versions[ i ].av_number;
611 afp_version_index = i;
615 if ( i == num ) /* An inappropo version */
616 return AFPERR_BADVERS ;
618 if (afp_version >= 30 && obj->proto != AFPPROTO_DSI)
619 return AFPERR_BADVERS ;
622 if (afp_version >= 30 && sizeof(off_t) != 8) {
623 LOG(log_error, logtype_afpd, "get_version: no LARGE_FILE support recompile!" );
624 return AFPERR_BADVERS ;
630 /* ---------------------- */
631 int afp_login(obj, ibuf, ibuflen, rbuf, rbuflen )
634 int ibuflen, *rbuflen;
636 struct passwd *pwd = NULL;
642 return send_reply(obj, AFPERR_SHUTDOWN );
645 return send_reply(obj, AFPERR_BADVERS );
648 len = (unsigned char) *ibuf++;
651 i = get_version(obj, ibuf, ibuflen, len);
653 return send_reply(obj, i );
659 return send_reply(obj, AFPERR_BADUAM);
661 len = (unsigned char) *ibuf++;
664 if (!len || len > ibuflen)
665 return send_reply(obj, AFPERR_BADUAM);
667 if (NULL == (afp_uam = auth_uamfind(UAM_SERVER_LOGIN, ibuf, len)) )
668 return send_reply(obj, AFPERR_BADUAM);
672 if (AFP_OK != (i = create_session_key(obj)) )
673 return send_reply(obj, i);
675 i = afp_uam->u.uam_login.login(obj, &pwd, ibuf, ibuflen, rbuf, rbuflen);
677 if (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
678 return send_reply(obj, i);
680 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((i==AFPERR_PWDEXPR)?1:0)));
683 /* ---------------------- */
684 int afp_login_ext(obj, ibuf, ibuflen, rbuf, rbuflen )
687 unsigned int ibuflen, *rbuflen;
689 struct passwd *pwd = NULL;
699 return send_reply(obj, AFPERR_SHUTDOWN );
702 return send_reply(obj, AFPERR_BADVERS );
708 len = (unsigned char) *ibuf;
712 i = get_version(obj, ibuf, ibuflen, len);
714 return send_reply(obj, i );
720 return send_reply(obj, AFPERR_BADUAM);
722 len = (unsigned char) *ibuf;
726 if (!len || len > ibuflen)
727 return send_reply(obj, AFPERR_BADUAM);
729 if ((afp_uam = auth_uamfind(UAM_SERVER_LOGIN, ibuf, len)) == NULL)
730 return send_reply(obj, AFPERR_BADUAM);
734 if (!afp_uam->u.uam_login.login_ext) {
735 LOG(log_error, logtype_afpd, "login_ext: uam %s not AFP 3 ready!", afp_uam->uam_name );
736 return send_reply(obj, AFPERR_BADUAM);
739 if (len <= 1 +sizeof(len16))
740 return send_reply(obj, AFPERR_PARAM);
746 return send_reply(obj, AFPERR_PARAM);
748 memcpy(&len16, ibuf, sizeof(len16));
749 ibuf += sizeof(len16);
750 ibuflen -= sizeof(len16);
753 return send_reply(obj, AFPERR_PARAM);
757 /* directory service name */
759 return send_reply(obj, AFPERR_PARAM);
768 return send_reply(obj, AFPERR_PARAM);
769 len = (unsigned char) *ibuf;
774 /* With "No User Authen" it is equal */
775 if (ibuflen < sizeof(len16))
776 return send_reply(obj, AFPERR_PARAM);
777 memcpy(&len16, ibuf, sizeof(len16));
778 ibuf += sizeof(len16);
779 ibuflen -= sizeof(len16);
783 return send_reply(obj, AFPERR_PARAM);
787 LOG(log_error, logtype_afpd, "login_ext: directory service path not null!" );
788 return send_reply(obj, AFPERR_PARAM);
795 if (ibuflen && ((unsigned long) ibuf & 1)) { /* pad character */
800 if (AFP_OK != (i = create_session_key(obj)) ) {
801 return send_reply(obj, i);
804 /* FIXME user name are in UTF8 */
805 i = afp_uam->u.uam_login.login_ext(obj, username, &pwd, ibuf, ibuflen, rbuf, rbuflen);
807 if (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
808 return send_reply(obj, i);
810 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((i==AFPERR_PWDEXPR)?1:0)));
813 /* ---------------------- */
814 int afp_logincont(obj, ibuf, ibuflen, rbuf, rbuflen)
817 int ibuflen, *rbuflen;
819 struct passwd *pwd = NULL;
822 if ( afp_uam == NULL || afp_uam->u.uam_login.logincont == NULL ) {
824 return send_reply(obj, AFPERR_NOTAUTH );
827 ibuf += 2; ibuflen -= 2;
828 err = afp_uam->u.uam_login.logincont(obj, &pwd, ibuf, ibuflen,
830 if (!pwd || ( err != AFP_OK && err != AFPERR_PWDEXPR))
831 return send_reply(obj, err);
833 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((err==AFPERR_PWDEXPR)?1:0)));
837 int afp_logout(obj, ibuf, ibuflen, rbuf, rbuflen)
839 char *ibuf _U_, *rbuf _U_;
840 int ibuflen _U_, *rbuflen _U_;
842 LOG(log_info, logtype_afpd, "logout %s", obj->username);
850 /* change password --
851 * NOTE: an FPLogin must already have completed successfully for this
852 * to work. this also does a little pre-processing before it hands
855 int afp_changepw(obj, ibuf, ibuflen, rbuf, rbuflen )
858 int ibuflen, *rbuflen;
860 char username[MACFILELEN + 1], *start = ibuf;
869 /* check if password change is allowed, OS-X ignores the flag.
870 * we shouldn't trust the client on this anyway.
871 * not sure about the "right" error code, NOOP for now */
872 if (!(obj->options.passwdbits & PASSWD_SET))
875 /* make sure we can deal w/ this uam */
876 len = (unsigned char) *ibuf++;
877 if ((uam = auth_uamfind(UAM_SERVER_CHANGEPW, ibuf, len)) == NULL)
878 return AFPERR_BADUAM;
881 if ((len + 1) & 1) /* pad byte */
884 if ( afp_version < 30) {
885 len = (unsigned char) *ibuf++;
886 if ( len > sizeof(username) - 1) {
889 memcpy(username, ibuf, len);
890 username[ len ] = '\0';
892 if ((len + 1) & 1) /* pad byte */
895 /* AFP > 3.0 doesn't pass the username, APF 3.1 specs page 124 */
896 if ( ibuf[0] != '\0' || ibuf[1] != '\0')
899 len = MIN(sizeof(username), strlen(obj->username));
900 memcpy(username, obj->username, len);
901 username[ len ] = '\0';
905 LOG(log_info, logtype_afpd, "changing password for <%s>", username);
907 if (( pwd = uam_getname( obj, username, sizeof(username))) == NULL )
910 /* send it off to the uam. we really don't use ibuflen right now. */
911 ibuflen -= (ibuf - start);
912 ret = uam->u.uam_changepw(obj, username, pwd, ibuf, ibuflen,
914 LOG(log_info, logtype_afpd, "password change %s.",
915 (ret == AFPERR_AUTHCONT) ? "continued" :
916 (ret ? "failed" : "succeeded"));
925 int afp_getuserinfo(obj, ibuf, ibuflen, rbuf, rbuflen )
928 int ibuflen _U_, *rbuflen;
937 LOG(log_debug, logtype_afpd, "begin afp_getuserinfo:");
942 ibuf += sizeof(id); /* userid is not used in AFP 2.0 */
943 memcpy(&bitmap, ibuf, sizeof(bitmap));
944 bitmap = ntohs(bitmap);
946 /* deal with error cases. we don't have to worry about
947 * AFPERR_ACCESS or AFPERR_NOITEM as geteuid and getegid always
951 if ((bitmap & USERIBIT_ALL) != bitmap)
952 return AFPERR_BITMAP;
954 /* copy the bitmap back to reply buffer */
955 memcpy(rbuf, ibuf, sizeof(bitmap));
956 rbuf += sizeof(bitmap);
957 *rbuflen = sizeof(bitmap);
959 /* copy the user/group info */
960 if (bitmap & USERIBIT_USER) {
961 id = htonl(geteuid());
962 memcpy(rbuf, &id, sizeof(id));
964 *rbuflen += sizeof(id);
967 if (bitmap & USERIBIT_GROUP) {
968 id = htonl(getegid());
969 memcpy(rbuf, &id, sizeof(id));
971 *rbuflen += sizeof(id);
974 #ifdef HAVE_NFSv4_ACLS
975 if (bitmap & USERIBIT_UUID) {
976 if ( ! (obj->options.flags & OPTION_UUID))
977 return AFPERR_BITMAP;
978 LOG(log_debug, logtype_afpd, "afp_getuserinfo: get UUID for \'%s\'", obj->username);
979 ret = getuuidfromname( obj->username, UUID_USER, uuid);
981 LOG(log_info, logtype_afpd, "afp_getuserinfo: error getting UUID !");
982 return AFPERR_NOITEM;
984 uuid_bin2string( uuid, &uuidstring);
985 LOG(log_debug, logtype_afpd, "afp_getuserinfo: got UUID: %s", uuidstring);
987 memcpy(rbuf, uuid, UUID_BINSIZE);
988 rbuf += UUID_BINSIZE;
989 *rbuflen += UUID_BINSIZE;
993 LOG(log_debug, logtype_afpd, "END afp_getuserinfo:");
996 #define UAM_LIST(type) (((type) == UAM_SERVER_LOGIN || (type) == UAM_SERVER_LOGIN_EXT) ? &uam_login : \
997 (((type) == UAM_SERVER_CHANGEPW) ? \
998 &uam_changepw : NULL))
1000 /* just do a linked list search. this could be sped up with a hashed
1001 * list, but i doubt anyone's going to have enough uams to matter. */
1002 struct uam_obj *auth_uamfind(const int type, const char *name,
1005 struct uam_obj *prev, *start;
1007 if (!name || !(start = UAM_LIST(type)))
1011 while ((prev = prev->uam_prev) != start)
1012 if (strndiacasecmp(prev->uam_name, name, len) == 0)
1018 int auth_register(const int type, struct uam_obj *uam)
1020 struct uam_obj *start;
1022 if (!uam || !uam->uam_name || (*uam->uam_name == '\0'))
1025 if (!(start = UAM_LIST(type)))
1026 return 1; /* we don't know what to do with it, caller must free it */
1028 uam_attach(start, uam);
1032 /* load all of the modules */
1033 int auth_load(const char *path, const char *list)
1035 char name[MAXPATHLEN + 1], buf[MAXPATHLEN + 1], *p;
1036 struct uam_mod *mod;
1040 if (!path || !*path || !list || (len = strlen(path)) > sizeof(name) - 2)
1043 strlcpy(buf, list, sizeof(buf));
1044 if ((p = strtok(buf, ",")) == NULL)
1048 if (name[len - 1] != '/') {
1054 strlcpy(name + len, p, sizeof(name) - len);
1055 LOG(log_debug, logtype_afpd, "uam: loading (%s)", name);
1057 if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) {
1059 if (stat(name, &st) == 0) {
1060 if ((mod = uam_load(name, p))) {
1061 uam_attach(&uam_modules, mod);
1062 LOG(log_info, logtype_afpd, "uam: %s loaded", p);
1064 LOG(log_info, logtype_afpd, "uam: %s load failure",p);
1067 LOG(log_info, logtype_afpd, "uam: uam not found (status=%d)", stat(name, &st));
1069 p = strtok(NULL, ",");
1075 /* get rid of all of the uams */
1078 struct uam_mod *mod, *prev, *start = &uam_modules;
1080 prev = start->uam_prev;
1081 while ((mod = prev) != start) {
1082 prev = prev->uam_prev;