Update smbrun to allow for settings environment variables.
authorTrever L. Adams <trever.adams@gmail.com>
Wed, 12 Oct 2016 15:55:15 +0000 (09:55 -0600)
committerJeremy Allison <jra@samba.org>
Thu, 13 Oct 2016 02:26:26 +0000 (04:26 +0200)
Signed-off-by: Trever L. Adams <trever.adams@gmail.com>
Reviewed-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Oct 13 04:26:26 CEST 2016 on sn-devel-144

22 files changed:
source3/auth/auth_util.c
source3/auth/user_util.c
source3/groupdb/mapping.c
source3/include/proto.h
source3/lib/smbrun.c
source3/libnet/libnet_dssync_passdb.c
source3/libnet/libnet_samsync_passdb.c
source3/modules/vfs_shell_snap.c
source3/modules/vfs_tsmsm.c
source3/nmbd/nmbd_winsserver.c
source3/passdb/pdb_interface.c
source3/passdb/pdb_ldap.c
source3/passdb/pdb_smbpasswd.c
source3/passdb/pdb_tdb.c
source3/printing/print_generic.c
source3/rpc_server/spoolss/srv_spoolss_nt.c
source3/rpc_server/srvsvc/srv_srvsvc_nt.c
source3/rpc_server/winreg/srv_winreg_nt.c
source3/services/svc_rcinit.c
source3/smbd/close.c
source3/smbd/message.c
source3/smbd/service.c

index 663c0bc7431e2c03db23653734aa8f9eaa22fa62..5473fa23a6c734883a8eb7e2db2ee7a2ff5a8106 100644 (file)
@@ -78,7 +78,7 @@ static int _smb_create_user(const char *domain, const char *unix_username, const
                        return -1;
                }
        }
-       ret = smbrun(add_script,NULL);
+       ret = smbrun(add_script, NULL, NULL);
        flush_pwnam_cache();
        DEBUG(ret ? 0 : 3,
                ("smb_create_user: Running the command `%s' gave %d\n",
@@ -434,7 +434,7 @@ static NTSTATUS log_nt_token(struct security_token *token)
        }
 
        DEBUG(8, ("running command: [%s]\n", command));
-       if (smbrun(command, NULL) != 0) {
+       if (smbrun(command, NULL, NULL) != 0) {
                DEBUG(0, ("Could not log NT token\n"));
                TALLOC_FREE(frame);
                return NT_STATUS_ACCESS_DENIED;
index ded2184051da0b21e82ce41de74fbbc0bc6879e4..d5c61b22794645eac68b088366fbdf2d4346f9b8 100644 (file)
@@ -315,7 +315,7 @@ bool map_username(TALLOC_CTX *ctx, const char *user_in, char **p_user_out)
                }
 
                DEBUG(10,("Running [%s]\n", command));
-               ret = smbrun(command, &fd);
+               ret = smbrun(command, &fd, NULL);
                DEBUGADD(10,("returned [%d]\n", ret));
 
                TALLOC_FREE(command);
index 4db53ab5eb0596c73dc5751371c8f0a8646e30a0..ac70fe68c482c34966a6c66c581910e4d9e99154 100644 (file)
@@ -227,7 +227,7 @@ int smb_create_group(const char *unix_group, gid_t *new_gid)
                        return -1;
                }
 
-               ret = smbrun(add_script, &fd);
+               ret = smbrun(add_script, &fd, NULL);
                DEBUG(ret ? 0 : 3,("smb_create_group: Running the command `%s' gave %d\n",add_script,ret));
                if (ret == 0) {
                        smb_nscd_flush_group_cache();
@@ -282,7 +282,7 @@ int smb_delete_group(const char *unix_group)
                if (!del_script) {
                        return -1;
                }
-               ret = smbrun(del_script,NULL);
+               ret = smbrun(del_script, NULL, NULL);
                DEBUG(ret ? 0 : 3,("smb_delete_group: Running the command `%s' gave %d\n",del_script,ret));
                if (ret == 0) {
                        smb_nscd_flush_group_cache();
@@ -322,7 +322,7 @@ int smb_set_primary_group(const char *unix_group, const char* unix_user)
                if (!add_script) {
                        return -1;
                }
-               ret = smbrun(add_script,NULL);
+               ret = smbrun(add_script, NULL, NULL);
                flush_pwnam_cache();
                DEBUG(ret ? 0 : 3,("smb_set_primary_group: "
                         "Running the command `%s' gave %d\n",add_script,ret));
@@ -364,7 +364,7 @@ int smb_add_user_group(const char *unix_group, const char *unix_user)
                if (!add_script) {
                        return -1;
                }
-               ret = smbrun(add_script,NULL);
+               ret = smbrun(add_script, NULL, NULL);
                DEBUG(ret ? 0 : 3,("smb_add_user_group: Running the command `%s' gave %d\n",add_script,ret));
                if (ret == 0) {
                        smb_nscd_flush_group_cache();
@@ -404,7 +404,7 @@ int smb_delete_user_group(const char *unix_group, const char *unix_user)
                if (!del_script) {
                        return -1;
                }
-               ret = smbrun(del_script,NULL);
+               ret = smbrun(del_script, NULL, NULL);
                DEBUG(ret ? 0 : 3,("smb_delete_user_group: Running the command `%s' gave %d\n",del_script,ret));
                if (ret == 0) {
                        smb_nscd_flush_group_cache();
index fe4217d93ef4e3e867578ae753b86e1a1cccd2d4..0b0a2b593258448721c9146a0d740272a85bfdef 100644 (file)
@@ -162,8 +162,8 @@ bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, struct security_d
 
 /* The following definitions come from lib/smbrun.c  */
 
-int smbrun_no_sanitize(const char *cmd, int *outfd);
-int smbrun(const char *cmd, int *outfd);
+int smbrun_no_sanitize(const char *cmd, int *outfd, char * const *env);
+int smbrun(const char *cmd, int *outfd, char * const *env);
 int smbrunsecret(const char *cmd, const char *secret);
 
 /* The following definitions come from lib/sock_exec.c  */
index 63b0323c51c46c2b95980d53fb1f377dff4eb0a3..3b7ed542ab2bca19f6318861b07e6dac78e96b99 100644 (file)
@@ -68,7 +68,8 @@ run a command being careful about uid/gid handling and putting the output in
 outfd (or discard it if outfd is NULL).
 ****************************************************************************/
 
-static int smbrun_internal(const char *cmd, int *outfd, bool sanitize)
+static int smbrun_internal(const char *cmd, int *outfd, bool sanitize,
+       char * const *env)
 {
        pid_t pid;
        uid_t uid = current_user.ut.uid;
@@ -197,8 +198,14 @@ static int smbrun_internal(const char *cmd, int *outfd, bool sanitize)
                                exit(82);
                }
 
-               execl("/bin/sh","sh","-c",
-                   newcmd ? (const char *)newcmd : cmd, NULL);
+               if (env != NULL) {
+                       execle("/bin/sh","sh","-c",
+                               newcmd ? (const char *)newcmd : cmd, NULL,
+                               env);
+               } else {
+                       execl("/bin/sh","sh","-c",
+                               newcmd ? (const char *)newcmd : cmd, NULL);
+               }
 
                SAFE_FREE(newcmd);
        }
@@ -212,18 +219,18 @@ static int smbrun_internal(const char *cmd, int *outfd, bool sanitize)
  Use only in known safe shell calls (printing).
 ****************************************************************************/
 
-int smbrun_no_sanitize(const char *cmd, int *outfd)
+int smbrun_no_sanitize(const char *cmd, int *outfd, char * const *env)
 {
-       return smbrun_internal(cmd, outfd, False);
+       return smbrun_internal(cmd, outfd, false, env);
 }
 
 /****************************************************************************
  By default this now sanitizes shell expansion.
 ****************************************************************************/
 
-int smbrun(const char *cmd, int *outfd)
+int smbrun(const char *cmd, int *outfd, char * const *env)
 {
-       return smbrun_internal(cmd, outfd, True);
+       return smbrun_internal(cmd, outfd, true, env);
 }
 
 /****************************************************************************
index 31c0616aae7379a015845e92059965b237414298..99e65c263adf6bc51a27a0719714c725faed9dc6 100644 (file)
@@ -693,7 +693,7 @@ static NTSTATUS smb_create_user(TALLOC_CTX *mem_ctx,
                if (!add_script) {
                        return NT_STATUS_NO_MEMORY;
                }
-               add_ret = smbrun(add_script, NULL);
+               add_ret = smbrun(add_script, NULL, NULL);
                DEBUG(add_ret ? 0 : 1,("fetch_account: Running the command `%s' "
                         "gave %d\n", add_script, add_ret));
                if (add_ret == 0) {
index 91482e69f2e627acf88db00697f37599ff66ef17..01373de08904302c2c80f01aacd096210a7075ba 100644 (file)
@@ -276,7 +276,7 @@ static NTSTATUS smb_create_user(TALLOC_CTX *mem_ctx,
                if (!add_script) {
                        return NT_STATUS_NO_MEMORY;
                }
-               add_ret = smbrun(add_script, NULL);
+               add_ret = smbrun(add_script, NULL, NULL);
                DEBUG(add_ret ? 0 : 1,("fetch_account: Running the command `%s' "
                         "gave %d\n", add_script, add_ret));
                if (add_ret == 0) {
index a8c292544194fa6cb98a2a0b3d36ec19262e7a73..2273652b360a8520307e3eb007c777260c7733de 100644 (file)
@@ -59,7 +59,7 @@ static NTSTATUS shell_snap_check_path(struct vfs_handle_struct *handle,
                goto err_tmp_free;
        }
 
-       ret = smbrun(cmd_run, NULL);
+       ret = smbrun(cmd_run, NULL, NULL);
        if (ret != 0) {
                DEBUG(0, ("%s failed with %d\n", cmd_run, ret));
                status = NT_STATUS_NOT_SUPPORTED;
@@ -116,7 +116,7 @@ static NTSTATUS shell_snap_create(struct vfs_handle_struct *handle,
                goto err_tmp_free;
        }
 
-       ret = smbrun(cmd_run, &fd);
+       ret = smbrun(cmd_run, &fd, NULL);
        talloc_free(cmd_run);
        if (ret != 0) {
                if (fd != -1) {
@@ -178,7 +178,7 @@ static NTSTATUS shell_snap_delete(struct vfs_handle_struct *handle,
                return NT_STATUS_NO_MEMORY;
        }
 
-       ret = smbrun(cmd_run, NULL);
+       ret = smbrun(cmd_run, NULL, NULL);
        talloc_free(cmd_run);
        if (ret != 0) {
                return NT_STATUS_UNSUCCESSFUL;
index b943515a8fcb13210135daeaa093da6f9643a84b..aa0ae963ae4caac1bf66c8cf66fe88779c8841db 100644 (file)
@@ -521,7 +521,8 @@ static NTSTATUS tsmsm_set_offline(struct vfs_handle_struct *handle,
                return NT_STATUS_NO_MEMORY;
        }
        DEBUG(10, ("tsmsm_set_offline: Running [%s]\n", command));
-       if((result = smbrun(command, NULL)) != 0) {
+       result = smbrun(command, NULL, NULL)
+       if(result != 0) {
                DEBUG(1,("tsmsm_set_offline: Running [%s] returned %d\n", command, result));
                TALLOC_FREE(command);
                return NT_STATUS_INTERNAL_ERROR;
index 98ec625098744c9abc7618b1d3597e8868cd8143..cdec10e08ca9c17dbc1abb1ceff8e2839ca488dc 100644 (file)
@@ -501,7 +501,7 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt
        }
 
        DEBUG(3,("calling wins hook for %s\n", nmb_namestr(&namerec->name)));
-       smbrun(command, NULL);
+       smbrun(command, NULL, NULL);
        TALLOC_FREE(command);
 }
 
index 5260320939e8834e2a9ecb1c0d5443dbbcdf1345..36ae576eb206b9e4e9e1e5168f79ab0a289bf6cb 100644 (file)
@@ -485,7 +485,7 @@ static NTSTATUS pdb_default_create_user(struct pdb_methods *methods,
                if (!add_script) {
                        return NT_STATUS_NO_MEMORY;
                }
-               add_ret = smbrun(add_script,NULL);
+               add_ret = smbrun(add_script, NULL, NULL);
                DEBUG(add_ret ? 0 : 3, ("_samr_create_user: Running the command `%s' gave %d\n",
                                        add_script, add_ret));
                if (add_ret == 0) {
@@ -570,7 +570,7 @@ static int smb_delete_user(const char *unix_user)
        if (!del_script) {
                return -1;
        }
-       ret = smbrun(del_script,NULL);
+       ret = smbrun(del_script, NULL, NULL);
        flush_pwnam_cache();
        if (ret == 0) {
                smb_nscd_flush_user_cache();
index 4383785a8418f5c54c2579a415b5eff3388f5faf..e3dd790b1fa36a50db4080cd4cd72715b10691b3 100644 (file)
@@ -2013,7 +2013,7 @@ static NTSTATUS ldapsam_rename_sam_account(struct pdb_methods *my_methods,
                                        oldname_lower,
                                        true,
                                        true);
-       rc = smbrun(rename_script, NULL);
+       rc = smbrun(rename_script, NULL, NULL);
 
        DEBUG(rc ? 0 : 3,("Running the command `%s' gave %d\n",
                          rename_script, rc));
index 9250bea32fc772bd355e3181ab7a2f8db0b3ef11..8a75fde644e1c8e5e78e276652ed6d3684bf795e 100644 (file)
@@ -1501,7 +1501,7 @@ static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
                        goto done;
                }
 
-               rename_ret = smbrun(rename_script, NULL);
+               rename_ret = smbrun(rename_script, NULL, NULL);
 
                DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret));
 
index 74a27920da695f70361d6180a755a2f9b7664cdc..6453c9f48b994a45697e9e9bbf0ca7aa9899f4b3 100644 (file)
@@ -1083,7 +1083,7 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods,
        if (!rename_script) {
                goto cancel;
        }
-       rename_ret = smbrun(rename_script, NULL);
+       rename_ret = smbrun(rename_script, NULL, NULL);
 
        DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n",
                                rename_script, rename_ret));
index e89eed7bcdda983738d546177e68eb8968d14c6a..d77fb21e3fd47dab66bcd8bd2590e1a8292a738c 100644 (file)
@@ -85,7 +85,7 @@ static int print_run_command(int snum, const char* printername, bool do_sub,
                }
        }
 
-       ret = smbrun_no_sanitize(syscmd,outfd);
+       ret = smbrun_no_sanitize(syscmd, outfd, NULL);
 
        DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
 
index 99e5eb2add1295805f01baa96cd894ccd3964e4e..c8ff44960d045948329893aaeba46ff5149ca999 100644 (file)
@@ -401,7 +401,8 @@ static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
        if ( is_print_op )
                become_root();
 
-       if ( (ret = smbrun(command, NULL)) == 0 ) {
+       ret = smbrun(command, NULL, NULL);
+       if (ret == 0) {
                /* Tell everyone we updated smb.conf. */
                message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
        }
@@ -6317,7 +6318,7 @@ static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const
        if ( is_print_op )
                become_root();
 
-       ret = smbrun(command, NULL);
+       ret = smbrun(command, NULL, NULL);
 
        if ( is_print_op )
                unbecome_root();
@@ -6384,7 +6385,8 @@ static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
        if ( is_print_op )
                become_root();
 
-       if ( (ret = smbrun(command, &fd)) == 0 ) {
+       ret = smbrun(command, &fd, NULL);
+       if (ret == 0) {
                /* Tell everyone we updated smb.conf. */
                message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
        }
@@ -8142,7 +8144,7 @@ static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
                }
 
                DEBUG(10,("Running [%s]\n", command));
-               ret = smbrun(command, &fd);
+               ret = smbrun(command, &fd, NULL);
                DEBUG(10,("Returned [%d]\n", ret));
                TALLOC_FREE(command);
                if (ret != 0) {
index a5236d82a5b9b21b5008e101cbd129d24053f24f..17172d27fe40920d7562bd87dd717aecca22ce32 100644 (file)
@@ -1904,7 +1904,8 @@ WERROR _srvsvc_NetShareSetInfo(struct pipes_struct *p,
                if (is_disk_op)
                        become_root();
 
-               if ( (ret = smbrun(command, NULL)) == 0 ) {
+               ret = smbrun(command, NULL, NULL);
+               if (ret == 0) {
                        /* Tell everyone we updated smb.conf. */
                        message_send_all(p->msg_ctx, MSG_SMB_CONF_UPDATED,
                                         NULL, 0, NULL);
@@ -2106,7 +2107,8 @@ WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
 
        /* FIXME: use libnetconf here - gd */
 
-       if ( (ret = smbrun(command, NULL)) == 0 ) {
+       ret = smbrun(command, NULL, NULL);
+       if (ret == 0) {
                /* Tell everyone we updated smb.conf. */
                message_send_all(p->msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0,
                                 NULL);
@@ -2213,7 +2215,8 @@ WERROR _srvsvc_NetShareDel(struct pipes_struct *p,
        if ( is_disk_op )
                become_root();
 
-       if ( (ret = smbrun(command, NULL)) == 0 ) {
+       ret = smbrun(command, NULL, NULL);
+       if (ret == 0) {
                /* Tell everyone we updated smb.conf. */
                message_send_all(p->msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0,
                                 NULL);
index 3cfd009931f04fc89a74d751ef52b07c257b2c31..d9ee8d0602d1461f657e144fe0c87346ee100e91 100644 (file)
@@ -592,7 +592,7 @@ WERROR _winreg_InitiateSystemShutdownEx(struct pipes_struct *p,
        if ( can_shutdown )
                become_root();
 
-       ret = smbrun( shutdown_script, NULL );
+       ret = smbrun(shutdown_script, NULL, NULL);
 
        if ( can_shutdown )
                unbecome_root();
@@ -626,7 +626,7 @@ WERROR _winreg_AbortSystemShutdown(struct pipes_struct *p,
        if ( can_shutdown )
                become_root();
 
-       ret = smbrun( abort_shutdown_script, NULL );
+       ret = smbrun(abort_shutdown_script, NULL, NULL);
 
        if ( can_shutdown )
                unbecome_root();
index a47931d63b691d5f37fc8f39eac7662417a15cc0..95442ce2efb73dfbd7afe5f9555a9db5e76dbed6 100644 (file)
@@ -36,7 +36,7 @@ static WERROR rcinit_stop( const char *service, struct SERVICE_STATUS *status )
        /* we've already performed the access check when the service was opened */
 
        become_root();
-       ret = smbrun( command , &fd );
+       ret = smbrun(command, &fd, NULL);
        unbecome_root();
 
        DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
@@ -70,7 +70,7 @@ static WERROR rcinit_start( const char *service )
        /* we've already performed the access check when the service was opened */
 
        become_root();
-       ret = smbrun( command , &fd );
+       ret = smbrun(command, &fd, NULL);
        unbecome_root();
 
        DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
@@ -99,7 +99,7 @@ static WERROR rcinit_status( const char *service, struct SERVICE_STATUS *status
           is STOPPED */
 
        become_root();
-       ret = smbrun( command , &fd );
+       ret = smbrun(command, &fd, NULL);
        unbecome_root();
 
        DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
index 22bd361768baf19b826a29e9c4a810bcfc88509d..bc468c7e55de6d5175574191c5230af7ce696678 100644 (file)
@@ -91,7 +91,7 @@ static NTSTATUS check_magic(struct files_struct *fsp)
                status = map_nt_error_from_unix(errno);
                goto out;
        }
-       ret = smbrun(p,&tmp_fd);
+       ret = smbrun(p, &tmp_fd, NULL);
        DEBUG(3,("Invoking magic command %s gave %d\n",
                p,ret));
 
index a1ead4a56fbb4b4b36bc5b4facddaad1eca6ce96..1c3976dd3e9edb822cd200d4f9d8db5bed4c6112 100644 (file)
@@ -129,7 +129,7 @@ static void msg_deliver(struct msg_state *state)
        if (s == NULL) {
                goto done;
        }
-       smbrun(s,NULL);
+       smbrun(s, NULL, NULL);
 
  done:
        TALLOC_FREE(frame);
index 5b54aecd12f1ca774e019a74c294a74f525d5bca..3308e9dce971dad026ae7de00d5184415b591afc 100644 (file)
@@ -764,7 +764,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
                                        conn->session_info->info->domain_name,
                                        lp_root_preexec(talloc_tos(), snum));
                DEBUG(5,("cmd=%s\n",cmd));
-               ret = smbrun(cmd,NULL);
+               ret = smbrun(cmd, NULL, NULL);
                TALLOC_FREE(cmd);
                if (ret != 0 && lp_root_preexec_close(snum)) {
                        DEBUG(1,("root preexec gave %d - failing "
@@ -801,7 +801,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
                                        conn->session_info->unix_info->sanitized_username,
                                        conn->session_info->info->domain_name,
                                        lp_preexec(talloc_tos(), snum));
-               ret = smbrun(cmd,NULL);
+               ret = smbrun(cmd, NULL, NULL);
                TALLOC_FREE(cmd);
                if (ret != 0 && lp_preexec_close(snum)) {
                        DEBUG(1,("preexec gave %d - failing connection\n",
@@ -1199,7 +1199,7 @@ void close_cnum(connection_struct *conn, uint64_t vuid)
                                        conn->session_info->unix_info->sanitized_username,
                                        conn->session_info->info->domain_name,
                                        lp_postexec(talloc_tos(), SNUM(conn)));
-               smbrun(cmd,NULL);
+               smbrun(cmd, NULL, NULL);
                TALLOC_FREE(cmd);
                change_to_root_user();
        }
@@ -1215,7 +1215,7 @@ void close_cnum(connection_struct *conn, uint64_t vuid)
                                        conn->session_info->unix_info->sanitized_username,
                                        conn->session_info->info->domain_name,
                                        lp_root_postexec(talloc_tos(), SNUM(conn)));
-               smbrun(cmd,NULL);
+               smbrun(cmd, NULL, NULL);
                TALLOC_FREE(cmd);
        }