2 * $Id: auth.c,v 1.44.2.3.2.9 2004-02-14 00:30:50 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;
55 #if defined( __svr4__ ) && !defined( NGROUPS )
56 #define NGROUPS NGROUPS_MAX
57 #endif /* __svr4__ NGROUPS */
58 #if defined( sun ) && !defined( __svr4__ ) || defined( ultrix )
59 int groups[ NGROUPS ];
60 #else /* sun __svr4__ ultrix */
61 #if defined( __svr4__ ) && !defined( NGROUPS )
62 #define NGROUPS NGROUPS_MAX
63 #endif /* __svr4__ NGROUPS */
64 gid_t groups[ NGROUPS ];
65 #endif /* sun ultrix */
69 * These numbers are scattered throughout the code.
71 static struct afp_versions afp_versions[] = {
72 { "AFPVersion 1.1", 11 },
73 { "AFPVersion 2.0", 20 },
74 { "AFPVersion 2.1", 21 },
82 static struct uam_mod uam_modules = {NULL, NULL, &uam_modules, &uam_modules};
83 static struct uam_obj uam_login = {"", "", 0, {{NULL}}, &uam_login,
85 static struct uam_obj uam_changepw = {"", "", 0, {{NULL}}, &uam_changepw,
88 static struct uam_obj *afp_uam = NULL;
91 void status_versions( data )
98 memcpy(&status, start + AFPSTATUS_VERSOFF, sizeof(status));
99 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
100 data += ntohs( status );
102 for ( i = 0; i < num; i++ ) {
103 len = strlen( afp_versions[ i ].av_name );
105 memcpy( data, afp_versions[ i ].av_name , len );
108 status = htons( data - start );
109 memcpy(start + AFPSTATUS_UAMSOFF, &status, sizeof(status));
112 void status_uams(char *data, const char *authlist)
116 struct uam_obj *uams;
119 memcpy(&status, start + AFPSTATUS_UAMSOFF, sizeof(status));
121 while ((uams = uams->uam_prev) != &uam_login) {
122 if (strstr(authlist, uams->uam_path))
126 data += ntohs( status );
128 while ((uams = uams->uam_prev) != &uam_login) {
129 if (strstr(authlist, uams->uam_path)) {
130 LOG(log_info, logtype_afpd, "uam: \"%s\" available", uams->uam_name);
131 len = strlen( uams->uam_name);
133 memcpy( data, uams->uam_name, len );
139 status = htons(data - start);
140 memcpy(start + AFPSTATUS_ICONOFF, &status, sizeof(status));
143 /* handle errors by closing the connection. this is only needed
144 * by the afp_* functions. */
145 static int send_reply(const AFPObj *obj, const int err)
147 if ((err == AFP_OK) || (err == AFPERR_AUTHCONT))
150 obj->reply(obj->handle, err);
157 static int afp_errpwdexpired(obj, ibuf, ibuflen, rbuf, rbuflen )
160 int ibuflen, *rbuflen;
163 return AFPERR_PWDEXPR;
167 static int set_auth_switch(AFPObj *obj, int expired)
173 * BF: expired password handling
174 * to allow the user to change his/her password we have to allow login
175 * but every following call except for FPChangePassword will be thrown
176 * away with an AFPERR_PWDEXPR error. (thanks to Leland Wallace from Apple
177 * for clarifying this)
180 for (i=0; i<=0xff; i++) {
181 uam_afpserver_action(i, UAM_AFPSERVER_PREAUTH, afp_errpwdexpired, NULL);
183 uam_afpserver_action(AFP_LOGOUT, UAM_AFPSERVER_PREAUTH, afp_logout, NULL);
184 uam_afpserver_action(AFP_CHANGEPW, UAM_AFPSERVER_PREAUTH, afp_changepw, NULL);
187 afp_switch = postauth_switch;
188 switch (afp_version) {
190 uam_afpserver_action(AFP_ENUMERATE_EXT2, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext2, NULL);
192 uam_afpserver_action(AFP_ENUMERATE_EXT, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext, NULL);
193 uam_afpserver_action(AFP_BYTELOCK_EXT, UAM_AFPSERVER_POSTAUTH, afp_bytelock_ext, NULL);
194 /* catsearch_ext uses the same packet as catsearch FIXME double check this, it wasn't true for enue
196 uam_afpserver_action(AFP_CATSEARCH_EXT, UAM_AFPSERVER_POSTAUTH, afp_catsearch_ext, NULL);
197 uam_afpserver_action(AFP_GETSESSTOKEN, UAM_AFPSERVER_POSTAUTH, afp_getsession, NULL);
198 uam_afpserver_action(AFP_READ_EXT, UAM_AFPSERVER_POSTAUTH, afp_read_ext, NULL);
199 uam_afpserver_action(AFP_WRITE_EXT, UAM_AFPSERVER_POSTAUTH, afp_write_ext, NULL);
200 uam_afpserver_action(AFP_DISCTOLDSESS, UAM_AFPSERVER_POSTAUTH, afp_disconnect, NULL);
204 * If first connection to a server is done in classic AFP2.2 version is used
205 * but OSX uses AFP3.x FPzzz command !
207 uam_afpserver_action(AFP_ZZZ, UAM_AFPSERVER_POSTAUTH, afp_zzz, NULL);
215 static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expired)
219 #endif /* ADMIN_GRP */
221 /* UAM had syslog control; afpd needs to reassert itself */
222 set_processname("afpd");
223 syslog_setup(log_debug, logtype_default, logoption_ndelay|logoption_pid, logfacility_daemon);
225 if ( pwd->pw_uid == 0 ) { /* don't allow root login */
226 LOG(log_error, logtype_afpd, "login: root login denied!" );
227 return AFPERR_NOTAUTH;
230 LOG(log_info, logtype_afpd, "login %s (uid %d, gid %d) %s", pwd->pw_name,
231 pwd->pw_uid, pwd->pw_gid , afp_versions[afp_version_index].av_name);
234 if (obj->proto == AFPPROTO_ASP) {
235 ASP asp = obj->handle;
236 int addr_net = ntohs( asp->asp_sat.sat_addr.s_net );
237 int addr_node = asp->asp_sat.sat_addr.s_node;
239 if (obj->options.authprintdir) {
240 if(addr_net && addr_node) { /* Do we have a valid Appletalk address? */
243 int mypid = getpid();
244 struct stat stat_buf;
246 sprintf(nodename, "%s/net%d.%dnode%d", obj->options.authprintdir,
247 addr_net / 256, addr_net % 256, addr_node);
248 LOG(log_info, logtype_afpd, "registering %s (uid %d) on %u.%u as %s",
249 pwd->pw_name, pwd->pw_uid, addr_net, addr_node, nodename);
251 if (stat(nodename, &stat_buf) == 0) { /* file exists */
252 if (S_ISREG(stat_buf.st_mode)) { /* normal file */
254 fp = fopen(nodename, "w");
255 fprintf(fp, "%s:%d\n", pwd->pw_name, mypid);
257 chown( nodename, pwd->pw_uid, -1 );
258 } else { /* somebody is messing with us */
259 LOG(log_error, logtype_afpd, "print authfile %s is not a normal file, it will not be modified", nodename );
261 } else { /* file 'nodename' does not exist */
262 fp = fopen(nodename, "w");
263 fprintf(fp, "%s:%d\n", pwd->pw_name, mypid);
265 chown( nodename, pwd->pw_uid, -1 );
267 } /* if (addr_net && addr_node ) */
268 } /* if (options->authprintdir) */
269 } /* if (obj->proto == AFPPROTO_ASP) */
272 if (initgroups( pwd->pw_name, pwd->pw_gid ) < 0) {
274 LOG(log_info, logtype_afpd, "running with uid %d", geteuid());
275 #else /* RUN_AS_USER */
276 LOG(log_error, logtype_afpd, "login: %s", strerror(errno));
277 return AFPERR_BADUAM;
278 #endif /* RUN_AS_USER */
282 /* Basically if the user is in the admin group, we stay root */
284 if (( ngroups = getgroups( NGROUPS, groups )) < 0 ) {
285 LOG(log_error, logtype_afpd, "login: getgroups: %s", strerror(errno) );
286 return AFPERR_BADUAM;
291 LOG(log_info, logtype_afpd, "obj->options.admingid == %d", obj->options.admingid);
293 if (obj->options.admingid != 0) {
295 for (i = 0; i < ngroups; i++) {
296 if (groups[i] == obj->options.admingid) admin = 1;
301 LOG(log_info, logtype_afpd, "admin login -- %s", pwd->pw_name );
307 struct DSI *dsi = obj->handle;
314 afp_get_cmdline( &argc, &argv );
316 hp = gethostbyaddr( (char *) &dsi->client.sin_addr,
317 sizeof( struct in_addr ),
318 dsi->client.sin_family );
321 clientname = hp->h_name;
323 clientname = inet_ntoa( dsi->client.sin_addr );
325 sprintf( hostname, "%s@%s", pwd->pw_name, clientname );
327 if( sia_become_user( NULL, argc, argv, hostname, pwd->pw_name,
328 NULL, FALSE, NULL, NULL,
329 SIA_BEU_REALLOGIN ) != SIASUCCESS )
330 return AFPERR_BADUAM;
332 LOG(log_info, logtype_afpd, "session from %s (%s)", hostname,
333 inet_ntoa( dsi->client.sin_addr ) );
335 if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
336 LOG(log_error, logtype_afpd, "login: %s", strerror(errno) );
337 return AFPERR_BADUAM;
341 if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
342 LOG(log_error, logtype_afpd, "login: %s", strerror(errno) );
343 return AFPERR_BADUAM;
347 /* There's probably a better way to do this, but for now, we just
353 #endif /* ADMIN_GRP */
356 set_auth_switch(obj, expired);
358 obj->logout = logout;
362 save_uidgid ( &obj->uidgid );
368 /* ---------------------- */
369 int afp_zzz (obj, ibuf, ibuflen, rbuf, rbuflen ) /* Function 122 */
372 unsigned int ibuflen, *rbuflen;
378 retdata = obj->options.sleep /120;
382 *rbuflen = sizeof(retdata);
383 retdata = htonl(retdata);
384 memcpy(rbuf, &retdata, sizeof(retdata));
387 rbuf += sizeof(retdata);
391 /* ---------------------- */
392 int afp_getsession(obj, ibuf, ibuflen, rbuf, rbuflen )
395 unsigned int ibuflen, *rbuflen;
401 u_int16_t tklen, tp; /* FIXME: spec u_int32_t? */
410 memcpy(&type, ibuf, sizeof(type));
412 ibuf += sizeof(type);
413 ibuflen -= sizeof(type);
418 case 0: /* old version ?*/
420 case 1: /* disconnect */
421 case 2: /* reconnect update id */
422 if (ibuflen >= sizeof(idlen)) {
423 memcpy(&idlen, ibuf, sizeof(idlen));
424 idlen = ntohl(idlen);
425 ibuf += sizeof(idlen);
426 ibuflen -= sizeof(idlen);
427 if (ibuflen < idlen) {
430 /* memcpy (id, ibuf, idlen) */
437 memcpy( &idlen, ibuf, sizeof(idlen));
438 idlen = ntohl(idlen);
439 ibuf += sizeof(idlen);
440 ibuflen -= sizeof(idlen);
441 ibuf += sizeof(boottime);
442 ibuflen -= sizeof(boottime);
443 if (ibuflen < idlen || idlen > (90-10)) {
446 server_ipc_write(IPC_GETSESSION, idlen+8, p );
451 *rbuflen = sizeof(type);
453 memcpy(rbuf, &type, sizeof(type));
454 rbuf += sizeof(type);
456 *rbuflen += sizeof(tklen);
458 /* use 8 bytes for token as OSX, don't know if it helps */
459 if ( sizeof(pid_t) > 8) {
460 LOG(log_error, logtype_afpd, "sizeof(pid_t) > 8" );
466 memcpy(rbuf, &tp, sizeof(tklen));
467 rbuf += sizeof(tklen);
470 memset(rbuf, 0, tklen);
472 memcpy(rbuf, &token, sizeof(pid_t));
476 /* ---------------------- */
477 int afp_disconnect(obj, ibuf, ibuflen, rbuf, rbuflen )
480 int ibuflen, *rbuflen;
491 memcpy(&type, ibuf, sizeof(type));
493 ibuf += sizeof(type);
495 memcpy(&tklen, ibuf, sizeof(tklen));
496 tklen = ntohl(tklen);
497 ibuf += sizeof(tklen);
499 if ( sizeof(pid_t) > 8) {
500 LOG(log_error, logtype_afpd, "sizeof(pid_t) > 8" );
506 tklen = sizeof(pid_t);
507 memcpy(&token, ibuf, tklen);
509 /* our stuff is pid + zero pad */
511 for (i = tklen; i < 8; i++, ibuf++) {
517 /* killed old session, not easy */
518 server_ipc_write(IPC_KILLTOKEN, tklen, &token);
521 return AFPERR_SESSCLOS; /* was AFP_OK */
524 /* ---------------------- */
525 static int get_version(obj, ibuf, ibuflen, len)
533 if (!len || len > ibuflen)
534 return AFPERR_BADVERS;
536 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ]);
537 for ( i = 0; i < num; i++ ) {
538 if ( strncmp( ibuf, afp_versions[ i ].av_name , len ) == 0 ) {
539 afp_version = afp_versions[ i ].av_number;
540 afp_version_index = i;
544 if ( i == num ) /* An inappropo version */
545 return AFPERR_BADVERS ;
547 if (afp_version >= 30 && obj->proto != AFPPROTO_DSI)
548 return AFPERR_BADVERS ;
551 if (afp_version >= 30 && sizeof(off_t) != 8) {
552 LOG(log_error, logtype_afpd, "get_version: no LARGE_FILE support recompile!" );
553 return AFPERR_BADVERS ;
559 /* ---------------------- */
560 int afp_login(obj, ibuf, ibuflen, rbuf, rbuflen )
563 int ibuflen, *rbuflen;
565 struct passwd *pwd = NULL;
571 return send_reply(obj, AFPERR_SHUTDOWN );
574 return send_reply(obj, AFPERR_BADVERS );
577 len = (unsigned char) *ibuf++;
580 i = get_version(obj, ibuf, ibuflen, len);
582 return send_reply(obj, i );
588 return send_reply(obj, AFPERR_BADUAM);
590 len = (unsigned char) *ibuf++;
593 if (!len || len > ibuflen)
594 return send_reply(obj, AFPERR_BADUAM);
596 if (NULL == (afp_uam = auth_uamfind(UAM_SERVER_LOGIN, ibuf, len)) )
597 return send_reply(obj, AFPERR_BADUAM);
601 i = afp_uam->u.uam_login.login(obj, &pwd, ibuf, ibuflen, rbuf, rbuflen);
603 if (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
604 return send_reply(obj, i);
606 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((i==AFPERR_PWDEXPR)?1:0)));
609 /* ---------------------- */
610 int afp_login_ext(obj, ibuf, ibuflen, rbuf, rbuflen )
613 unsigned int ibuflen, *rbuflen;
615 struct passwd *pwd = NULL;
625 return send_reply(obj, AFPERR_SHUTDOWN );
628 return send_reply(obj, AFPERR_BADVERS );
634 len = (unsigned char) *ibuf;
638 i = get_version(obj, ibuf, ibuflen, len);
640 return send_reply(obj, i );
646 return send_reply(obj, AFPERR_BADUAM);
648 len = (unsigned char) *ibuf;
652 if (!len || len > ibuflen)
653 return send_reply(obj, AFPERR_BADUAM);
655 if ((afp_uam = auth_uamfind(UAM_SERVER_LOGIN, ibuf, len)) == NULL)
656 return send_reply(obj, AFPERR_BADUAM);
660 if (!afp_uam->u.uam_login.login_ext) {
661 LOG(log_error, logtype_afpd, "login_ext: uam %s not AFP 3 ready!", afp_uam->uam_name );
662 return send_reply(obj, AFPERR_BADUAM);
665 if (len <= 1 +sizeof(len16))
666 return send_reply(obj, AFPERR_PARAM);
672 return send_reply(obj, AFPERR_PARAM);
674 memcpy(&len16, ibuf, sizeof(len16));
675 ibuf += sizeof(len16);
676 ibuflen -= sizeof(len16);
679 return send_reply(obj, AFPERR_PARAM);
683 /* directory service name */
685 return send_reply(obj, AFPERR_PARAM);
694 return send_reply(obj, AFPERR_PARAM);
695 len = (unsigned char) *ibuf;
700 /* With "No User Authen" it is equal */
701 if (ibuflen < sizeof(len16))
702 return send_reply(obj, AFPERR_PARAM);
703 memcpy(&len16, ibuf, sizeof(len16));
704 ibuf += sizeof(len16);
705 ibuflen -= sizeof(len16);
709 return send_reply(obj, AFPERR_PARAM);
713 LOG(log_error, logtype_afpd, "login_ext: directory service path not null!" );
714 return send_reply(obj, AFPERR_PARAM);
721 if (ibuflen && ((unsigned long) ibuf & 1)) { /* pad character */
726 /* FIXME user name are in UTF8 */
727 i = afp_uam->u.uam_login.login_ext(obj, username, &pwd, ibuf, ibuflen, rbuf, rbuflen);
729 if (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
730 return send_reply(obj, i);
732 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((i==AFPERR_PWDEXPR)?1:0)));
735 /* ---------------------- */
736 int afp_logincont(obj, ibuf, ibuflen, rbuf, rbuflen)
739 int ibuflen, *rbuflen;
741 struct passwd *pwd = NULL;
744 if ( afp_uam == NULL || afp_uam->u.uam_login.logincont == NULL ) {
746 return send_reply(obj, AFPERR_NOTAUTH );
750 err = afp_uam->u.uam_login.logincont(obj, &pwd, ibuf, ibuflen,
752 if (!pwd || ( err != AFP_OK && err != AFPERR_PWDEXPR))
753 return send_reply(obj, err);
755 return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((err==AFPERR_PWDEXPR)?1:0)));
759 int afp_logout(obj, ibuf, ibuflen, rbuf, rbuflen)
762 int ibuflen, *rbuflen;
764 LOG(log_info, logtype_afpd, "logout %s", obj->username);
772 /* change password --
773 * NOTE: an FPLogin must already have completed successfully for this
774 * to work. this also does a little pre-processing before it hands
777 int afp_changepw(obj, ibuf, ibuflen, rbuf, rbuflen )
780 int ibuflen, *rbuflen;
782 char username[MACFILELEN + 1], *start = ibuf;
791 /* make sure we can deal w/ this uam */
792 len = (unsigned char) *ibuf++;
793 if ((uam = auth_uamfind(UAM_SERVER_CHANGEPW, ibuf, len)) == NULL)
794 return AFPERR_BADUAM;
797 if ((len + 1) & 1) /* pad byte */
800 if ( afp_version < 30) {
801 len = (unsigned char) *ibuf++;
802 if ( len > sizeof(username) - 1) {
805 memcpy(username, ibuf, len);
806 username[ len ] = '\0';
808 if ((len + 1) & 1) /* pad byte */
811 /* AFP > 3.0 doesn't pass the username, APF 3.1 specs page 124 */
812 if ( ibuf[0] != '\0' || ibuf[1] != '\0')
815 len = MIN(sizeof(username), strlen(obj->username));
816 memcpy(username, obj->username, len);
817 username[ len ] = '\0';
821 LOG(log_info, logtype_afpd, "changing password for <%s>", username);
823 if (( pwd = uam_getname( obj, username, sizeof(username))) == NULL )
826 /* send it off to the uam. we really don't use ibuflen right now. */
827 ibuflen -= (ibuf - start);
828 ret = uam->u.uam_changepw(obj, username, pwd, ibuf, ibuflen,
830 LOG(log_info, logtype_afpd, "password change %s.",
831 (ret == AFPERR_AUTHCONT) ? "continued" :
832 (ret ? "failed" : "succeeded"));
834 set_auth_switch(obj, 0);
841 int afp_getuserinfo(obj, ibuf, ibuflen, rbuf, rbuflen )
844 int ibuflen, *rbuflen;
853 ibuf += sizeof(id); /* userid is not used in AFP 2.0 */
854 memcpy(&bitmap, ibuf, sizeof(bitmap));
855 bitmap = ntohs(bitmap);
857 /* deal with error cases. we don't have to worry about
858 * AFPERR_ACCESS or AFPERR_NOITEM as geteuid and getegid always
862 if ((bitmap & USERIBIT_ALL) != bitmap)
863 return AFPERR_BITMAP;
865 /* copy the bitmap back to reply buffer */
866 memcpy(rbuf, ibuf, sizeof(bitmap));
867 rbuf += sizeof(bitmap);
868 *rbuflen = sizeof(bitmap);
870 /* copy the user/group info */
871 if (bitmap & USERIBIT_USER) {
872 id = htonl(geteuid());
873 memcpy(rbuf, &id, sizeof(id));
875 *rbuflen += sizeof(id);
878 if (bitmap & USERIBIT_GROUP) {
879 id = htonl(getegid());
880 memcpy(rbuf, &id, sizeof(id));
882 *rbuflen += sizeof(id);
888 #define UAM_LIST(type) (((type) == UAM_SERVER_LOGIN || (type) == UAM_SERVER_LOGIN_EXT) ? &uam_login : \
889 (((type) == UAM_SERVER_CHANGEPW) ? \
890 &uam_changepw : NULL))
892 /* just do a linked list search. this could be sped up with a hashed
893 * list, but i doubt anyone's going to have enough uams to matter. */
894 struct uam_obj *auth_uamfind(const int type, const char *name,
897 struct uam_obj *prev, *start;
899 if (!name || !(start = UAM_LIST(type)))
903 while ((prev = prev->uam_prev) != start)
904 if (strndiacasecmp(prev->uam_name, name, len) == 0)
910 int auth_register(const int type, struct uam_obj *uam)
912 struct uam_obj *start;
914 if (!uam || !uam->uam_name || (*uam->uam_name == '\0'))
917 if (!(start = UAM_LIST(type)))
918 return 1; /* we don't know what to do with it, caller must free it */
920 uam_attach(start, uam);
924 /* load all of the modules */
925 int auth_load(const char *path, const char *list)
927 char name[MAXPATHLEN + 1], buf[MAXPATHLEN + 1], *p;
932 if (!path || !*path || !list || (len = strlen(path)) > sizeof(name) - 2)
935 strlcpy(buf, list, sizeof(buf));
936 if ((p = strtok(buf, ",")) == NULL)
940 if (name[len - 1] != '/') {
946 strncpy(name + len, p, sizeof(name) - len);
947 LOG(log_debug, logtype_afpd, "uam: loading (%s)", name);
949 if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) {
951 if (stat(name, &st) == 0) {
952 if ((mod = uam_load(name, p))) {
953 uam_attach(&uam_modules, mod);
954 LOG(log_info, logtype_afpd, "uam: %s loaded", p);
956 LOG(log_info, logtype_afpd, "uam: %s load failure",p);
959 LOG(log_info, logtype_afpd, "uam: uam not found (status=%d)", stat(name, &st));
961 p = strtok(NULL, ",");
967 /* get rid of all of the uams */
970 struct uam_mod *mod, *prev, *start = &uam_modules;
972 prev = start->uam_prev;
973 while ((mod = prev) != start) {
974 prev = prev->uam_prev;