PATCH: 'source environment' param and % token subs for 'netbios name'
Nicolas Williams
Nicolas.Williams at wdr.com
Fri Jan 28 17:54:07 GMT 2000
Ooops, forgot to attach the diff... Sorry.
Oh, and, my apologies for that nasty, silly disclaimer that the gateways
here append to outgoing e-mails.
Nico
-DISCLAIMER: an automatically appended disclaimer may follow. By posting-
-to a public e-mail mailing list I hereby grant permission to distribute-
-and copy this message.-
-------------- next part --------------
diff -u -r samba.2.0.6.orig/docs/manpages/smb.conf.5 samba-sourceenv/docs/manpages/smb.conf.5
--- samba.2.0.6.orig/docs/manpages/smb.conf.5 Fri Jan 28 12:03:10 2000
+++ samba-sourceenv/docs/manpages/smb.conf.5 Fri Jan 28 12:41:12 2000
@@ -829,6 +829,9 @@
\fBsocket options\fP
.IP
.IP o
+\fBsource environment\fP
+.IP
+.IP o
\fBssl\fP
.IP
.IP o
@@ -5776,6 +5779,27 @@
\fBExample:\fP
\f(CW socket options = IPTOS_LOWDELAY\fP
.IP
+.IP "\fBsource environment (G)\fP"
+.IP
+This parameter causes Samba to set environment variables as per the
+content of the file named.
+.IP
+If the value of this parameter ends with a "|" character then Samba will
+treat that value as a pipe command to open and will set the environment
+variables from the oput of the pipe.
+.IP
+The contents of the file or the output of the pipe should be formatted
+as the output of the standard Unix env(1) command.
+.IP
+\fBExample:\fP
+\f(CW source environment = /etc/smb.conf.env\fP
+.IP
+\fBExample:\fP
+\f(CW source environment = /etc/smb.conf.sh|\fP
+.IP
+\fBExample environment entry:\fP
+\f(CWSAMBA_NETBIOS_NAME=myhostname\fP
+.IP
.IP "\fBssl (G)\fP"
.IP
This variable is part of SSL-enabled Samba\&. This is only available if
diff -u -r samba.2.0.6.orig/source/param/loadparm.c samba-sourceenv/source/param/loadparm.c
--- samba.2.0.6.orig/source/param/loadparm.c Fri Jan 28 12:03:16 2000
+++ samba-sourceenv/source/param/loadparm.c Fri Jan 28 11:57:59 2000
@@ -158,6 +158,7 @@
char *szAddUserScript;
char *szDelUserScript;
char *szWINSHook;
+ char *szSourceEnv;
int max_log_size;
int mangled_stack;
int max_xmit;
@@ -472,6 +473,8 @@
static BOOL handle_character_set(char *pszParmValue,char **ptr);
static BOOL handle_coding_system(char *pszParmValue,char **ptr);
static BOOL handle_client_code_page(char *pszParmValue,char **ptr);
+static BOOL handle_source_env(char *pszParmValue,char **ptr);
+static BOOL handle_netbios_name(char *pszParmValue,char **ptr);
static void set_default_server_announce_type(void);
@@ -538,7 +541,7 @@
{"path", P_STRING, P_LOCAL, &sDefault.szPath, NULL, NULL, FLAG_BASIC|FLAG_SHARE|FLAG_PRINT|FLAG_DOS_STRING},
{"directory", P_STRING, P_LOCAL, &sDefault.szPath, NULL, NULL, FLAG_DOS_STRING},
{"workgroup", P_USTRING, P_GLOBAL, &Globals.szWorkGroup, NULL, NULL, FLAG_BASIC|FLAG_DOS_STRING},
- {"netbios name", P_UGSTRING,P_GLOBAL, global_myname, NULL, NULL, FLAG_BASIC|FLAG_DOS_STRING},
+ {"netbios name", P_UGSTRING,P_GLOBAL, global_myname, handle_netbios_name, NULL, FLAG_BASIC|FLAG_DOS_STRING},
{"netbios aliases", P_STRING, P_GLOBAL, &Globals.szNetbiosAliases, NULL, NULL, FLAG_DOS_STRING},
{"server string", P_STRING, P_GLOBAL, &Globals.szServerString, NULL, NULL, FLAG_BASIC|FLAG_DOS_STRING},
{"interfaces", P_STRING, P_GLOBAL, &Globals.szInterfaces, NULL, NULL, FLAG_BASIC},
@@ -820,6 +823,7 @@
{"volume", P_STRING, P_LOCAL, &sDefault.volume, NULL, NULL, FLAG_SHARE},
{"fstype", P_STRING, P_LOCAL, &sDefault.fstype, NULL, NULL, FLAG_SHARE},
{"set directory", P_BOOLREV, P_LOCAL, &sDefault.bNo_set_dir, NULL, NULL, FLAG_SHARE},
+ {"source environment", P_STRING, P_GLOBAL, &Globals.szSourceEnv, handle_source_env, NULL, 0},
{"wide links", P_BOOL, P_LOCAL, &sDefault.bWidelinks, NULL, NULL, FLAG_SHARE|FLAG_GLOBAL},
{"follow symlinks", P_BOOL, P_LOCAL, &sDefault.bSymlinks, NULL, NULL, FLAG_SHARE|FLAG_GLOBAL},
{"dont descend", P_STRING, P_LOCAL, &sDefault.szDontdescend, NULL, NULL, FLAG_SHARE},
@@ -1171,6 +1175,7 @@
FN_GLOBAL_STRING(lp_printcapname,&Globals.szPrintcapname)
FN_GLOBAL_STRING(lp_lockdir,&Globals.szLockDir)
FN_GLOBAL_STRING(lp_rootdir,&Globals.szRootdir)
+FN_GLOBAL_STRING(lp_sourceenv,&Globals.szSourceEnv)
FN_GLOBAL_STRING(lp_defaultservice,&Globals.szDefaultService)
FN_GLOBAL_STRING(lp_msg_command,&Globals.szMsgCommand)
FN_GLOBAL_STRING(lp_hosts_equiv,&Globals.szHostsEquiv)
@@ -1936,6 +1941,121 @@
add_char_string(pszParmValue);
return(True);
}
+
+/***************************************************************************
+run standard_sub_basic on netbios name... needed because global_myname
+is not accessed through any lp_ macro.
+***************************************************************************/
+
+static BOOL handle_netbios_name(char *pszParmValue,char **ptr)
+{
+ pstring netbios_name;
+
+ pstrcpy(netbios_name,pszParmValue);
+
+ standard_sub_basic(netbios_name);
+ strupper(netbios_name);
+ string_set(ptr,netbios_name);
+
+ pstrcpy(global_myname,netbios_name);
+
+ DEBUG(4,("handle_netbios_name: set global_myname to: %s\n", global_myname));
+
+ return(True);
+}
+
+/***************************************************************************
+do the work of sourcing in environment variable/value pairs
+***************************************************************************/
+static BOOL source_env(FILE *fenv)
+{
+ pstring line;
+ char *varval;
+ int len;
+ char *p;
+
+ while (!feof(fenv))
+ {
+ if (fgets(line, sizeof(line), fenv) == NULL)
+ break;
+
+ len=strlen(line);
+ if (line[len - 1] == '\n')
+ line[--len] = '\0';
+ if ((varval=malloc(len+1)) == NULL)
+ {
+ DEBUG(0,("source_env: Not enough memory!\n"));
+ return(False);
+ }
+
+ DEBUG(4,("source_env: Adding to environment: %s\n", line));
+ strncpy(varval, line, len);
+ varval[len] = '\0';
+ if (putenv(varval))
+ return(False);
+
+ p=strchr(line, (int) '=');
+ if (p == NULL)
+ {
+ DEBUG(4,("source_env: OOPS: %s\n", line));
+ continue;
+ }
+
+ *p='\0';p++;
+ DEBUG(4,("source_env: var %s = %s\n", line, getenv(line)));
+ }
+
+ DEBUG(4,("source_env: returning successfully\n"));
+ return(True);
+}
+
+
+/***************************************************************************
+handle the source environment operation
+***************************************************************************/
+static BOOL handle_source_env(char *pszParmValue,char **ptr)
+{
+ pstring fname;
+ FILE *env;
+ BOOL result;
+ int pexit;
+
+ pstrcpy(fname,pszParmValue);
+
+ standard_sub_basic(fname);
+
+ string_set(ptr,pszParmValue);
+
+ DEBUG(4, ("handle_source_env: checking env type\n"));
+
+ if (fname[strlen(fname) - 1] == '|')
+ {
+ DEBUG(4, ("handle_source_env: source env from pipe\n"));
+ fname[strlen(fname) - 1]='\0';
+ DEBUG(4, ("handle_source_env: opening pipe\n"));
+ if ((env=popen(fname, "r")) == NULL)
+ return(False);
+ DEBUG(4, ("handle_source_env: calling source_env()\n"));
+ result=source_env(env);
+ pexit=pclose(env);
+ }
+ else
+ {
+ DEBUG(4, ("handle_source_env: source env from file\n"));
+ /*add_to_file_list(fname);*/
+ if (file_exist(fname,NULL))
+ {
+ DEBUG(4, ("handle_source_env: opening env file %s\n", fname));
+ if ((env=fopen(fname, "r")) == NULL)
+ return(False);
+ DEBUG(4, ("handle_source_env: calling source_env()\n"));
+ result=source_env(env);
+ fclose(env);
+ }
+ }
+ return(result);
+}
+
/***************************************************************************
handle the include operation
-------------- next part --------------
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission. If
verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.
More information about the samba
mailing list