]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/uam.c
Merge remote-tracking branch 'origin/branch-netatalk-3-1'
[netatalk.git] / etc / afpd / uam.c
index 92173915c5f5cc5e7dfa8934c00f1a1ba34a1d85..04e54cbbd2f60c1999337a917412bb4cb87b91d1 100644 (file)
@@ -1,5 +1,4 @@
 /*
- * $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.
 
 #include <stdio.h>
 #include <stdlib.h>
-
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#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 <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <ctype.h>
 #include <atalk/logger.h>
 #include <sys/param.h>
@@ -45,19 +25,17 @@ char *strchr (), *strrchr ();
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
-#include <netatalk/endian.h>
-#include <atalk/asp.h>
 #include <atalk/dsi.h>
 #include <atalk/afp.h>
 #include <atalk/util.h>
+#include <atalk/globals.h>
+#include <atalk/volume.h>
+#include <atalk/bstrlib.h>
 
-#include "globals.h"
 #include "afp_config.h"
 #include "auth.h"
 #include "uam_auth.h"
 
-#define utf8_encoding() (afp_version >= 30)
-
 #ifdef TRU64
 #include <netdb.h>
 #include <sia.h>
@@ -68,7 +46,7 @@ char *strchr (), *strrchr ();
 /* --- server uam functions -- */
 
 /* uam_load. uams must have a uam_setup function. */
-struct uam_mod *uam_load(const char *path, const char *name)
+struct uam_mod *uam_load(AFPObj *obj, const char *path, const char *name)
 {
     char buf[MAXPATHLEN + 1], *p;
     struct uam_mod *mod;
@@ -104,7 +82,7 @@ struct uam_mod *uam_load(const char *path, const char *name)
     /* version check would go here */
 
     if (!mod->uam_fcn->uam_setup ||
-            ((*mod->uam_fcn->uam_setup)(name) < 0)) {
+        ((*mod->uam_fcn->uam_setup)(obj, name) < 0)) {
         LOG(log_error, logtype_afpd, "uam_load(%s): uam_setup failed", name);
         goto uam_load_err;
     }
@@ -231,30 +209,29 @@ struct passwd *uam_getname(void *private, char *name, const int len)
         return pwent;
         
     /* if we have a NT domain name try with it */
-    if (obj->options.ntdomain && obj->options.ntseparator) {
+    if (obj->options.addomain || (obj->options.ntdomain && obj->options.ntseparator)) {
         /* FIXME What about charset ? */
-        size_t ulen = strlen(obj->options.ntdomain) + strlen(obj->options.ntseparator) + strlen(name);
-        if ((p = malloc(ulen +1))) {
-            strcpy(p, obj->options.ntdomain);
-            strcat(p, obj->options.ntseparator);
-            strcat(p, name);
-            pwent = getpwnam(p);
-            free(p);
-            if (pwent) {
-                int len = strlen(pwent->pw_name);              
-                if (len < MAXUSERLEN) {
-                    strncpy(name,pwent->pw_name, MAXUSERLEN);  
-                }else{
-                    LOG(log_error, logtype_uams, "MAJOR:The name %s is longer than %d",pwent->pw_name,MAXUSERLEN);
-                }
-
-                return pwent;
+        bstring princ;
+        if (obj->options.addomain)
+            princ = bformat("%s@%s", name, obj->options.addomain);
+        else
+            princ = bformat("%s%s%s", obj->options.ntdomain, obj->options.ntseparator, name);
+        pwent = getpwnam(bdata(princ));
+        bdestroy(princ);
+
+        if (pwent) {
+            int len = strlen(pwent->pw_name);              
+            if (len < MAXUSERLEN) {
+                strncpy(name,pwent->pw_name, MAXUSERLEN);  
+            } else {
+                LOG(log_error, logtype_uams, "The name '%s' is longer than %d", pwent->pw_name, MAXUSERLEN);
             }
+            return pwent;
         }
     }
 #ifndef NO_REAL_USER_NAME
 
-    if ( (size_t) -1 == (namelen = convert_string((utf8_encoding())?CH_UTF8_MAC:obj->options.maccharset,
+    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;
 
@@ -263,11 +240,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, -1, user, sizeof(username))) )
-               continue;
-       if ((size_t)-1 == ( pwnamelen = convert_string(obj->options.unixcharset, CH_UCS2, 
-                               pwent->pw_name, -1, 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;
 
 
@@ -317,7 +294,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;
 
@@ -332,7 +309,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));
@@ -359,7 +336,7 @@ int uam_afpserver_option(void *private, const int what, void *option,
 
     switch (what) {
     case UAM_OPTION_USERNAME:
-        *buf = obj->username;
+        *buf = &(obj->username[0]);
         if (len)
             *len = sizeof(obj->username) - 1;
         break;
@@ -385,11 +362,6 @@ int uam_afpserver_option(void *private, const int what, void *option,
             *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;
@@ -398,7 +370,7 @@ int uam_afpserver_option(void *private, const int what, void *option,
         break;
 
     case UAM_OPTION_SIGNATURE:
-        *buf = (void *) (((AFPConfig *)obj->config)->signature);
+        *buf = (void *)obj->dsi->signature;
         if (len)
             *len = 16;
         break;
@@ -416,13 +388,9 @@ int uam_afpserver_option(void *private, const int what, void *option,
             *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 DSI *dsi = obj->dsi;
         const struct sockaddr *sa;
         static char hbuf[NI_MAXHOST];
         
@@ -487,28 +455,18 @@ int uam_afp_read(void *handle, char *buf, size_t *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: