summaryrefslogtreecommitdiff
path: root/source3/param/loadparm.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-04-16 11:00:21 +0000
committerAndrew Tridgell <tridge@samba.org>2000-04-16 11:00:21 +0000
commit19f946ba6fe442544ac9b0f71bcd33112fc79995 (patch)
tree1f26158879ef7eba4670d0811871077e921dc65b /source3/param/loadparm.c
parent83170b36c5511b000e36ad0d3a1d9b73a73d2046 (diff)
downloadsamba-19f946ba6fe442544ac9b0f71bcd33112fc79995.tar.gz
samba-19f946ba6fe442544ac9b0f71bcd33112fc79995.tar.bz2
samba-19f946ba6fe442544ac9b0f71bcd33112fc79995.zip
converted a bunch more functions to use a fd instead of a FILE*
to support some of this I added the following functions in util_file.c file_lines_pload : load lines from a pipe file_pload : load a pipe into memory (This used to be commit a09470817c5b21dba42f9ef4ce5e8b768a254c0b)
Diffstat (limited to 'source3/param/loadparm.c')
-rw-r--r--source3/param/loadparm.c60
1 files changed, 14 insertions, 46 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 6890a08fce..cc5a51c6c6 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -1971,19 +1971,15 @@ static BOOL handle_netbios_name(char *pszParmValue,char **ptr)
Do the work of sourcing in environment variable/value pairs.
***************************************************************************/
-static BOOL source_env(FILE *fenv)
+static BOOL source_env(char **lines)
{
- pstring line;
char *varval;
size_t len;
+ int i;
char *p;
- while (!feof(fenv)) {
- if (fgets(line, sizeof(line), fenv) == NULL)
- break;
-
- if(feof(fenv))
- break;
+ for (i=0; lines[i]; i++) {
+ char *line = lines[i];
if((len = strlen(line)) == 0)
continue;
@@ -2028,8 +2024,8 @@ static BOOL handle_source_env(char *pszParmValue,char **ptr)
{
pstring fname;
char *p = fname;
- FILE *env;
BOOL result;
+ char **lines;
pstrcpy(fname,pszParmValue);
@@ -2044,47 +2040,19 @@ static BOOL handle_source_env(char *pszParmValue,char **ptr)
*/
if (*p == '|') {
-
- DEBUG(4, ("handle_source_env: source env from pipe\n"));
- p++;
-
- if ((env = sys_popen(p, "r", True)) == NULL) {
- DEBUG(0,("handle_source_env: Failed to popen %s. Error was %s\n", p, strerror(errno) ));
- return(False);
- }
-
- DEBUG(4, ("handle_source_env: calling source_env()\n"));
- result = source_env(env);
- sys_pclose(env);
-
+ lines = file_lines_pload(p+1, NULL);
} else {
+ lines = file_lines_load(fname, NULL);
+ }
- SMB_STRUCT_STAT st;
-
- DEBUG(4, ("handle_source_env: source env from file %s\n", fname));
- if ((env = sys_fopen(fname, "r")) == NULL) {
- DEBUG(0,("handle_source_env: Failed to open file %s, Error was %s\n", fname, strerror(errno) ));
- return(False);
- }
-
- /*
- * Ensure this file is owned by root and not writable by world.
- */
- if(sys_fstat(fileno(env), &st) != 0) {
- DEBUG(0,("handle_source_env: Failed to stat file %s, Error was %s\n", fname, strerror(errno) ));
- fclose(env);
- return False;
- }
+ if (!lines) {
+ DEBUG(0,("handle_source_env: Failed to open file %s, Error was %s\n", fname, strerror(errno) ));
+ return(False);
+ }
- if((st.st_uid != (uid_t)0) || (st.st_mode & S_IWOTH)) {
- DEBUG(0,("handle_source_env: unsafe to source env file %s. Not owned by root or world writable\n", fname ));
- fclose(env);
- return False;
- }
+ result=source_env(lines);
+ file_lines_free(lines);
- result=source_env(env);
- fclose(env);
- }
return(result);
}