X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fuams%2Fuams_guest.c;h=00f90ece0972ee01670d5cc1eee55879d6795b35;hb=be96d276348da0a7e66eeec844b306e8a5fa8fac;hp=e580f858338b2faf55f4e8a6cdedc9a79e23f59f;hpb=5268a18e175c883c0f62bb3bd0bde8a3e17d254c;p=netatalk.git diff --git a/etc/uams/uams_guest.c b/etc/uams/uams_guest.c index e580f858..00f90ece 100644 --- a/etc/uams/uams_guest.c +++ b/etc/uams/uams_guest.c @@ -1,31 +1,43 @@ /* - * $Id: uams_guest.c,v 1.4 2001-02-27 17:07:43 rufustfirefly Exp $ + * $Id: uams_guest.c,v 1.18 2009-11-08 01:07:17 didg Exp $ * * (c) 2001 (see COPYING) */ #ifdef HAVE_CONFIG_H #include "config.h" -#endif +#endif /* HAVE_CONFIG_H */ #include #include +#include #include #include -#include +#include #include #include +#include +#include +#ifndef MIN +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif /* MIN */ + +/*XXX in etc/papd/file.h */ +struct papfile; +extern UAM_MODULE_EXPORT void append(struct papfile *, const char *, int); + +/* login and login_ext are almost the same */ static int noauth_login(void *obj, struct passwd **uam_pwd, - char *ibuf, int ibuflen, - char *rbuf, int *rbuflen) + char *ibuf _U_, size_t ibuflen _U_, + char *rbuf _U_, size_t *rbuflen) { struct passwd *pwent; char *guest, *username; *rbuflen = 0; - syslog( LOG_INFO, "login noauth" ); + LOG(log_info, logtype_uams, "login noauth" ); if (uam_afpserver_option(obj, UAM_OPTION_GUEST, (void *) &guest, NULL) < 0) @@ -37,13 +49,14 @@ static int noauth_login(void *obj, struct passwd **uam_pwd, strcpy(username, guest); if ((pwent = getpwnam(guest)) == NULL) { - syslog( LOG_ERR, "noauth_login: getpwnam( %s ): %m", guest); + LOG(log_error, logtype_uams, "noauth_login: getpwnam( %s ): %s", + guest, strerror(errno) ); return( AFPERR_BADUAM ); } #ifdef AFS if ( setpag() < 0 ) { - syslog( LOG_ERR, "noauth_login: setpag: %m" ); + LOG(log_error, logtype_uams, "noauth_login: setpag: %s", strerror(errno) ); return( AFPERR_BADUAM ); } #endif /* AFS */ @@ -52,17 +65,27 @@ static int noauth_login(void *obj, struct passwd **uam_pwd, return( AFP_OK ); } +static int noauth_login_ext(void *obj, char *uname _U_, struct passwd **uam_pwd, + char *ibuf, size_t ibuflen, + char *rbuf, size_t *rbuflen) +{ + return ( noauth_login (obj, uam_pwd, ibuf, ibuflen, rbuf, rbuflen)); +} + /* Printer NoAuthUAM Login */ -int noauth_printer(start, stop, username, out) - char *start, *stop, *username; - struct papfile *out; +static int noauth_printer(char *start, char *stop, char *username, struct papfile *out) { char *data, *p, *q; static const char *loginok = "0\r"; data = (char *)malloc(stop - start + 1); - strncpy(data, start, stop - start + 1); + if (!data) { + LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: malloc"); + return(-1); + } + + strlcpy(data, start, stop - start + 1); /* We are looking for the following format in data: * (username) @@ -71,38 +94,40 @@ int noauth_printer(start, stop, username, out) */ if ((p = strchr(data, '(' )) == NULL) { - syslog(LOG_INFO,"Bad Login NoAuthUAM: username not found in string"); + LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string"); free(data); return(-1); } p++; - if ((q = strchr(data, ')' )) == NULL) { - syslog(LOG_INFO,"Bad Login NoAuthUAM: username not found in string"); + if ((q = strchr(p, ')' )) == NULL) { + LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string"); free(data); return(-1); } - strncpy(username, p, q - p); + memcpy(username, p, MIN( UAM_USERNAMELEN, q - p )); /* Done copying username, clean up */ free(data); if (getpwnam(username) == NULL) { - syslog(LOG_INFO, "Bad Login NoAuthUAM: %s: %m", username); + LOG(log_info, logtype_uams, "Bad Login NoAuthUAM: %s: %s", + username, strerror(errno) ); return(-1); } /* Login successful */ append(out, loginok, strlen(loginok)); - syslog(LOG_INFO, "Login NoAuthUAM: %s", username); + LOG(log_info, logtype_uams, "Login NoAuthUAM: %s", username); return(0); } static int uam_setup(const char *path) { - if (uam_register(UAM_SERVER_LOGIN, path, "No User Authent", - noauth_login, NULL, NULL) < 0) - return -1; + if (uam_register(UAM_SERVER_LOGIN_EXT, path, "No User Authent", + noauth_login, NULL, NULL, noauth_login_ext) < 0) + return -1; + if (uam_register(UAM_SERVER_PRINTAUTH, path, "NoAuthUAM", noauth_printer) < 0) return -1; @@ -110,7 +135,7 @@ static int uam_setup(const char *path) return 0; } -static void uam_cleanup() +static void uam_cleanup(void) { uam_unregister(UAM_SERVER_LOGIN, "No User Authent"); uam_unregister(UAM_SERVER_PRINTAUTH, "NoAuthUAM");