s3-auth Rename auth_serversupplied_info varaiables: server_info -> session_info
[ira/wip.git] / source3 / smbd / password.c
index 2e63f7a39589ba4df7807f9f699b128fdfb85c85..15277d04b4a95f2df206f56c62f37898917ef78a 100644 (file)
 
 #include "includes.h"
 #include "smbd/globals.h"
+#include "../librpc/gen_ndr/netlogon.h"
+
+/* Fix up prototypes for OSX 10.4, where they're missing */
+#ifndef HAVE_SETNETGRENT_PROTOTYPE
+extern int setnetgrent(const char* netgroup);
+#endif
+#ifndef HAVE_GETNETGRENT_PROTOTYPE
+extern int getnetgrent(char **host, char **user, char **domain);
+#endif
+#ifndef HAVE_ENDNETGRENT_PROTOTYPE
+extern void endnetgrent(void);
+#endif
 
 enum server_allocated_state { SERVER_ALLOCATED_REQUIRED_YES,
                                SERVER_ALLOCATED_REQUIRED_NO,
@@ -41,12 +53,12 @@ static user_struct *get_valid_user_struct_internal(
                if (vuid == usp->vuid) {
                        switch (server_allocated) {
                                case SERVER_ALLOCATED_REQUIRED_YES:
-                                       if (usp->server_info == NULL) {
+                                       if (usp->session_info == NULL) {
                                                continue;
                                        }
                                        break;
                                case SERVER_ALLOCATED_REQUIRED_NO:
-                                       if (usp->server_info != NULL) {
+                                       if (usp->session_info != NULL) {
                                                continue;
                                        }
                                case SERVER_ALLOCATED_REQUIRED_ANY:
@@ -109,7 +121,7 @@ void invalidate_vuid(struct smbd_server_connection *sconn, uint16 vuid)
        session_yield(vuser);
 
        if (vuser->auth_ntlmssp_state) {
-               auth_ntlmssp_end(&vuser->auth_ntlmssp_state);
+               TALLOC_FREE(vuser->auth_ntlmssp_state);
        }
 
        DLIST_REMOVE(sconn->smb1.sessions.validated_users, vuser);
@@ -128,7 +140,7 @@ void invalidate_vuid(struct smbd_server_connection *sconn, uint16 vuid)
 
 void invalidate_all_vuids(struct smbd_server_connection *sconn)
 {
-       if (sconn->allow_smb2) {
+       if (sconn->using_smb2) {
                return;
        }
 
@@ -197,7 +209,7 @@ int register_initial_vuid(struct smbd_server_connection *sconn)
        return vuser->vuid;
 }
 
-static int register_homes_share(const char *username)
+int register_homes_share(const char *username)
 {
        int result;
        struct passwd *pwd;
@@ -210,7 +222,7 @@ static int register_homes_share(const char *username)
                return result;
        }
 
-       pwd = getpwnam_alloc(talloc_tos(), username);
+       pwd = Get_Pwnam_alloc(talloc_tos(), username);
 
        if ((pwd == NULL) || (pwd->pw_dir[0] == '\0')) {
                DEBUG(3, ("No home directory defined for user '%s'\n",
@@ -230,7 +242,7 @@ static int register_homes_share(const char *username)
 
 /**
  *  register that a valid login has been performed, establish 'session'.
- *  @param server_info The token returned from the authentication process.
+ *  @param session_info The token returned from the authentication process.
  *   (now 'owned' by register_existing_vuid)
  *
  *  @param session_key The User session key for the login session (now also
@@ -248,7 +260,7 @@ static int register_homes_share(const char *username)
 
 int register_existing_vuid(struct smbd_server_connection *sconn,
                        uint16 vuid,
-                       struct auth_serversupplied_info *server_info,
+                       struct auth_serversupplied_info *session_info,
                        DATA_BLOB response_blob,
                        const char *smb_name)
 {
@@ -261,37 +273,37 @@ int register_existing_vuid(struct smbd_server_connection *sconn,
        }
 
        /* Use this to keep tabs on all our info from the authentication */
-       vuser->server_info = talloc_move(vuser, &server_info);
+       vuser->session_info = talloc_move(vuser, &session_info);
 
        /* This is a potentially untrusted username */
        alpha_strcpy(tmp, smb_name, ". _-$", sizeof(tmp));
 
-       vuser->server_info->sanitized_username = talloc_strdup(
-               vuser->server_info, tmp);
+       vuser->session_info->sanitized_username = talloc_strdup(
+               vuser->session_info, tmp);
 
        DEBUG(10,("register_existing_vuid: (%u,%u) %s %s %s guest=%d\n",
-                 (unsigned int)vuser->server_info->utok.uid,
-                 (unsigned int)vuser->server_info->utok.gid,
-                 vuser->server_info->unix_name,
-                 vuser->server_info->sanitized_username,
-                 pdb_get_domain(vuser->server_info->sam_account),
-                 vuser->server_info->guest ));
+                 (unsigned int)vuser->session_info->utok.uid,
+                 (unsigned int)vuser->session_info->utok.gid,
+                 vuser->session_info->unix_name,
+                 vuser->session_info->sanitized_username,
+                 vuser->session_info->info3->base.domain.string,
+                 vuser->session_info->guest ));
 
        DEBUG(3, ("register_existing_vuid: User name: %s\t"
-                 "Real name: %s\n", vuser->server_info->unix_name,
-                 pdb_get_fullname(vuser->server_info->sam_account)));
+                 "Real name: %s\n", vuser->session_info->unix_name,
+                 vuser->session_info->info3->base.full_name.string));
 
-       if (!vuser->server_info->ptok) {
-               DEBUG(1, ("register_existing_vuid: server_info does not "
+       if (!vuser->session_info->security_token) {
+               DEBUG(1, ("register_existing_vuid: session_info does not "
                        "contain a user_token - cannot continue\n"));
                goto fail;
        }
 
        DEBUG(3,("register_existing_vuid: UNIX uid %d is UNIX user %s, "
-               "and will be vuid %u\n", (int)vuser->server_info->utok.uid,
-                vuser->server_info->unix_name, vuser->vuid));
+               "and will be vuid %u\n", (int)vuser->session_info->utok.uid,
+                vuser->session_info->unix_name, vuser->vuid));
 
-       if (!session_claim(vuser)) {
+       if (!session_claim(sconn, vuser)) {
                DEBUG(1, ("register_existing_vuid: Failed to claim session "
                        "for vuid=%d\n",
                        vuser->vuid));
@@ -306,25 +318,25 @@ int register_existing_vuid(struct smbd_server_connection *sconn,
 
        vuser->homes_snum = -1;
 
-       if (!vuser->server_info->guest) {
+       if (!vuser->session_info->guest) {
                vuser->homes_snum = register_homes_share(
-                       vuser->server_info->unix_name);
+                       vuser->session_info->unix_name);
        }
 
-       if (srv_is_signing_negotiated(smbd_server_conn) &&
-           !vuser->server_info->guest) {
+       if (srv_is_signing_negotiated(sconn) &&
+           !vuser->session_info->guest) {
                /* Try and turn on server signing on the first non-guest
                 * sessionsetup. */
-               srv_set_signing(smbd_server_conn,
-                               vuser->server_info->user_session_key,
+               srv_set_signing(sconn,
+                               vuser->session_info->user_session_key,
                                response_blob);
        }
 
        /* fill in the current_user_info struct */
        set_current_user_info(
-               vuser->server_info->sanitized_username,
-               vuser->server_info->unix_name,
-               pdb_get_domain(vuser->server_info->sam_account));
+               vuser->session_info->sanitized_username,
+               vuser->session_info->unix_name,
+               vuser->session_info->info3->base.domain.string);
 
        return vuser->vuid;
 
@@ -403,153 +415,11 @@ const char *get_session_workgroup(struct smbd_server_connection *sconn)
        return sconn->smb1.sessions.session_workgroup;
 }
 
-/****************************************************************************
- Check if a user is in a netgroup user list. If at first we don't succeed,
- try lower case.
-****************************************************************************/
-
-bool user_in_netgroup(struct smbd_server_connection *sconn,
-                     const char *user, const char *ngname)
-{
-#ifdef HAVE_NETGROUP
-       fstring lowercase_user;
-
-       if (sconn->smb1.sessions.my_yp_domain == NULL) {
-               yp_get_default_domain(&sconn->smb1.sessions.my_yp_domain);
-       }
-
-       if (sconn->smb1.sessions.my_yp_domain == NULL) {
-               DEBUG(5,("Unable to get default yp domain, "
-                       "let's try without specifying it\n"));
-       }
-
-       DEBUG(5,("looking for user %s of domain %s in netgroup %s\n",
-               user,
-               sconn->smb1.sessions.my_yp_domain?
-               sconn->smb1.sessions.my_yp_domain:"(ANY)",
-               ngname));
-
-       if (innetgr(ngname, NULL, user, sconn->smb1.sessions.my_yp_domain)) {
-               DEBUG(5,("user_in_netgroup: Found\n"));
-               return true;
-       }
-
-       /*
-        * Ok, innetgr is case sensitive. Try once more with lowercase
-        * just in case. Attempt to fix #703. JRA.
-        */
-       fstrcpy(lowercase_user, user);
-       strlower_m(lowercase_user);
-
-       if (strcmp(user,lowercase_user) == 0) {
-               /* user name was already lower case! */
-               return false;
-       }
-
-       DEBUG(5,("looking for user %s of domain %s in netgroup %s\n",
-               lowercase_user,
-               sconn->smb1.sessions.my_yp_domain?
-               sconn->smb1.sessions.my_yp_domain:"(ANY)",
-               ngname));
-
-       if (innetgr(ngname, NULL, lowercase_user,
-                   sconn->smb1.sessions.my_yp_domain)) {
-               DEBUG(5,("user_in_netgroup: Found\n"));
-               return true;
-       }
-#endif /* HAVE_NETGROUP */
-       return false;
-}
-
-/****************************************************************************
- Check if a user is in a user list - can check combinations of UNIX
- and netgroup lists.
-****************************************************************************/
-
-bool user_in_list(struct smbd_server_connection *sconn,
-                 const char *user,const char **list)
-{
-       if (!list || !*list)
-               return False;
-
-       DEBUG(10,("user_in_list: checking user %s in list\n", user));
-
-       while (*list) {
-
-               DEBUG(10,("user_in_list: checking user |%s| against |%s|\n",
-                         user, *list));
-
-               /*
-                * Check raw username.
-                */
-               if (strequal(user, *list))
-                       return(True);
-
-               /*
-                * Now check to see if any combination
-                * of UNIX and netgroups has been specified.
-                */
-
-               if(**list == '@') {
-                       /*
-                        * Old behaviour. Check netgroup list
-                        * followed by UNIX list.
-                        */
-                       if(user_in_netgroup(sconn, user, *list +1))
-                               return True;
-                       if(user_in_group(user, *list +1))
-                               return True;
-               } else if (**list == '+') {
-
-                       if((*(*list +1)) == '&') {
-                               /*
-                                * Search UNIX list followed by netgroup.
-                                */
-                               if(user_in_group(user, *list +2))
-                                       return True;
-                               if(user_in_netgroup(sconn, user, *list +2))
-                                       return True;
-
-                       } else {
-
-                               /*
-                                * Just search UNIX list.
-                                */
-
-                               if(user_in_group(user, *list +1))
-                                       return True;
-                       }
-
-               } else if (**list == '&') {
-
-                       if(*(*list +1) == '+') {
-                               /*
-                                * Search netgroup list followed by UNIX list.
-                                */
-                               if(user_in_netgroup(sconn, user, *list +2))
-                                       return True;
-                               if(user_in_group(user, *list +2))
-                                       return True;
-                       } else {
-                               /*
-                                * Just search netgroup list.
-                                */
-                               if(user_in_netgroup(sconn, user, *list +1))
-                                       return True;
-                       }
-               }
-
-               list++;
-       }
-       return(False);
-}
-
 /****************************************************************************
  Check if a username is valid.
 ****************************************************************************/
 
-static bool user_ok(struct smbd_server_connection *sconn,
-                   const char *user, int snum)
+static bool user_ok(const char *user, int snum)
 {
        bool ret;
 
@@ -565,7 +435,7 @@ static bool user_ok(struct smbd_server_connection *sconn,
                         * around to pass to str_list_sub_basic() */
 
                        if ( invalid && str_list_sub_basic(invalid, "", "") ) {
-                               ret = !user_in_list(sconn, user,
+                               ret = !user_in_list(talloc_tos(), user,
                                                    (const char **)invalid);
                        }
                }
@@ -582,7 +452,7 @@ static bool user_ok(struct smbd_server_connection *sconn,
                         * around to pass to str_list_sub_basic() */
 
                        if ( valid && str_list_sub_basic(valid, "", "") ) {
-                               ret = user_in_list(sconn, user,
+                               ret = user_in_list(talloc_tos(), user,
                                                   (const char **)valid);
                        }
                }
@@ -595,7 +465,7 @@ static bool user_ok(struct smbd_server_connection *sconn,
                if (user_list &&
                    str_list_substitute(user_list, "%S",
                                        lp_servicename(snum))) {
-                       ret = user_in_list(sconn, user,
+                       ret = user_in_list(talloc_tos(), user,
                                           (const char **)user_list);
                }
                TALLOC_FREE(user_list);
@@ -619,7 +489,7 @@ static char *validate_group(struct smbd_server_connection *sconn,
                setnetgrent(group);
                while (getnetgrent(&host, &user, &domain)) {
                        if (user) {
-                               if (user_ok(sconn, user, snum) &&
+                               if (user_ok(user, snum) &&
                                    password_ok(actx, enc,
                                                get_session_workgroup(sconn),
                                                user,password)) {
@@ -685,7 +555,7 @@ static char *validate_group(struct smbd_server_connection *sconn,
 
                        member = member_list;
                        while (*member) {
-                               if (user_ok(sconn, member,snum) &&
+                               if (user_ok(member,snum) &&
                                    password_ok(actx, enc,
                                                get_session_workgroup(sconn),
                                                member,password)) {
@@ -764,7 +634,7 @@ bool authorise_login(struct smbd_server_connection *sconn,
                     auser = strtok_r(NULL, LIST_SEP, &saveptr)) {
                        fstring user2;
                        fstrcpy(user2,auser);
-                       if (!user_ok(sconn,user2,snum))
+                       if (!user_ok(user2,snum))
                                continue;
 
                        if (password_ok(actx, enc,
@@ -817,7 +687,7 @@ bool authorise_login(struct smbd_server_connection *sconn,
                        } else {
                                fstring user2;
                                fstrcpy(user2,auser);
-                               if (user_ok(sconn,user2,snum) &&
+                               if (user_ok(user2,snum) &&
                                    password_ok(actx, enc,
                                                get_session_workgroup(sconn),
                                                user2,password)) {
@@ -853,7 +723,7 @@ bool authorise_login(struct smbd_server_connection *sconn,
                *guest = True;
        }
 
-       if (ok && !user_ok(sconn, user, snum)) {
+       if (ok && !user_ok(user, snum)) {
                DEBUG(0,("authorise_login: rejected invalid user %s\n",user));
                ok = False;
        }