The branch, master has been updated via b4239ca idmap_script: Parallelize script calls via 2f6a69d lib: Avoid an unnecessary cast via 3a1685d lib: Remove "includes.h" from util_file.c via b4b8c8c lib: Add file_pload_send/recv via 3de5d8f lib: Add "mem_ctx" to file_lines_pload via 5276835 lib: Remove an unimplemented prototype via 908df8e lib: Extract sys_popen() via 8338fe6 lib: Remove sys_waitpid via b7b7b0a lib: Fix whitespace via 7377803 lib: Move data_blob_list_item to source4 via 746f54c smbd: Fix line length & whitespace in write_file via 8fc86f4 py_xattr: Fix a "ignoring return value" warning from 7b4dfd9 winbindd: return trust parameters when listing trusts
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit b4239ca096738f553b0f9d7fa6aaa4219b72ef7f Author: Volker Lendecke <v...@samba.org> Date: Wed Feb 17 14:01:47 2016 +0100 idmap_script: Parallelize script calls Fixes a case I've seen where a user with 200 group memberships timed out and can now log in. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> Autobuild-User(master): Michael Adam <ob...@samba.org> Autobuild-Date(master): Wed Feb 24 01:17:25 CET 2016 on sn-devel-144 commit 2f6a69d807ed1a9ff2413a49f4ef751d9c4851cf Author: Volker Lendecke <v...@samba.org> Date: Mon Feb 22 11:59:52 2016 +0100 lib: Avoid an unnecessary cast Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> commit 3a1685db0b42cadcd8616949c73e7e5a06e6057b Author: Volker Lendecke <v...@samba.org> Date: Tue Feb 16 17:09:43 2016 +0100 lib: Remove "includes.h" from util_file.c Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> commit b4b8c8ca0133132add7c5adfd1099666566b2882 Author: Volker Lendecke <v...@samba.org> Date: Tue Feb 16 17:01:04 2016 +0100 lib: Add file_pload_send/recv Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> commit 3de5d8fdfd02fc796e7e06686fb07bbfc47e6851 Author: Volker Lendecke <v...@samba.org> Date: Tue Feb 16 16:29:01 2016 +0100 lib: Add "mem_ctx" to file_lines_pload Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> commit 52768351bea0e8d3b85bd08ade4ffe34c449a481 Author: Volker Lendecke <v...@samba.org> Date: Tue Feb 16 16:24:29 2016 +0100 lib: Remove an unimplemented prototype Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> commit 908df8ec136626616e9419986f09ff1bf30dbde1 Author: Volker Lendecke <v...@samba.org> Date: Tue Feb 16 15:58:52 2016 +0100 lib: Extract sys_popen() This was added by Jeremy with 3cf31a194f5, do the (C) accordingly sys_popen is a pretty isolated functionality, and I'd like to use it soon without "includes.h", needed by "proto.h" Except for one malloc->talloc this is supposed to be a 1:1 copy Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> commit 8338fe6ac878ef8c04276229ae6e6a8edf9c3e3a Author: Volker Lendecke <v...@samba.org> Date: Tue Feb 16 15:46:06 2016 +0100 lib: Remove sys_waitpid We have waitpid in libreplace Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> commit b7b7b0a819f52fa645bfd5a417a0a1a2684c7a1f Author: Volker Lendecke <v...@samba.org> Date: Tue Feb 16 14:59:53 2016 +0100 lib: Fix whitespace Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> commit 737780384c0fbf8722239dceed7c8fcfa45552cb Author: Volker Lendecke <v...@samba.org> Date: Sat Feb 20 10:07:11 2016 +0100 lib: Move data_blob_list_item to source4 It's only used in dcesrv_call_state. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> commit 746f54c1cf6514b547c2df2e56c69671916053b6 Author: Volker Lendecke <v...@samba.org> Date: Thu Jan 14 11:51:39 2016 +0100 smbd: Fix line length & whitespace in write_file No code change intended. This file just looked to hard to read. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> commit 8fc86f41e4072d5717f0d7a000cdb7461c8effd9 Author: Volker Lendecke <v...@samba.org> Date: Wed Jan 13 11:15:36 2016 +0100 py_xattr: Fix a "ignoring return value" warning Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Michael Adam <ob...@samba.org> ----------------------------------------------------------------------- Summary of changes: lib/util/data_blob.h | 5 - source3/include/proto.h | 8 - source3/lib/g_lock.c | 2 +- source3/lib/server_prefork.c | 2 +- source3/lib/smbrun.c | 4 +- source3/lib/sys_popen.c | 254 +++++++++ lib/util/close_low_fd.h => source3/lib/sys_popen.h | 14 +- source3/lib/sysquotas.c | 5 +- source3/lib/system.c | 244 -------- source3/lib/tdb_validate.c | 2 +- source3/lib/util_file.c | 144 ++++- source3/{passdb/pdb_tdb.h => lib/util_file.h} | 25 +- source3/printing/print_svid.c | 5 +- source3/printing/queue_process.c | 2 +- source3/printing/spoolssd.c | 2 +- source3/rpc_server/samr/srv_samr_chgpasswd.c | 2 +- source3/smbd/dfree.c | 3 +- source3/smbd/fileio.c | 117 ++-- source3/smbd/server.c | 2 +- source3/winbindd/idmap_script.c | 623 ++++++++++++++------- source3/winbindd/winbindd.c | 2 +- source3/wscript_build | 1 + source4/librpc/ndr/py_xattr.c | 8 +- source4/rpc_server/dcerpc_server.h | 5 + tests/fcntl_lock_thread.c | 5 - 25 files changed, 948 insertions(+), 538 deletions(-) create mode 100644 source3/lib/sys_popen.c copy lib/util/close_low_fd.h => source3/lib/sys_popen.h (79%) copy source3/{passdb/pdb_tdb.h => lib/util_file.h} (59%) Changeset truncated at 500 lines: diff --git a/lib/util/data_blob.h b/lib/util/data_blob.h index 94af767..799e953 100644 --- a/lib/util/data_blob.h +++ b/lib/util/data_blob.h @@ -40,11 +40,6 @@ typedef struct datablob { size_t length; } DATA_BLOB; -struct data_blob_list_item { - struct data_blob_list_item *prev,*next; - DATA_BLOB blob; -}; - /* by making struct ldb_val and DATA_BLOB the same, we can simplify a fair bit of code */ #define ldb_val datablob diff --git a/source3/include/proto.h b/source3/include/proto.h index 09e9915..0c15f96 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -243,7 +243,6 @@ int sys_fallocate(int fd, uint32_t mode, off_t offset, off_t len); void kernel_flock(int fd, uint32_t share_mode, uint32_t access_mask); DIR *sys_fdopendir(int fd); int sys_mknod(const char *path, mode_t mode, SMB_DEV_T dev); -int sys_waitpid(pid_t pid,int *status,int options); char *sys_getwd(void); void set_effective_capability(enum smbd_capability capability); void drop_effective_capability(enum smbd_capability capability); @@ -252,8 +251,6 @@ void sys_srandom(unsigned int seed); int groups_max(void); int sys_getgroups(int setlen, gid_t *gidset); int sys_setgroups(gid_t UNUSED(primary_gid), int setlen, gid_t *gidset); -int sys_popen(const char *command); -int sys_pclose(int fd); ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size); ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size); ssize_t sys_listxattr (const char *path, char *list, size_t size); @@ -452,11 +449,6 @@ bool sid_check_is_builtin(const struct dom_sid *sid); bool sid_check_is_in_builtin(const struct dom_sid *sid); bool sid_check_is_wellknown_builtin(const struct dom_sid *sid); -/* The following definitions come from lib/util_file.c */ - -char **file_lines_pload(const char *syscmd, int *numlines); -void file_lines_free(char **lines); - /* The following definitions come from lib/util_nscd.c */ void smb_nscd_flush_user_cache(void); diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 30c5f52..346c1ed 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -99,7 +99,7 @@ static bool g_lock_parse(TALLOC_CTX *mem_ctx, TDB_DATA data, struct g_lock_rec *locks; if ((data.dsize % sizeof(struct g_lock_rec)) != 0) { - DEBUG(1, ("invalid lock record length %d\n", (int)data.dsize)); + DEBUG(1, ("invalid lock record length %zu\n", data.dsize)); return false; } num_locks = data.dsize / sizeof(struct g_lock_rec); diff --git a/source3/lib/server_prefork.c b/source3/lib/server_prefork.c index c725607..1d64db2 100644 --- a/source3/lib/server_prefork.c +++ b/source3/lib/server_prefork.c @@ -329,7 +329,7 @@ static void prefork_cleanup_loop(struct prefork_pool *pfp) continue; } - pid = sys_waitpid(pfp->pool[i].pid, &status, WNOHANG); + pid = waitpid(pfp->pool[i].pid, &status, WNOHANG); if (pid > 0) { if (pfp->pool[i].status != PF_WORKER_EXITING) { diff --git a/source3/lib/smbrun.c b/source3/lib/smbrun.c index 55f7a87..63b0323 100644 --- a/source3/lib/smbrun.c +++ b/source3/lib/smbrun.c @@ -116,7 +116,7 @@ static int smbrun_internal(const char *cmd, int *outfd, bool sanitize) /* the parent just waits for the child to exit */ - while((wpid = sys_waitpid(pid,&status,0)) < 0) { + while((wpid = waitpid(pid,&status,0)) < 0) { if(errno == EINTR) { errno = 0; continue; @@ -287,7 +287,7 @@ int smbrunsecret(const char *cmd, const char *secret) close(ifd[1]); /* the parent just waits for the child to exit */ - while((wpid = sys_waitpid(pid, &status, 0)) < 0) { + while((wpid = waitpid(pid, &status, 0)) < 0) { if(errno == EINTR) { errno = 0; continue; diff --git a/source3/lib/sys_popen.c b/source3/lib/sys_popen.c new file mode 100644 index 0000000..607e599 --- /dev/null +++ b/source3/lib/sys_popen.c @@ -0,0 +1,254 @@ +/* + * Unix SMB/CIFS implementation. + * Samba system utilities + * Copyright (C) Jeremy Allison 2000 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "replace.h" +#include "system/wait.h" +#include "system/filesys.h" +#include <talloc.h> +#include "lib/sys_popen.h" +#include "lib/util/debug.h" + +/************************************************************************** + Extract a command into an arg list. +****************************************************************************/ + +static char **extract_args(TALLOC_CTX *mem_ctx, const char *command) +{ + char *trunc_cmd; + char *saveptr; + char *ptr; + int argcl; + char **argl = NULL; + int i; + + if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) { + DEBUG(0, ("talloc failed\n")); + goto nomem; + } + + if(!(ptr = strtok_r(trunc_cmd, " \t", &saveptr))) { + TALLOC_FREE(trunc_cmd); + errno = EINVAL; + return NULL; + } + + /* + * Count the args. + */ + + for( argcl = 1; ptr; ptr = strtok_r(NULL, " \t", &saveptr)) + argcl++; + + TALLOC_FREE(trunc_cmd); + + if (!(argl = talloc_array(mem_ctx, char *, argcl + 1))) { + goto nomem; + } + + /* + * Now do the extraction. + */ + + if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) { + goto nomem; + } + + ptr = strtok_r(trunc_cmd, " \t", &saveptr); + i = 0; + + if (!(argl[i++] = talloc_strdup(argl, ptr))) { + goto nomem; + } + + while((ptr = strtok_r(NULL, " \t", &saveptr)) != NULL) { + + if (!(argl[i++] = talloc_strdup(argl, ptr))) { + goto nomem; + } + } + + argl[i++] = NULL; + TALLOC_FREE(trunc_cmd); + return argl; + + nomem: + DEBUG(0, ("talloc failed\n")); + TALLOC_FREE(trunc_cmd); + TALLOC_FREE(argl); + errno = ENOMEM; + return NULL; +} + +/************************************************************************** + Wrapper for popen. Safer as it doesn't search a path. + Modified from the glibc sources. + modified by tridge to return a file descriptor. We must kick our FILE* habit +****************************************************************************/ + +typedef struct _popen_list +{ + int fd; + pid_t child_pid; + struct _popen_list *next; +} popen_list; + +static popen_list *popen_chain; + +int sys_popen(const char *command) +{ + int parent_end, child_end; + int pipe_fds[2]; + popen_list *entry = NULL; + char **argl = NULL; + int ret; + + if (!*command) { + errno = EINVAL; + return -1; + } + + ret = pipe(pipe_fds); + if (ret < 0) { + DEBUG(0, ("sys_popen: error opening pipe: %s\n", + strerror(errno))); + return -1; + } + + parent_end = pipe_fds[0]; + child_end = pipe_fds[1]; + + entry = talloc_zero(NULL, popen_list); + if (entry == NULL) { + DEBUG(0, ("sys_popen: malloc failed\n")); + goto err_exit; + } + + /* + * Extract the command and args into a NULL terminated array. + */ + + argl = extract_args(NULL, command); + if (argl == NULL) { + DEBUG(0, ("sys_popen: extract_args() failed: %s\n", strerror(errno))); + goto err_exit; + } + + entry->child_pid = fork(); + + if (entry->child_pid == -1) { + DEBUG(0, ("sys_popen: fork failed: %s\n", strerror(errno))); + goto err_exit; + } + + if (entry->child_pid == 0) { + + /* + * Child ! + */ + + int child_std_end = STDOUT_FILENO; + popen_list *p; + + close(parent_end); + if (child_end != child_std_end) { + dup2 (child_end, child_std_end); + close (child_end); + } + + /* + * POSIX.2: "popen() shall ensure that any streams from previous + * popen() calls that remain open in the parent process are closed + * in the new child process." + */ + + for (p = popen_chain; p; p = p->next) + close(p->fd); + + ret = execv(argl[0], argl); + if (ret == -1) { + DEBUG(0, ("sys_popen: ERROR executing command " + "'%s': %s\n", command, strerror(errno))); + } + _exit (127); + } + + /* + * Parent. + */ + + close (child_end); + TALLOC_FREE(argl); + + /* Link into popen_chain. */ + entry->next = popen_chain; + popen_chain = entry; + entry->fd = parent_end; + + return entry->fd; + +err_exit: + + TALLOC_FREE(entry); + TALLOC_FREE(argl); + close(pipe_fds[0]); + close(pipe_fds[1]); + return -1; +} + +/************************************************************************** + Wrapper for pclose. Modified from the glibc sources. +****************************************************************************/ + +int sys_pclose(int fd) +{ + int wstatus; + popen_list **ptr = &popen_chain; + popen_list *entry = NULL; + pid_t wait_pid; + int status = -1; + + /* Unlink from popen_chain. */ + for ( ; *ptr != NULL; ptr = &(*ptr)->next) { + if ((*ptr)->fd == fd) { + entry = *ptr; + *ptr = (*ptr)->next; + status = 0; + break; + } + } + + if (status < 0 || close(entry->fd) < 0) + return -1; + + /* + * As Samba is catching and eating child process + * exits we don't really care about the child exit + * code, a -1 with errno = ECHILD will do fine for us. + */ + + do { + wait_pid = waitpid (entry->child_pid, &wstatus, 0); + } while (wait_pid == -1 && errno == EINTR); + + TALLOC_FREE(entry); + + if (wait_pid == -1) + return -1; + return wstatus; +} diff --git a/lib/util/close_low_fd.h b/source3/lib/sys_popen.h similarity index 79% copy from lib/util/close_low_fd.h copy to source3/lib/sys_popen.h index 954d1d2..6807d3c 100644 --- a/lib/util/close_low_fd.h +++ b/source3/lib/sys_popen.h @@ -1,7 +1,7 @@ /* * Unix SMB/CIFS implementation. - * Samba utility functions - * Copyright (C) Volker Lendecke 2014 + * Samba system utilities + * Copyright (C) Jeremy Allison 2000 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,12 +17,10 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _CLOSE_LOW_FD_H -#define _CLOSE_LOW_FD_H +#ifndef __LIB_SYS_POPEN_H__ +#define __LIB_SYS_POPEN_H__ -/* - * Redirect "fd" to /dev/null - */ -int close_low_fd(int fd); +int sys_popen(const char *command); +int sys_pclose(int fd); #endif diff --git a/source3/lib/sysquotas.c b/source3/lib/sysquotas.c index bacc4b2..102e458 100644 --- a/source3/lib/sysquotas.c +++ b/source3/lib/sysquotas.c @@ -19,6 +19,7 @@ #include "includes.h" +#include "lib/util_file.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_QUOTA @@ -268,7 +269,7 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t DEBUG (3, ("get_quota: Running command %s\n", syscmd)); - lines = file_lines_pload(syscmd, NULL); + lines = file_lines_pload(talloc_tos(), syscmd, NULL); SAFE_FREE(syscmd); if (lines) { @@ -416,7 +417,7 @@ static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t DEBUG (3, ("get_quota: Running command %s\n", syscmd)); - lines = file_lines_pload(syscmd, NULL); + lines = file_lines_pload(talloc_tos(), syscmd, NULL); SAFE_FREE(syscmd); if (lines) { char *line = lines[0]; diff --git a/source3/lib/system.c b/source3/lib/system.c index 0351e37..3d3eeed 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -572,19 +572,6 @@ int sys_mknod(const char *path, mode_t mode, SMB_DEV_T dev) } /******************************************************************* -The wait() calls vary between systems -********************************************************************/ - -int sys_waitpid(pid_t pid,int *status,int options) -{ -#ifdef HAVE_WAITPID - return waitpid(pid,status,options); -#else /* HAVE_WAITPID */ - return wait4(pid, status, options, NULL); -#endif /* HAVE_WAITPID */ -} - -/******************************************************************* System wrapper for getwd. Always returns MALLOC'ed memory, or NULL on error (malloc fail usually). ********************************************************************/ @@ -979,237 +966,6 @@ int sys_setgroups(gid_t UNUSED(primary_gid), int setlen, gid_t *gidset) #endif } -/************************************************************************** - Extract a command into an arg list. -****************************************************************************/ - -static char **extract_args(TALLOC_CTX *mem_ctx, const char *command) -{ - char *trunc_cmd; - char *saveptr; - char *ptr; - int argcl; - char **argl = NULL; - int i; - - if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) { - DEBUG(0, ("talloc failed\n")); - goto nomem; - } - - if(!(ptr = strtok_r(trunc_cmd, " \t", &saveptr))) { - TALLOC_FREE(trunc_cmd); - errno = EINVAL; - return NULL; - } - - /* - * Count the args. - */ - - for( argcl = 1; ptr; ptr = strtok_r(NULL, " \t", &saveptr)) - argcl++; - - TALLOC_FREE(trunc_cmd); - - if (!(argl = talloc_array(mem_ctx, char *, argcl + 1))) { - goto nomem; - } - - /* - * Now do the extraction. - */ - - if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) { - goto nomem; - } - - ptr = strtok_r(trunc_cmd, " \t", &saveptr); - i = 0; - - if (!(argl[i++] = talloc_strdup(argl, ptr))) { - goto nomem; - } -- Samba Shared Repository