r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
[vlendec/samba-autobuild/.git] / source3 / smbd / service.c
index cb9bfcc27aec90be12d8a1c79e9bf44446345f99..9dcb8a354f416625c2c290fe2dd43d822bc9b4c1 100644 (file)
@@ -371,35 +371,38 @@ static NTSTATUS find_forced_user(int snum, BOOL vuser_is_guest,
 {
        TALLOC_CTX *mem_ctx;
        char *fuser, *found_username;
+       struct nt_user_token *tmp_token;
        NTSTATUS result;
 
-       mem_ctx = talloc_new(NULL);
-       if (mem_ctx == NULL) {
+       if (!(mem_ctx = talloc_new(NULL))) {
                DEBUG(0, ("talloc_new failed\n"));
                return NT_STATUS_NO_MEMORY;
        }
 
-       fuser = talloc_string_sub(mem_ctx, lp_force_user(snum), "%S",
-                                 lp_servicename(snum));
-       if (fuser == NULL) {
-               result = NT_STATUS_NO_MEMORY;
-               goto done;
+       if (!(fuser = talloc_string_sub(mem_ctx, lp_force_user(snum), "%S",
+                                       lp_servicename(snum)))) {
+               TALLOC_FREE(mem_ctx);
+               return NT_STATUS_NO_MEMORY;
+               
        }
 
        result = create_token_from_username(mem_ctx, fuser, vuser_is_guest,
                                            uid, gid, &found_username,
-                                           token);
+                                           &tmp_token);
        if (!NT_STATUS_IS_OK(result)) {
-               goto done;
+               TALLOC_FREE(mem_ctx);
+               return result;
+       }
+
+       if (!(*token = dup_nt_token(NULL, tmp_token))) {
+               TALLOC_FREE(mem_ctx);
+               return NT_STATUS_NO_MEMORY;
        }
 
-       talloc_steal(NULL, *token);
        fstrcpy(username, found_username);
 
-       result = NT_STATUS_OK;
- done:
        TALLOC_FREE(mem_ctx);
-       return result;
+       return NT_STATUS_OK;
 }
 
 /*
@@ -620,7 +623,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                    sizeof(conn->client_address)-1);
        conn->num_files_open = 0;
        conn->lastused = conn->lastused_count = time(NULL);
-       conn->service = snum;
+       conn->params->service = snum;
        conn->used = True;
        conn->printer = (strncmp(dev,"LPT",3) == 0);
        conn->ipc = ( (strncmp(dev,"IPC",3) == 0) ||
@@ -646,7 +649,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        string_set(&conn->dirpath,"");
        string_set(&conn->user,user);
 
-       conn->read_only = lp_readonly(conn->service);
+       conn->read_only = lp_readonly(SNUM(conn));
        conn->admin_user = False;
 
        /*
@@ -746,7 +749,11 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        {
                pstring s;
                pstrcpy(s,lp_pathname(snum));
-               standard_sub_conn(conn,s,sizeof(s));
+               standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user,
+                                     conn->connectpath, conn->gid,
+                                     get_current_username(),
+                                     current_user_info.domain,
+                                     s, sizeof(s));
                set_conn_connectpath(conn,s);
                DEBUG(3,("Connect path is '%s' for service [%s]\n",s,
                         lp_servicename(snum)));
@@ -821,7 +828,11 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        if (*lp_rootpreexec(snum)) {
                pstring cmd;
                pstrcpy(cmd,lp_rootpreexec(snum));
-               standard_sub_conn(conn,cmd,sizeof(cmd));
+               standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user,
+                                     conn->connectpath, conn->gid,
+                                     get_current_username(),
+                                     current_user_info.domain,
+                                     cmd, sizeof(cmd));
                DEBUG(5,("cmd=%s\n",cmd));
                ret = smbrun(cmd,NULL);
                if (ret != 0 && lp_rootpreexec_close(snum)) {
@@ -854,7 +865,11 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        if (*lp_preexec(snum)) {
                pstring cmd;
                pstrcpy(cmd,lp_preexec(snum));
-               standard_sub_conn(conn,cmd,sizeof(cmd));
+               standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user,
+                                     conn->connectpath, conn->gid,
+                                     get_current_username(),
+                                     current_user_info.domain,
+                                     cmd, sizeof(cmd));
                ret = smbrun(cmd,NULL);
                if (ret != 0 && lp_preexec_close(snum)) {
                        DEBUG(1,("preexec gave %d - failing connection\n",
@@ -1148,7 +1163,11 @@ void close_cnum(connection_struct *conn, uint16 vuid)
            change_to_user(conn, vuid))  {
                pstring cmd;
                pstrcpy(cmd,lp_postexec(SNUM(conn)));
-               standard_sub_conn(conn,cmd,sizeof(cmd));
+               standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user,
+                                     conn->connectpath, conn->gid,
+                                     get_current_username(),
+                                     current_user_info.domain,
+                                     cmd, sizeof(cmd));
                smbrun(cmd,NULL);
                change_to_root_user();
        }
@@ -1158,7 +1177,11 @@ void close_cnum(connection_struct *conn, uint16 vuid)
        if (*lp_rootpostexec(SNUM(conn)))  {
                pstring cmd;
                pstrcpy(cmd,lp_rootpostexec(SNUM(conn)));
-               standard_sub_conn(conn,cmd,sizeof(cmd));
+               standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user,
+                                     conn->connectpath, conn->gid,
+                                     get_current_username(),
+                                     current_user_info.domain,
+                                     cmd, sizeof(cmd));
                smbrun(cmd,NULL);
        }