X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Fauth.c;h=fef13eb8fc46ac79dad45003e09013b84fa78e74;hb=b0bcb8f6b0571592a50ce039882c9319e012a270;hp=cd2f73f3cfb7a384df8e7dc9f0ca8154eabba3af;hpb=327257d3290c7a2723791c9b755a5b05a6b7ce74;p=netatalk.git diff --git a/etc/afpd/auth.c b/etc/afpd/auth.c index cd2f73f3..fef13eb8 100644 --- a/etc/afpd/auth.c +++ b/etc/afpd/auth.c @@ -10,13 +10,12 @@ #include #include #include -#ifdef HAVE_UNISTD_H #include -#endif /* HAVE_UNISTD_H */ #include #include #include -#include +#include + #include #include #include @@ -39,8 +38,8 @@ extern void afp_get_cmdline( int *ac, char ***av ); #include #include #include +#include -#include "globals.h" #include "auth.h" #include "uam_auth.h" #include "switch.h" @@ -73,11 +72,6 @@ int ngroups; * These numbers are scattered throughout the code. */ static struct afp_versions afp_versions[] = { -#ifndef NO_DDP - { "AFPVersion 1.1", 11 }, - { "AFPVersion 2.0", 20 }, - { "AFPVersion 2.1", 21 }, -#endif /* ! NO_DDP */ { "AFP2.2", 22 }, { "AFPX03", 30 }, { "AFP3.1", 31 }, @@ -94,7 +88,7 @@ static struct uam_obj uam_changepw = {"", "", 0, {{NULL, NULL, NULL, NULL}}, &ua static struct uam_obj *afp_uam = NULL; -void status_versions( char *data, const ASP asp, const DSI *dsi) +void status_versions( char *data, const DSI *dsi) { char *start = data; u_int16_t status; @@ -104,9 +98,6 @@ void status_versions( char *data, const ASP asp, const DSI *dsi) num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] ); for ( i = 0; i < num; i++ ) { -#ifndef NO_DDP - if ( !asp && (afp_versions[ i ].av_number <= 21)) continue; -#endif /* ! NO_DDP */ if ( !dsi && (afp_versions[ i ].av_number >= 22)) continue; count++; } @@ -114,9 +105,6 @@ void status_versions( char *data, const ASP asp, const DSI *dsi) *data++ = count; for ( i = 0; i < num; i++ ) { -#ifndef NO_DDP - if ( !asp && (afp_versions[ i ].av_number <= 21)) continue; -#endif /* ! NO_DDP */ if ( !dsi && (afp_versions[ i ].av_number >= 22)) continue; len = strlen( afp_versions[ i ].av_name ); *data++ = len; @@ -268,45 +256,6 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expi LOG(log_note, logtype_afpd, "%s Login by %s", afp_versions[afp_version_index].av_name, pwd->pw_name); -#ifndef NO_DDP - if (obj->proto == AFPPROTO_ASP) { - ASP asp = obj->handle; - int addr_net = ntohs( asp->asp_sat.sat_addr.s_net ); - int addr_node = asp->asp_sat.sat_addr.s_node; - - if (obj->options.authprintdir) { - if(addr_net && addr_node) { /* Do we have a valid Appletalk address? */ - char nodename[256]; - FILE *fp; - int mypid = getpid(); - struct stat stat_buf; - - sprintf(nodename, "%s/net%d.%dnode%d", obj->options.authprintdir, - addr_net / 256, addr_net % 256, addr_node); - LOG(log_info, logtype_afpd, "registering %s (uid %d) on %u.%u as %s", - pwd->pw_name, pwd->pw_uid, addr_net, addr_node, nodename); - - if (stat(nodename, &stat_buf) == 0) { /* file exists */ - if (S_ISREG(stat_buf.st_mode)) { /* normal file */ - unlink(nodename); - fp = fopen(nodename, "w"); - fprintf(fp, "%s:%d\n", pwd->pw_name, mypid); - fclose(fp); - chown( nodename, pwd->pw_uid, -1 ); - } else { /* somebody is messing with us */ - LOG(log_error, logtype_afpd, "print authfile %s is not a normal file, it will not be modified", nodename ); - } - } else { /* file 'nodename' does not exist */ - fp = fopen(nodename, "w"); - fprintf(fp, "%s:%d\n", pwd->pw_name, mypid); - fclose(fp); - chown( nodename, pwd->pw_uid, -1 ); - } - } /* if (addr_net && addr_node ) */ - } /* if (options->authprintdir) */ - } /* if (obj->proto == AFPPROTO_ASP) */ -#endif - if (initgroups( pwd->pw_name, pwd->pw_gid ) < 0) { #ifdef RUN_AS_USER LOG(log_info, logtype_afpd, "running with uid %d", geteuid()); @@ -427,21 +376,18 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expi obj->uid = geteuid(); obj->logout = logout; -#ifdef FORCE_UIDGID - obj->force_uid = 1; - save_uidgid ( &obj->uidgid ); -#endif - return( AFP_OK ); } /* ---------------------- */ -int afp_zzz(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) +int afp_zzz(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen) { uint32_t data; DSI *dsi = (DSI *)AFPobj->handle; *rbuflen = 0; + ibuf += 2; + ibuflen -= 2; if (ibuflen < 4) return AFPERR_MISC; @@ -457,19 +403,20 @@ int afp_zzz(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbu if (data & AFPZZZ_EXT_WAKEUP) { /* wakeup request from exetended sleep */ if (dsi->flags & DSI_EXTSLEEP) { - LOG(log_debug, logtype_afpd, "afp_zzz: waking up from extended sleep"); + LOG(log_note, logtype_afpd, "afp_zzz: waking up from extended sleep"); dsi->flags &= ~(DSI_SLEEPING | DSI_EXTSLEEP); } } else { /* sleep request */ dsi->flags |= DSI_SLEEPING; if (data & AFPZZZ_EXT_SLEEP) { - LOG(log_debug, logtype_afpd, "afp_zzz: entering extended sleep"); + LOG(log_note, logtype_afpd, "afp_zzz: entering extended sleep"); dsi->flags |= DSI_EXTSLEEP; } else { - LOG(log_debug, logtype_afpd, "afp_zzz: entering normal sleep"); + LOG(log_note, logtype_afpd, "afp_zzz: entering normal sleep"); } } + /* * According to AFP 3.3 spec we should not return anything, * but eg 10.5.8 server still returns the numbers of hours @@ -591,7 +538,13 @@ int afp_getsession( if (ibuflen < idlen || idlen > (90-10)) { return AFPERR_PARAM; } - ipc_child_write(obj->ipc_fd, IPC_GETSESSION, idlen+8, p); + if (!obj->sinfo.clientid) { + obj->sinfo.clientid = malloc(idlen + 8); + memcpy(obj->sinfo.clientid, p, idlen + 8); + obj->sinfo.clientid_len = idlen + 8; + } + if (ipc_child_write(obj->ipc_fd, IPC_GETSESSION, idlen+8, p) != 0) + return AFPERR_MISC; tklen = obj->sinfo.sessiontoken_len; token = obj->sinfo.sessiontoken; } @@ -673,7 +626,7 @@ int afp_disconnect(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, setitimer(ITIMER_REAL, &none, NULL); /* check for old session, possibly transfering session from here to there */ - if (ipc_child_write(obj->ipc_fd, IPC_DISCOLDSESSION, tklen, &token) == -1) + if (ipc_child_write(obj->ipc_fd, IPC_DISCOLDSESSION, tklen, &token) != 0) goto exit; /* write uint16_t DSI request ID */ if (writet(obj->ipc_fd, &dsi->header.dsi_requestID, 2, 0, 2) != 2) { @@ -932,11 +885,15 @@ int afp_logincont(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *r } -int afp_logout(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen _U_) +int afp_logout(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen) { + DSI *dsi = (DSI *)(obj->handle); + LOG(log_note, logtype_afpd, "AFP logout by %s", obj->username); + of_close_all_forks(); close_all_vol(); - obj->exit(0); + dsi->flags = DSI_AFP_LOGGED_OUT; + *rbuflen = 0; return AFP_OK; }