2 * Copyright (c) 1990,1993 Regents of The University of Michigan.
3 * All Rights Reserved. See COPYRIGHT.
8 #endif /* HAVE_CONFIG_H */
14 #include <sys/types.h>
15 #include <sys/param.h>
17 #include <arpa/inet.h>
19 #include <atalk/afp.h>
20 #include <atalk/compat.h>
21 #include <atalk/util.h>
31 #include <arpa/inet.h>
35 extern void afp_get_cmdline( int *ac, char ***av );
38 #include <atalk/logger.h>
39 #include <atalk/server_ipc.h>
40 #include <atalk/uuid.h>
54 static int afp_version_index;
58 #if defined( sun ) && !defined( __svr4__ ) || defined( ultrix )
61 #define GROUPS_SIZE sizeof(int)
63 #else /* sun __svr4__ ultrix */
66 #define GROUPS_SIZE sizeof(gid_t)
67 #endif /* sun ultrix */
72 * These numbers are scattered throughout the code.
74 static struct afp_versions afp_versions[] = {
82 static struct uam_mod uam_modules = {NULL, NULL, &uam_modules, &uam_modules};
83 static struct uam_obj uam_login = {"", "", 0, {{NULL, NULL, NULL, NULL }}, &uam_login,
85 static struct uam_obj uam_changepw = {"", "", 0, {{NULL, NULL, NULL, NULL}}, &uam_changepw,
88 static struct uam_obj *afp_uam = NULL;
91 void status_versions( char *data, const DSI *dsi)
95 int len, num, i, count = 0;
97 memcpy(&status, start + AFPSTATUS_VERSOFF, sizeof(status));
98 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
100 for ( i = 0; i < num; i++ ) {
101 if ( !dsi && (afp_versions[ i ].av_number >= 22)) continue;
104 data += ntohs( status );
107 for ( i = 0; i < num; i++ ) {
108 if ( !dsi && (afp_versions[ i ].av_number >= 22)) continue;
109 len = strlen( afp_versions[ i ].av_name );
111 memcpy( data, afp_versions[ i ].av_name , len );
114 status = htons( data - start );
115 memcpy(start + AFPSTATUS_UAMSOFF, &status, sizeof(status));
118 void status_uams(char *data, const char *authlist)
122 struct uam_obj *uams;
125 memcpy(&status, start + AFPSTATUS_UAMSOFF, sizeof(status));
127 while ((uams = uams->uam_prev) != &uam_login) {
128 if (strstr(authlist, uams->uam_path))
132 data += ntohs( status );
134 while ((uams = uams->uam_prev) != &uam_login) {
135 if (strstr(authlist, uams->uam_path)) {
136 LOG(log_info, logtype_afpd, "uam: \"%s\" available", uams->uam_name);
137 len = strlen( uams->uam_name);
139 memcpy( data, uams->uam_name, len );
145 status = htons(data - start);
146 memcpy(start + AFPSTATUS_ICONOFF, &status, sizeof(status));
149 /* handle errors by closing the connection. this is only needed
150 * by the afp_* functions. */
151 static int send_reply(const AFPObj *obj, const int err)
153 if ((err == AFP_OK) || (err == AFPERR_AUTHCONT))
156 obj->reply(obj->handle, err);
162 static int afp_errpwdexpired(AFPObj *obj _U_, char *ibuf _U_, size_t ibuflen _U_,
163 char *rbuf _U_, size_t *rbuflen)
166 return AFPERR_PWDEXPR;
169 static int afp_null_nolog(AFPObj *obj _U_, char *ibuf _U_, size_t ibuflen _U_,
170 char *rbuf _U_, size_t *rbuflen)
173 return( AFPERR_NOOP );
176 static int set_auth_switch(int expired)
182 * BF: expired password handling
183 * to allow the user to change his/her password we have to allow login
184 * but every following call except for FPChangePassword will be thrown
185 * away with an AFPERR_PWDEXPR error. (thanks to Leland Wallace from Apple
186 * for clarifying this)
189 for (i=0; i<=0xff; i++) {
190 uam_afpserver_action(i, UAM_AFPSERVER_PREAUTH, afp_errpwdexpired, NULL);
192 uam_afpserver_action(AFP_LOGOUT, UAM_AFPSERVER_PREAUTH, afp_logout, NULL);
193 uam_afpserver_action(AFP_CHANGEPW, UAM_AFPSERVER_PREAUTH, afp_changepw, NULL);
196 afp_switch = postauth_switch;
197 switch (afp_version) {
202 uam_afpserver_action(AFP_GETACL, UAM_AFPSERVER_POSTAUTH, afp_getacl, NULL);
203 uam_afpserver_action(AFP_SETACL, UAM_AFPSERVER_POSTAUTH, afp_setacl, NULL);
204 uam_afpserver_action(AFP_ACCESS, UAM_AFPSERVER_POSTAUTH, afp_access, NULL);
205 #endif /* HAVE_ACLS */
206 uam_afpserver_action(AFP_GETEXTATTR, UAM_AFPSERVER_POSTAUTH, afp_getextattr, NULL);
207 uam_afpserver_action(AFP_SETEXTATTR, UAM_AFPSERVER_POSTAUTH, afp_setextattr, NULL);
208 uam_afpserver_action(AFP_REMOVEATTR, UAM_AFPSERVER_POSTAUTH, afp_remextattr, NULL);
209 uam_afpserver_action(AFP_LISTEXTATTR, UAM_AFPSERVER_POSTAUTH, afp_listextattr, NULL);
212 uam_afpserver_action(AFP_SYNCDIR, UAM_AFPSERVER_POSTAUTH, afp_syncdir, NULL);
213 uam_afpserver_action(AFP_SYNCFORK, UAM_AFPSERVER_POSTAUTH, afp_syncfork, NULL);
214 uam_afpserver_action(AFP_SPOTLIGHT_PRIVATE, UAM_AFPSERVER_POSTAUTH, afp_null_nolog, NULL);
215 uam_afpserver_action(AFP_ENUMERATE_EXT2, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext2, NULL);
218 uam_afpserver_action(AFP_ENUMERATE_EXT, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext, NULL);
219 uam_afpserver_action(AFP_BYTELOCK_EXT, UAM_AFPSERVER_POSTAUTH, afp_bytelock_ext, NULL);
220 /* catsearch_ext uses the same packet as catsearch FIXME double check this, it wasn't true for enue
222 uam_afpserver_action(AFP_CATSEARCH_EXT, UAM_AFPSERVER_POSTAUTH, afp_catsearch_ext, NULL);
223 uam_afpserver_action(AFP_GETSESSTOKEN, UAM_AFPSERVER_POSTAUTH, afp_getsession, NULL);
224 uam_afpserver_action(AFP_READ_EXT, UAM_AFPSERVER_POSTAUTH, afp_read_ext, NULL);
225 uam_afpserver_action(AFP_WRITE_EXT, UAM_AFPSERVER_POSTAUTH, afp_write_ext, NULL);
226 uam_afpserver_action(AFP_DISCTOLDSESS, UAM_AFPSERVER_POSTAUTH, afp_disconnect, NULL);
230 * If first connection to a server is done in classic AFP2.2 version is used
231 * but OSX uses AFP3.x FPzzz command !
233 uam_afpserver_action(AFP_ZZZ, UAM_AFPSERVER_POSTAUTH, afp_zzz, NULL);
241 static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expired)
245 #endif /* ADMIN_GRP */
248 set_processname("afpd");
251 if ( pwd->pw_uid == 0 ) { /* don't allow root login */
252 LOG(log_error, logtype_afpd, "login: root login denied!" );
253 return AFPERR_NOTAUTH;
256 LOG(log_note, logtype_afpd, "%s Login by %s",
257 afp_versions[afp_version_index].av_name, pwd->pw_name);
259 if (initgroups( pwd->pw_name, pwd->pw_gid ) < 0) {
261 LOG(log_info, logtype_afpd, "running with uid %d", geteuid());
262 #else /* RUN_AS_USER */
263 LOG(log_error, logtype_afpd, "login: %s", strerror(errno));
264 return AFPERR_BADUAM;
265 #endif /* RUN_AS_USER */
269 /* Basically if the user is in the admin group, we stay root */
271 if (( ngroups = getgroups( 0, NULL )) < 0 ) {
272 LOG(log_error, logtype_afpd, "login: %s getgroups: %s", pwd->pw_name, strerror(errno) );
273 return AFPERR_BADUAM;
276 if ( NULL == (groups = calloc(ngroups, GROUPS_SIZE)) ) {
277 LOG(log_error, logtype_afpd, "login: %s calloc: %d", ngroups);
278 return AFPERR_BADUAM;
281 if (( ngroups = getgroups( ngroups, groups )) < 0 ) {
282 LOG(log_error, logtype_afpd, "login: %s getgroups: %s", pwd->pw_name, strerror(errno) );
283 return AFPERR_BADUAM;
287 LOG(log_debug, logtype_afpd, "obj->options.admingid == %d", obj->options.admingid);
289 if (obj->options.admingid != 0) {
291 for (i = 0; i < ngroups; i++) {
292 if (groups[i] == obj->options.admingid) admin = 1;
297 LOG(log_info, logtype_afpd, "admin login -- %s", pwd->pw_name );
300 #endif /* ADMIN_GRP */
303 struct DSI *dsi = obj->handle;
310 afp_get_cmdline( &argc, &argv );
312 hp = gethostbyaddr( (char *) &dsi->client.sin_addr,
313 sizeof( struct in_addr ),
314 dsi->client.sin_family );
317 clientname = hp->h_name;
319 clientname = inet_ntoa( dsi->client.sin_addr );
321 sprintf( hostname, "%s@%s", pwd->pw_name, clientname );
323 if( sia_become_user( NULL, argc, argv, hostname, pwd->pw_name,
324 NULL, FALSE, NULL, NULL,
325 SIA_BEU_REALLOGIN ) != SIASUCCESS )
326 return AFPERR_BADUAM;
328 LOG(log_info, logtype_afpd, "session from %s (%s)", hostname,
329 inet_ntoa( dsi->client.sin_addr ) );
331 if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
332 LOG(log_error, logtype_afpd, "login: %s %s", pwd->pw_name, strerror(errno) );
333 return AFPERR_BADUAM;
337 if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
338 LOG(log_error, logtype_afpd, "login: %s %s", pwd->pw_name, strerror(errno) );
339 return AFPERR_BADUAM;
344 #define GROUPSTR_BUFSIZE 1024
345 char groupsstr[GROUPSTR_BUFSIZE];
347 int j = GROUPSTR_BUFSIZE;
349 int n = snprintf(groupsstr, GROUPSTR_BUFSIZE, "%u", groups[0]);
353 for (int i = 1; i < ngroups; i++) {
354 n = snprintf(s, j, ", %u", groups[i]);
357 LOG(log_debug, logtype_afpd, "login: group string buffer overflow");
363 LOG(log_debug, logtype_afpd, "login: %u supplementary groups: %s", ngroups, groupsstr);
366 /* There's probably a better way to do this, but for now, we just play root */
371 #endif /* ADMIN_GRP */
374 set_auth_switch(expired);
375 /* save our euid, we need it for preexec_close */
376 obj->uid = geteuid();
377 obj->logout = logout;
382 /* ---------------------- */
383 int afp_zzz ( /* Function 122 */
385 char *ibuf _U_, size_t ibuflen _U_,
386 char *rbuf, size_t *rbuflen)
392 retdata = obj->options.sleep /120;
396 *rbuflen = sizeof(retdata);
397 retdata = htonl(retdata);
398 memcpy(rbuf, &retdata, sizeof(retdata));
401 rbuf += sizeof(retdata);
405 /* ---------------------- */
406 static int create_session_token(AFPObj *obj)
410 /* use 8 bytes for token as OSX, don't know if it helps */
411 if ( sizeof(pid_t) > SESSIONTOKEN_LEN) {
412 LOG(log_error, logtype_afpd, "sizeof(pid_t) > %u", SESSIONTOKEN_LEN );
416 if ( NULL == (obj->sinfo.sessiontoken = malloc(SESSIONTOKEN_LEN)) )
419 memset(obj->sinfo.sessiontoken, 0, SESSIONTOKEN_LEN);
420 obj->sinfo.sessiontoken_len = SESSIONTOKEN_LEN;
422 memcpy(obj->sinfo.sessiontoken, &pid, sizeof(pid_t));
427 static int create_session_key(AFPObj *obj)
429 /* create session key */
430 if (obj->sinfo.sessionkey == NULL) {
431 if (NULL == (obj->sinfo.sessionkey = malloc(SESSIONKEY_LEN)) )
433 uam_random_string(obj, obj->sinfo.sessionkey, SESSIONKEY_LEN);
434 obj->sinfo.sessionkey_len = SESSIONKEY_LEN;
440 /* ---------------------- */
443 char *ibuf, size_t ibuflen,
444 char *rbuf, size_t *rbuflen)
456 if (ibuflen < 2 + sizeof(type)) {
463 memcpy(&type, ibuf, sizeof(type));
465 ibuf += sizeof(type);
466 ibuflen -= sizeof(type);
468 if ( obj->sinfo.sessiontoken == NULL ) {
469 if ( create_session_token( obj ) )
477 case 0: /* old version ?*/
478 tklen = obj->sinfo.sessiontoken_len;
479 token = obj->sinfo.sessiontoken;
481 case 1: /* disconnect */
482 case 2: /* reconnect update id */
483 if (ibuflen >= sizeof(idlen)) {
484 memcpy(&idlen, ibuf, sizeof(idlen));
485 idlen = ntohl(idlen);
486 ibuf += sizeof(idlen);
487 ibuflen -= sizeof(idlen);
488 if (ibuflen < idlen) {
491 /* memcpy (id, ibuf, idlen) */
492 tklen = obj->sinfo.sessiontoken_len;
493 token = obj->sinfo.sessiontoken;
500 memcpy( &idlen, ibuf, sizeof(idlen));
501 idlen = ntohl(idlen);
502 ibuf += sizeof(idlen);
503 ibuflen -= sizeof(idlen);
504 ibuf += sizeof(boottime);
505 ibuflen -= sizeof(boottime);
506 if (ibuflen < idlen || idlen > (90-10)) {
509 ipc_child_write(obj->ipc_fd, IPC_GETSESSION, idlen+8, p);
510 tklen = obj->sinfo.sessiontoken_len;
511 token = obj->sinfo.sessiontoken;
514 case 8: /* Panther Kerberos Token */
515 tklen = obj->sinfo.cryptedkey_len;
516 token = obj->sinfo.cryptedkey;
528 memcpy(rbuf, &tp, sizeof(tklen));
529 rbuf += sizeof(tklen);
530 *rbuflen += sizeof(tklen);
532 memcpy(rbuf, token, tklen);
538 /* ---------------------- */
539 int afp_disconnect(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
541 DSI *dsi = (DSI *)obj->handle;
551 /* check for guest user */
552 if ( 0 == (strcasecmp(obj->username, obj->options.guest)) ) {
557 memcpy(&type, ibuf, sizeof(type));
559 ibuf += sizeof(type);
561 memcpy(&tklen, ibuf, sizeof(tklen));
562 tklen = ntohl(tklen);
563 ibuf += sizeof(tklen);
565 if ( sizeof(pid_t) > SESSIONTOKEN_LEN) {
566 LOG(log_error, logtype_afpd, "sizeof(pid_t) > %u", SESSIONTOKEN_LEN );
569 if (tklen != SESSIONTOKEN_LEN) {
572 tklen = sizeof(pid_t);
573 memcpy(&token, ibuf, tklen);
575 /* our stuff is pid + zero pad */
577 for (i = tklen; i < SESSIONTOKEN_LEN; i++, ibuf++) {
583 LOG(log_note, logtype_afpd, "afp_disconnect: trying primary reconnect");
584 dsi->flags |= DSI_RECONINPROG;
586 /* Deactivate tickle timer */
587 const struct itimerval none = {{0, 0}, {0, 0}};
588 setitimer(ITIMER_REAL, &none, NULL);
590 /* check for old session, possibly transfering session from here to there */
591 if (ipc_child_write(obj->ipc_fd, IPC_DISCOLDSESSION, tklen, &token) == -1)
593 /* write uint16_t DSI request ID */
594 if (writet(obj->ipc_fd, &dsi->header.dsi_requestID, 2, 0, 2) != 2) {
595 LOG(log_error, logtype_afpd, "afp_disconnect: couldn't send DSI request ID");
598 /* now send our connected AFP client socket */
599 if (send_fd(obj->ipc_fd, dsi->socket) != 0)
601 /* Now see what happens: either afpd master sends us SIGTERM because our session */
602 /* has been transfered to a old disconnected session, or we continue */
605 if (!(dsi->flags & DSI_RECONINPROG)) { /* deleted in SIGTERM handler */
606 /* Reconnect succeeded, we exit now after sleeping some more */
607 sleep(2); /* sleep some more to give the recon. session time */
608 LOG(log_note, logtype_afpd, "afp_disconnect: primary reconnect succeeded");
613 /* Reinstall tickle timer */
614 setitimer(ITIMER_REAL, &dsi->timer, NULL);
616 LOG(log_error, logtype_afpd, "afp_disconnect: primary reconnect failed");
620 /* ---------------------- */
621 static int get_version(AFPObj *obj, char *ibuf, size_t ibuflen, size_t len)
625 if (!len || len > ibuflen)
626 return AFPERR_BADVERS;
628 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ]);
629 for ( i = 0; i < num; i++ ) {
630 if ( strncmp( ibuf, afp_versions[ i ].av_name , len ) == 0 ) {
631 afp_version = afp_versions[ i ].av_number;
632 afp_version_index = i;
636 if ( i == num ) /* An inappropo version */
637 return AFPERR_BADVERS ;
639 if (afp_version >= 30 && obj->proto != AFPPROTO_DSI)
640 return AFPERR_BADVERS ;
643 if (afp_version >= 30 && sizeof(off_t) != 8) {
644 LOG(log_error, logtype_afpd, "get_version: no LARGE_FILE support recompile!" );
645 return AFPERR_BADVERS ;
651 /* ---------------------- */
652 int afp_login(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
654 struct passwd *pwd = NULL;
661 return send_reply(obj, AFPERR_SHUTDOWN );
664 return send_reply(obj, AFPERR_BADVERS );
667 len = (unsigned char) *ibuf++;
670 i = get_version(obj, ibuf, ibuflen, len);
672 return send_reply(obj, i );
675 return send_reply(obj, AFPERR_BADUAM);
680 len = (unsigned char) *ibuf++;
683 if (!len || len > ibuflen)
684 return send_reply(obj, AFPERR_BADUAM);
686 if (NULL == (afp_uam = auth_uamfind(UAM_SERVER_LOGIN, ibuf, len)) )
687 return send_reply(obj, AFPERR_BADUAM);
691 if (AFP_OK != (i = create_session_key(obj)) )
692 return send_reply(obj, i);
694 i = afp_uam->u.uam_login.login(obj, &pwd, ibuf, ibuflen, rbuf, rbuflen);
696 if (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
697 return send_reply(obj, i);
699 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((i==AFPERR_PWDEXPR)?1:0)));
702 /* ---------------------- */
703 int afp_login_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
705 struct passwd *pwd = NULL;
715 return send_reply(obj, AFPERR_SHUTDOWN );
718 return send_reply(obj, AFPERR_BADVERS );
724 len = (unsigned char) *ibuf;
728 i = get_version(obj, ibuf, ibuflen, len);
730 return send_reply(obj, i );
733 return send_reply(obj, AFPERR_BADUAM);
738 len = (unsigned char) *ibuf;
742 if (!len || len > ibuflen)
743 return send_reply(obj, AFPERR_BADUAM);
745 if ((afp_uam = auth_uamfind(UAM_SERVER_LOGIN, ibuf, len)) == NULL)
746 return send_reply(obj, AFPERR_BADUAM);
750 if (!afp_uam->u.uam_login.login_ext) {
751 LOG(log_error, logtype_afpd, "login_ext: uam %s not AFP 3 ready!", afp_uam->uam_name );
752 return send_reply(obj, AFPERR_BADUAM);
755 if (ibuflen <= 1 +sizeof(len16))
756 return send_reply(obj, AFPERR_PARAM);
762 return send_reply(obj, AFPERR_PARAM);
764 memcpy(&len16, ibuf, sizeof(len16));
765 ibuf += sizeof(len16);
766 ibuflen -= sizeof(len16);
769 return send_reply(obj, AFPERR_PARAM);
773 /* directory service name */
775 return send_reply(obj, AFPERR_PARAM);
784 return send_reply(obj, AFPERR_PARAM);
785 len = (unsigned char) *ibuf;
790 /* With "No User Authen" it is equal */
791 if (ibuflen < sizeof(len16))
792 return send_reply(obj, AFPERR_PARAM);
793 memcpy(&len16, ibuf, sizeof(len16));
794 ibuf += sizeof(len16);
795 ibuflen -= sizeof(len16);
799 return send_reply(obj, AFPERR_PARAM);
803 LOG(log_error, logtype_afpd, "login_ext: directory service path not null!" );
804 return send_reply(obj, AFPERR_PARAM);
811 if (ibuflen && ((unsigned long) ibuf & 1)) { /* pad character */
816 if (AFP_OK != (i = create_session_key(obj)) ) {
817 return send_reply(obj, i);
820 /* FIXME user name are in UTF8 */
821 i = afp_uam->u.uam_login.login_ext(obj, username, &pwd, ibuf, ibuflen, rbuf, rbuflen);
823 if (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
824 return send_reply(obj, i);
826 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((i==AFPERR_PWDEXPR)?1:0)));
829 /* ---------------------- */
830 int afp_logincont(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
832 struct passwd *pwd = NULL;
835 if ( afp_uam == NULL || afp_uam->u.uam_login.logincont == NULL || ibuflen < 2 ) {
837 return send_reply(obj, AFPERR_NOTAUTH );
840 ibuf += 2; ibuflen -= 2;
841 err = afp_uam->u.uam_login.logincont(obj, &pwd, ibuf, ibuflen,
843 if (!pwd || ( err != AFP_OK && err != AFPERR_PWDEXPR))
844 return send_reply(obj, err);
846 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((err==AFPERR_PWDEXPR)?1:0)));
850 int afp_logout(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen _U_)
852 LOG(log_note, logtype_afpd, "AFP logout by %s", obj->username);
860 /* change password --
861 * NOTE: an FPLogin must already have completed successfully for this
862 * to work. this also does a little pre-processing before it hands
865 int afp_changepw(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
867 char username[MACFILELEN + 1], *start = ibuf;
876 /* check if password change is allowed, OS-X ignores the flag.
877 * we shouldn't trust the client on this anyway.
878 * not sure about the "right" error code, NOOP for now */
879 if (!(obj->options.passwdbits & PASSWD_SET))
882 /* make sure we can deal w/ this uam */
883 len = (unsigned char) *ibuf++;
884 if ((uam = auth_uamfind(UAM_SERVER_CHANGEPW, ibuf, len)) == NULL)
885 return AFPERR_BADUAM;
888 if ((len + 1) & 1) /* pad byte */
891 if ( afp_version < 30) {
892 len = (unsigned char) *ibuf++;
893 if ( len > sizeof(username) - 1) {
896 memcpy(username, ibuf, len);
897 username[ len ] = '\0';
899 if ((len + 1) & 1) /* pad byte */
902 /* AFP > 3.0 doesn't pass the username, APF 3.1 specs page 124 */
903 if ( ibuf[0] != '\0' || ibuf[1] != '\0')
906 len = MIN(sizeof(username), strlen(obj->username));
907 memcpy(username, obj->username, len);
908 username[ len ] = '\0';
912 LOG(log_info, logtype_afpd, "changing password for <%s>", username);
914 if (( pwd = uam_getname( obj, username, sizeof(username))) == NULL )
917 /* send it off to the uam. we really don't use ibuflen right now. */
918 if (ibuflen < (size_t)(ibuf - start))
921 ibuflen -= (ibuf - start);
922 ret = uam->u.uam_changepw(obj, username, pwd, ibuf, ibuflen,
924 LOG(log_info, logtype_afpd, "password change %s.",
925 (ret == AFPERR_AUTHCONT) ? "continued" :
926 (ret ? "failed" : "succeeded"));
935 int afp_getuserinfo(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
942 LOG(log_debug, logtype_afpd, "begin afp_getuserinfo:");
947 ibuf += sizeof(id); /* userid is not used in AFP 2.0 */
948 memcpy(&bitmap, ibuf, sizeof(bitmap));
949 bitmap = ntohs(bitmap);
951 /* deal with error cases. we don't have to worry about
952 * AFPERR_ACCESS or AFPERR_NOITEM as geteuid and getegid always
956 if ((bitmap & USERIBIT_ALL) != bitmap)
957 return AFPERR_BITMAP;
959 /* remember place where we store the possibly modified bitmap later */
960 memcpy(rbuf, ibuf, sizeof(bitmap));
962 rbuf += sizeof(bitmap);
963 *rbuflen = sizeof(bitmap);
965 /* copy the user/group info */
966 if (bitmap & USERIBIT_USER) {
967 id = htonl(geteuid());
968 memcpy(rbuf, &id, sizeof(id));
970 *rbuflen += sizeof(id);
973 if (bitmap & USERIBIT_GROUP) {
974 id = htonl(getegid());
975 memcpy(rbuf, &id, sizeof(id));
977 *rbuflen += sizeof(id);
980 if (bitmap & USERIBIT_UUID) {
981 if ( ! (obj->options.flags & OPTION_UUID)) {
982 bitmap &= ~USERIBIT_UUID;
983 bitmap = htons(bitmap);
984 memcpy(bitmapp, &bitmap, sizeof(bitmap));
986 LOG(log_debug, logtype_afpd, "afp_getuserinfo: get UUID for \'%s\'", obj->username);
989 ret = getuuidfromname( obj->username, UUID_USER, uuid);
991 LOG(log_info, logtype_afpd, "afp_getuserinfo: error getting UUID !");
992 return AFPERR_NOITEM;
994 LOG(log_debug, logtype_afpd, "afp_getuserinfo: got UUID: %s", uuid_bin2string(uuid));
996 memcpy(rbuf, uuid, UUID_BINSIZE);
997 rbuf += UUID_BINSIZE;
998 *rbuflen += UUID_BINSIZE;
1002 LOG(log_debug, logtype_afpd, "END afp_getuserinfo:");
1006 #define UAM_LIST(type) (((type) == UAM_SERVER_LOGIN || (type) == UAM_SERVER_LOGIN_EXT) ? &uam_login : \
1007 (((type) == UAM_SERVER_CHANGEPW) ? \
1008 &uam_changepw : NULL))
1010 /* just do a linked list search. this could be sped up with a hashed
1011 * list, but i doubt anyone's going to have enough uams to matter. */
1012 struct uam_obj *auth_uamfind(const int type, const char *name,
1015 struct uam_obj *prev, *start;
1017 if (!name || !(start = UAM_LIST(type)))
1021 while ((prev = prev->uam_prev) != start)
1022 if (strndiacasecmp(prev->uam_name, name, len) == 0)
1028 int auth_register(const int type, struct uam_obj *uam)
1030 struct uam_obj *start;
1032 if (!uam || !uam->uam_name || (*uam->uam_name == '\0'))
1035 if (!(start = UAM_LIST(type)))
1036 return 1; /* we don't know what to do with it, caller must free it */
1038 uam_attach(start, uam);
1042 /* load all of the modules */
1043 int auth_load(const char *path, const char *list)
1045 char name[MAXPATHLEN + 1], buf[MAXPATHLEN + 1], *p;
1046 struct uam_mod *mod;
1050 if (!path || !*path || !list || (len = strlen(path)) > sizeof(name) - 2)
1053 strlcpy(buf, list, sizeof(buf));
1054 if ((p = strtok(buf, ",")) == NULL)
1058 if (name[len - 1] != '/') {
1064 strlcpy(name + len, p, sizeof(name) - len);
1065 LOG(log_debug, logtype_afpd, "uam: loading (%s)", name);
1067 if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) {
1069 if (stat(name, &st) == 0) {
1070 if ((mod = uam_load(name, p))) {
1071 uam_attach(&uam_modules, mod);
1072 LOG(log_debug, logtype_afpd, "uam: %s loaded", p);
1074 LOG(log_error, logtype_afpd, "uam: %s load failure",p);
1077 LOG(log_info, logtype_afpd, "uam: uam not found (status=%d)", stat(name, &st));
1079 p = strtok(NULL, ",");
1085 /* get rid of all of the uams */
1086 void auth_unload(void)
1088 struct uam_mod *mod, *prev, *start = &uam_modules;
1090 prev = start->uam_prev;
1091 while ((mod = prev) != start) {
1092 prev = prev->uam_prev;