X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Fauth.c;h=d6382c84118bda9b89f4b801af9b520805494840;hb=df7560dfdb12b06090dc4b2c6e88d0858930b591;hp=6ff0988459dccd48763ebac847da2fc5a71a2cdf;hpb=be96d276348da0a7e66eeec844b306e8a5fa8fac;p=netatalk.git diff --git a/etc/afpd/auth.c b/etc/afpd/auth.c index 6ff09884..d6382c84 100644 --- a/etc/afpd/auth.c +++ b/etc/afpd/auth.c @@ -38,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" @@ -68,17 +68,6 @@ gid_t *groups; int ngroups; -/* - * These numbers are scattered throughout the code. - */ -static struct afp_versions afp_versions[] = { - { "AFP2.2", 22 }, - { "AFPX03", 30 }, - { "AFP3.1", 31 }, - { "AFP3.2", 32 }, - { "AFP3.3", 33 } -}; - static struct uam_mod uam_modules = {NULL, NULL, &uam_modules, &uam_modules}; static struct uam_obj uam_login = {"", "", 0, {{NULL, NULL, NULL, NULL }}, &uam_login, &uam_login}; @@ -91,7 +80,7 @@ static struct uam_obj *afp_uam = NULL; void status_versions( char *data, const DSI *dsi) { char *start = data; - u_int16_t status; + uint16_t status; int len, num, i, count = 0; memcpy(&status, start + AFPSTATUS_VERSOFF, sizeof(status)); @@ -118,7 +107,7 @@ void status_versions( char *data, const DSI *dsi) void status_uams(char *data, const char *authlist) { char *start = data; - u_int16_t status; + uint16_t status; struct uam_obj *uams; int len, num = 0; @@ -153,7 +142,7 @@ static int send_reply(const AFPObj *obj, const int err) if ((err == AFP_OK) || (err == AFPERR_AUTHCONT)) return err; - obj->reply(obj->handle, err); + obj->reply(obj->dsi, err); obj->exit(0); return AFP_OK; @@ -238,16 +227,29 @@ static int set_auth_switch(int expired) return AFP_OK; } +#define GROUPSTR_BUFSIZE 1024 +static const char *print_groups(int ngroups, gid_t *groups) +{ + static char groupsstr[GROUPSTR_BUFSIZE]; + int i; + char *s = groupsstr; + + if (ngroups == 0) + return "-"; + + for (i = 0; (i < ngroups) && (s < &groupsstr[GROUPSTR_BUFSIZE]); i++) { + s += snprintf(s, &groupsstr[GROUPSTR_BUFSIZE] - s, " %u", groups[i]); + } + + return groupsstr; +} + static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expired) { #ifdef ADMIN_GRP int admin = 0; #endif /* ADMIN_GRP */ -#if 0 - set_processname("afpd"); -#endif - if ( pwd->pw_uid == 0 ) { /* don't allow root login */ LOG(log_error, logtype_afpd, "login: root login denied!" ); return AFPERR_NOTAUTH; @@ -340,28 +342,7 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expi } #endif /* TRU64 */ - if (ngroups > 0) { - #define GROUPSTR_BUFSIZE 1024 - char groupsstr[GROUPSTR_BUFSIZE]; - char *s = groupsstr; - int j = GROUPSTR_BUFSIZE; - - int n = snprintf(groupsstr, GROUPSTR_BUFSIZE, "%u", groups[0]); - j -= n; - s += n; - - for (int i = 1; i < ngroups; i++) { - n = snprintf(s, j, ", %u", groups[i]); - if (n == j) { - /* Buffer full */ - LOG(log_debug, logtype_afpd, "login: group string buffer overflow"); - break; - } - j -= n; - s += n; - } - LOG(log_debug, logtype_afpd, "login: %u supplementary groups: %s", ngroups, groupsstr); - } + LOG(log_debug, logtype_afpd, "login: supplementary groups: %s", print_groups(ngroups, groups)); /* There's probably a better way to do this, but for now, we just play root */ #ifdef ADMIN_GRP @@ -380,25 +361,57 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expi } /* ---------------------- */ -int afp_zzz ( /* Function 122 */ - AFPObj *obj, - char *ibuf _U_, size_t ibuflen _U_, - char *rbuf, size_t *rbuflen) +int afp_zzz(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen) { - u_int32_t retdata; + uint32_t data; + DSI *dsi = (DSI *)AFPobj->dsi; *rbuflen = 0; + ibuf += 2; + ibuflen -= 2; - retdata = obj->options.sleep /120; - if (!retdata) { - retdata = 1; + if (ibuflen < 4) + return AFPERR_MISC; + memcpy(&data, ibuf, 4); /* flag */ + data = ntohl(data); + + /* + * Possible sleeping states: + * 1) normal sleep: DSI_SLEEPING (up to 10.3) + * 2) extended sleep: DSI_SLEEPING | DSI_EXTSLEEP (starting with 10.4) + */ + + if (data & AFPZZZ_EXT_WAKEUP) { + /* wakeup request from exetended sleep */ + if (dsi->flags & DSI_EXTSLEEP) { + 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_note, logtype_afpd, "afp_zzz: entering extended sleep"); + dsi->flags |= DSI_EXTSLEEP; + } else { + LOG(log_note, logtype_afpd, "afp_zzz: entering normal sleep"); + } } - *rbuflen = sizeof(retdata); - retdata = htonl(retdata); - memcpy(rbuf, &retdata, sizeof(retdata)); - if (obj->sleep) - obj->sleep(); - rbuf += sizeof(retdata); + + /* + * According to AFP 3.3 spec we should not return anything, + * but eg 10.5.8 server still returns the numbers of hours + * the server is keeping the sessino (ie max sleeptime). + */ + data = obj->options.sleep / 120; /* hours */ + if (!data) { + data = 1; + } + *rbuflen = sizeof(data); + data = htonl(data); + memcpy(rbuf, &data, sizeof(data)); + rbuf += sizeof(data); + return AFP_OK; } @@ -443,10 +456,10 @@ int afp_getsession( char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen) { - u_int16_t type; - u_int32_t idlen = 0; - u_int32_t boottime; - u_int32_t tklen, tp; + uint16_t type; + uint32_t idlen = 0; + uint32_t boottime; + uint32_t tklen, tp; char *token; char *p; @@ -506,7 +519,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; } @@ -538,9 +557,9 @@ int afp_getsession( /* ---------------------- */ int afp_disconnect(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen) { - DSI *dsi = (DSI *)obj->handle; - u_int16_t type; - u_int32_t tklen; + DSI *dsi = (DSI *)obj->dsi; + uint16_t type; + uint32_t tklen; pid_t token; int i; @@ -588,7 +607,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) { @@ -706,7 +725,7 @@ int afp_login_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *r size_t len; int i; char type; - u_int16_t len16; + uint16_t len16; char *username; *rbuflen = 0; @@ -847,11 +866,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->dsi); + 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; } @@ -934,9 +957,9 @@ int afp_changepw(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rb /* FPGetUserInfo */ int afp_getuserinfo(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) { - u_int8_t thisuser; - u_int32_t id; - u_int16_t bitmap; + uint8_t thisuser; + uint32_t id; + uint16_t bitmap; char *bitmapp; LOG(log_debug, logtype_afpd, "begin afp_getuserinfo:");