Remove the unix token info from "struct user_struct"
[kai/samba.git] / source3 / smbd / password.c
index 80eba562c54c77990bcdfbceb655d2ad6bc6520a..c5c0245444f265f6a1405dd7d558f01de2ebeb73 100644 (file)
@@ -201,6 +201,37 @@ int register_initial_vuid(void)
        return vuser->vuid;
 }
 
+static int register_homes_share(const char *username)
+{
+       int result;
+       struct passwd *pwd;
+
+       result = lp_servicenumber(username);
+       if (result != -1) {
+               DEBUG(3, ("Using static (or previously created) service for "
+                         "user '%s'; path = '%s'\n", username,
+                         lp_pathname(result)));
+               return result;
+       }
+
+       pwd = getpwnam_alloc(talloc_tos(), username);
+
+       if ((pwd == NULL) || (pwd->pw_dir[0] == '\0')) {
+               DEBUG(3, ("No home directory defined for user '%s'\n",
+                         username));
+               TALLOC_FREE(pwd);
+               return -1;
+       }
+
+       DEBUG(3, ("Adding homes service for user '%s' using home directory: "
+                 "'%s'\n", username, pwd->pw_dir));
+
+       result = add_home_service(username, username, pwd->pw_dir);
+
+       TALLOC_FREE(pwd);
+       return result;
+}
+
 /**
  *  register that a valid login has been performed, establish 'session'.
  *  @param server_info The token returned from the authentication process.
@@ -238,24 +269,6 @@ int register_existing_vuid(uint16 vuid,
 
        talloc_steal(vuser, vuser->server_info);
 
-       /* the next functions should be done by a SID mapping system (SMS) as
-        * the new real sam db won't have reference to unix uids or gids
-        */
-
-       vuser->uid = server_info->uid;
-       vuser->gid = server_info->gid;
-
-       vuser->n_groups = server_info->n_groups;
-       if (vuser->n_groups) {
-               if (!(vuser->groups = (gid_t *)talloc_memdup(vuser,
-                                       server_info->groups,
-                                       sizeof(gid_t)*vuser->n_groups))) {
-                       DEBUG(0,("register_existing_vuid: "
-                               "failed to talloc_memdup vuser->groups\n"));
-                       goto fail;
-               }
-       }
-
        vuser->guest = server_info->guest;
        fstrcpy(vuser->user.unix_name, server_info->unix_name);
 
@@ -267,45 +280,11 @@ int register_existing_vuid(uint16 vuid,
        fstrcpy(vuser->user.full_name,
        pdb_get_fullname(server_info->sam_account));
 
-       {
-               /* Keep the homedir handy */
-               const char *homedir =
-                       pdb_get_homedir(server_info->sam_account);
-               const char *logon_script =
-                       pdb_get_logon_script(server_info->sam_account);
-
-               if (!IS_SAM_DEFAULT(server_info->sam_account,
-                                       PDB_UNIXHOMEDIR)) {
-                       const char *unix_homedir =
-                               pdb_get_unix_homedir(server_info->sam_account);
-                       if (unix_homedir) {
-                               vuser->unix_homedir = unix_homedir;
-                       }
-               } else {
-                       struct passwd *passwd =
-                               getpwnam_alloc(vuser, vuser->user.unix_name);
-                       if (passwd) {
-                               vuser->unix_homedir = passwd->pw_dir;
-                               /* Ensure that the unix_homedir now
-                                * belongs to vuser, so it goes away
-                                * with it, not with passwd below: */
-                               talloc_steal(vuser, vuser->unix_homedir);
-                               TALLOC_FREE(passwd);
-                       }
-               }
-
-               if (homedir) {
-                       vuser->homedir = homedir;
-               }
-               if (logon_script) {
-                       vuser->logon_script = logon_script;
-               }
-       }
        vuser->session_key = session_key;
 
        DEBUG(10,("register_existing_vuid: (%u,%u) %s %s %s guest=%d\n",
-                       (unsigned int)vuser->uid,
-                       (unsigned int)vuser->gid,
+                       (unsigned int)vuser->server_info->uid,
+                       (unsigned int)vuser->server_info->gid,
                        vuser->user.unix_name, vuser->user.smb_name,
                        vuser->user.domain, vuser->guest ));
 
@@ -313,17 +292,15 @@ int register_existing_vuid(uint16 vuid,
                "Real name: %s\n", vuser->user.unix_name,
                vuser->user.full_name));
 
-       if (server_info->ptok) {
-               vuser->nt_user_token = dup_nt_token(vuser, server_info->ptok);
-       } else {
+       if (!server_info->ptok) {
                DEBUG(1, ("register_existing_vuid: server_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->uid,vuser->user.unix_name, vuser->vuid));
+               "and will be vuid %u\n", (int)vuser->server_info->uid,
+                vuser->user.unix_name, vuser->vuid));
 
        next_vuid++;
        num_validated_vuids++;
@@ -342,23 +319,10 @@ int register_existing_vuid(uint16 vuid,
        If a share exists by this name (autoloaded or not) reuse it . */
 
        vuser->homes_snum = -1;
-       if ( (!vuser->guest) && vuser->unix_homedir && *(vuser->unix_homedir)) {
-               int servicenumber = lp_servicenumber(vuser->user.unix_name);
-               if ( servicenumber == -1 ) {
-                       DEBUG(3, ("Adding homes service for user '%s' using "
-                               "home directory: '%s'\n",
-                               vuser->user.unix_name, vuser->unix_homedir));
-                       vuser->homes_snum =
-                               add_home_service(vuser->user.unix_name,
-                                               vuser->user.unix_name,
-                                               vuser->unix_homedir);
-               } else {
-                       DEBUG(3, ("Using static (or previously created) "
-                               "service for user '%s'; path = '%s'\n",
-                               vuser->user.unix_name,
-                               lp_pathname(servicenumber) ));
-                       vuser->homes_snum = servicenumber;
-               }
+
+       if (!vuser->guest) {
+               vuser->homes_snum = register_homes_share(
+                       vuser->user.unix_name);
        }
 
        if (srv_is_signing_negotiated() && !vuser->guest &&