X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Fuam.c;h=d99d381edd38cc4408a5076039ef47f53d4e7899;hb=84c3a8f52deced7429f9d72276232ee282b3b823;hp=4b275f188268240a0cd54c471a1de5ff4f1b2fd5;hpb=3adfc34b14bf40a472c82eb328b9c3160df7e127;p=netatalk.git diff --git a/etc/afpd/uam.c b/etc/afpd/uam.c index 4b275f18..d99d381e 100644 --- a/etc/afpd/uam.c +++ b/etc/afpd/uam.c @@ -1,5 +1,5 @@ /* - * $Id: uam.c,v 1.28 2009-09-14 00:02:21 didg Exp $ + * $Id: uam.c,v 1.35 2009-11-08 01:15:31 didg Exp $ * * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT. @@ -11,28 +11,9 @@ #include #include - -/* STDC check */ -#if STDC_HEADERS #include -#else /* STDC_HEADERS */ -#ifndef HAVE_STRCHR -#define strchr index -#define strrchr index -#endif /* HAVE_STRCHR */ -char *strchr (), *strrchr (); -#ifndef HAVE_MEMCPY -#define memcpy(d,s,n) bcopy ((s), (d), (n)) -#define memmove(d,s,n) bcopy ((s), (d), (n)) -#endif /* ! HAVE_MEMCPY */ -#endif /* STDC_HEADERS */ - -#ifdef HAVE_UNISTD_H #include -#endif /* HAVE_UNISTD_H */ -#ifdef HAVE_FCNTL_H #include -#endif /* HAVE_FCNTL_H */ #include #include #include @@ -45,23 +26,16 @@ char *strchr (), *strrchr (); #include #include -#include -#include #include #include #include +#include +#include -#include "globals.h" #include "afp_config.h" #include "auth.h" #include "uam_auth.h" -#ifdef AFP3x -#define utf8_encoding() (afp_version >= 30) -#else -#define utf8_encoding() (0) -#endif - #ifdef TRU64 #include #include @@ -70,9 +44,6 @@ char *strchr (), *strrchr (); #endif /* TRU64 */ /* --- server uam functions -- */ -#ifndef NO_LOAD_UAM -extern int uam_setup(const char *path); -#endif /* uam_load. uams must have a uam_setup function. */ struct uam_mod *uam_load(const char *path, const char *name) @@ -81,12 +52,10 @@ struct uam_mod *uam_load(const char *path, const char *name) struct uam_mod *mod; void *module; -#ifndef NO_LOAD_UAM if ((module = mod_open(path)) == NULL) { LOG(log_error, logtype_afpd, "uam_load(%s): failed to load: %s", name, mod_error()); return NULL; } -#endif if ((mod = (struct uam_mod *) malloc(sizeof(struct uam_mod))) == NULL) { LOG(log_error, logtype_afpd, "uam_load(%s): malloc failed", name); @@ -97,7 +66,6 @@ struct uam_mod *uam_load(const char *path, const char *name) if ((p = strchr(buf, '.'))) *p = '\0'; -#ifndef NO_LOAD_UAM if ((mod->uam_fcn = mod_symbol(module, buf)) == NULL) { LOG(log_error, logtype_afpd, "uam_load(%s): mod_symbol error for symbol %s", name, @@ -118,9 +86,6 @@ struct uam_mod *uam_load(const char *path, const char *name) LOG(log_error, logtype_afpd, "uam_load(%s): uam_setup failed", name); goto uam_load_err; } -#else - uam_setup(name); -#endif mod->uam_module = module; return mod; @@ -140,9 +105,7 @@ void uam_unload(struct uam_mod *mod) if (mod->uam_fcn->uam_cleanup) (*mod->uam_fcn->uam_cleanup)(); -#ifndef NO_LOAD_UAM mod_close(mod->uam_module); -#endif free(mod); } @@ -269,8 +232,8 @@ struct passwd *uam_getname(void *private, char *name, const int len) } #ifndef NO_REAL_USER_NAME - if ( (size_t) -1 == (namelen = convert_string((utf8_encoding())?CH_UTF8_MAC:obj->options.maccharset, - CH_UCS2, name, strlen(name), username, sizeof(username)))) + if ( (size_t) -1 == (namelen = convert_string((utf8_encoding(obj))?CH_UTF8_MAC:obj->options.maccharset, + CH_UCS2, name, -1, username, sizeof(username)))) return NULL; setpwent(); @@ -278,11 +241,11 @@ struct passwd *uam_getname(void *private, char *name, const int len) if ((p = strchr(pwent->pw_gecos, ','))) *p = '\0'; - if ((size_t)-1 == ( gecoslen = convert_string(obj->options.unixcharset, CH_UCS2, - pwent->pw_gecos, strlen(pwent->pw_gecos), user, sizeof(username))) ) - continue; - if ((size_t)-1 == ( pwnamelen = convert_string(obj->options.unixcharset, CH_UCS2, - pwent->pw_name, strlen(pwent->pw_name), pwname, sizeof(username))) ) + gecoslen = convert_string(obj->options.unixcharset, CH_UCS2, + pwent->pw_gecos, -1, user, sizeof(username)); + pwnamelen = convert_string(obj->options.unixcharset, CH_UCS2, + pwent->pw_name, -1, pwname, sizeof(username)); + if ((size_t)-1 == gecoslen && (size_t)-1 == pwnamelen) continue; @@ -332,7 +295,7 @@ int uam_checkuser(const struct passwd *pwd) int uam_random_string (AFPObj *obj, char *buf, int len) { - u_int32_t result; + uint32_t result; int ret; int fd; @@ -347,7 +310,7 @@ int uam_random_string (AFPObj *obj, char *buf, int len) if (gettimeofday(&tv, &tz) < 0) return -1; - srandom(tv.tv_sec + (unsigned long) obj + (unsigned long) obj->handle); + srandom(tv.tv_sec + (unsigned long) obj + (unsigned long) obj->dsi); for (i = 0; i < len; i += sizeof(result)) { result = random(); memcpy(buf + i, &result, sizeof(result)); @@ -363,10 +326,10 @@ int uam_random_string (AFPObj *obj, char *buf, int len) /* afp-specific functions */ int uam_afpserver_option(void *private, const int what, void *option, - int *len) + size_t *len) { -AFPObj *obj = private; - char **buf = (char **) option; /* most of the options are this */ + AFPObj *obj = private; + const char **buf = (const char **) option; /* most of the options are this */ struct session_info **sinfo = (struct session_info **) option; if (!obj || !option) @@ -374,7 +337,7 @@ AFPObj *obj = private; switch (what) { case UAM_OPTION_USERNAME: - *buf = obj->username; + *buf = &(obj->username[0]); if (len) *len = sizeof(obj->username) - 1; break; @@ -400,11 +363,6 @@ AFPObj *obj = private; *len = sizeof(obj->options.passwdminlen); break; - case UAM_PASSWD_MAXFAIL: - *((int *) option) = obj->options.loginmaxfail; - *len = sizeof(obj->options.loginmaxfail); - break; - case UAM_PASSWD_EXPIRETIME: /* not implemented */ default: return -1; @@ -413,7 +371,7 @@ AFPObj *obj = private; break; case UAM_OPTION_SIGNATURE: - *buf = (void *) (((AFPConfig *)obj->config)->signature); + *buf = (void *)obj->dsi->signature; if (len) *len = 16; break; @@ -431,24 +389,20 @@ AFPObj *obj = private; *len = strlen(obj->options.hostname); break; - case UAM_OPTION_PROTOCOL: - *((int *) option) = obj->proto; - break; - case UAM_OPTION_CLIENTNAME: - { - struct DSI *dsi = obj->handle; - struct hostent *hp; - - hp = gethostbyaddr( (char *) &dsi->client.sin_addr, - sizeof( struct in_addr ), - dsi->client.sin_family ); - if( hp ) - *buf = hp->h_name; - else - *buf = inet_ntoa( dsi->client.sin_addr ); - } + { + struct DSI *dsi = obj->dsi; + const struct sockaddr *sa; + static char hbuf[NI_MAXHOST]; + + sa = (struct sockaddr *)&dsi->client; + if (getnameinfo(sa, sizeof(dsi->client), hbuf, sizeof(hbuf), NULL, 0, 0) == 0) + *buf = hbuf; + else + *buf = getip_string((struct sockaddr *)&dsi->client); + break; + } case UAM_OPTION_COOKIE: /* it's up to the uam to actually store something useful here. * this just passes back a handle to the cookie. the uam side @@ -493,7 +447,7 @@ AFPObj *obj = private; /* if we need to maintain a connection, this is how we do it. * because an action pointer gets passed in, we can stream * DSI connections */ -int uam_afp_read(void *handle, char *buf, int *buflen, +int uam_afp_read(void *handle, char *buf, size_t *buflen, int (*action)(void *, void *, const int)) { AFPObj *obj = handle; @@ -502,28 +456,18 @@ int uam_afp_read(void *handle, char *buf, int *buflen, if (!obj) return AFPERR_PARAM; - switch (obj->proto) { - case AFPPROTO_ASP: - if ((len = asp_wrtcont(obj->handle, buf, buflen )) < 0) - goto uam_afp_read_err; - return action(handle, buf, *buflen); - break; - - case AFPPROTO_DSI: - len = dsi_writeinit(obj->handle, buf, *buflen); + len = dsi_writeinit(obj->dsi, buf, *buflen); if (!len || ((len = action(handle, buf, len)) < 0)) { - dsi_writeflush(obj->handle); + dsi_writeflush(obj->dsi); goto uam_afp_read_err; } - while ((len = (dsi_write(obj->handle, buf, *buflen)))) { + while ((len = (dsi_write(obj->dsi, buf, *buflen)))) { if ((len = action(handle, buf, len)) < 0) { - dsi_writeflush(obj->handle); + dsi_writeflush(obj->dsi); goto uam_afp_read_err; } } - break; - } return 0; uam_afp_read_err: @@ -583,7 +527,9 @@ int uam_sia_validate_user(sia_collect_func_t * collect, int argc, char **argv, #endif /* TRU64 */ /* --- papd-specific functions (just placeholders) --- */ -void append(void *pf _U_, char *data _U_, int len _U_) +struct papfile; + +UAM_MODULE_EXPORT void append(struct papfile *pf _U_, const char *data _U_, int len _U_) { return; }