Adding a feature to the smbd
Thomas Langås
tlan at stud.ntnu.no
Sat Jan 20 23:16:25 GMT 2001
Richard Sharpe:
> >Don't mind my last posting :) I found the part I think you're refering too,
> >it was called sys_popen(); I've included that now... Should I send the
> >diff-file to the list?
> Please do ... And a short description of what it is intended for, including
> examples if you can ... It may be that there is an existing mechanism that
> can do the job.
Ok, this whole thing started when we decided to transfer our
Windows-profiles for each users from profile-server to our samba-servers.
Since we have a lot of computer labs, and a lot of them have different
programs installed, you can't have the same profile in each lab. So, it was
one of two things, either have different profile-shares for each lab, or
have one share and let samba do the job selecting which path you should get
as your profile-dir. This was when I decided to create a feature I called
"enhanced path=", it's an option in the shares-config. Instead of sending
"path=" you set "enhanced path=". The value in "enhanced path=" is a
program/shell-script that sends a line of text to stdout, smbd then reads
this output and uses this output as the "path=" string (it set's the
.szPath-string, actually). I'm using standard_sub_basic on the value passed
with "enhanced path=" so that you can use %I, %M, etc. to achieve the wanted
dynamic configuration. I asked on the reg. samba list before doing this
patch, and no one seemed to think of a solution that could do this with
todays options.
--
-Thomas
-------------- next part --------------
495d494
< static BOOL handle_enhanced_path(char *pszParmValue,char **ptr);
562d560
< {"enhanced path", P_STRING, P_LOCAL, &sDefault.szPath, handle_enhanced_path, NULL, FLAG_BASIC|FLAG_SHARE|FLAG_PRINT|FLAG_DOS_STRING},
1338,1339d1335
< //Don't know is this one is needed...
< FN_LOCAL_STRING(lp_enhanced_pathname,szPath)
1938,1983d1933
<
< /***************************************************************************
< This routine allows you to define a shell-script/program that returns a
< string. This string will then be the path used.
< pszParmValue - Contains the command
< ptr - Points to szPath
< This routine is done by Thomas Lang?s (tlan at stud.ntnu.no)
< ***************************************************************************/
< static BOOL handle_enhanced_path(char *pszParmValue,char **ptr)
< {
< pstring output, cmd;
< FILE *mypipe;
< int retvalue,i;
<
< retvalue = 0;
<
< pstrcpy(cmd, pszParmValue);
< standard_sub_basic(cmd);
<
< //sys_popen is a safe-wrapper around popen...
< if ((mypipe = sys_popen(cmd, "r", True)) != NULL) {
< if (fgets(output, sizeof(output), mypipe) != NULL) {
< retvalue = pclose(mypipe);
< } else {
< //Just ditch the rest of the output
< while (fgets(cmd, sizeof(cmd), mypipe) != NULL) {}
< retvalue = pclose(mypipe);
< }
<
< if (retvalue != 0)
< DEBUG(0, ("handle_enhanced_path: Command exited with value %d, it echoed \047%s\047", retvalue, output));
<
< for (i=0;i<strlen(output);i++)
< if (output[i] == '\n')
< output[i] = '\0';
<
< unix_to_dos(output, True);
<
< string_set(ptr, (char *) &output[0]);
< return(True);
< } else { //Error
< DEBUG(0, ("handle_enhanced_path: Failed trying to open \047%s\047 as pipe\n", pszParmValue));
< return(True);
< }
< }
<
More information about the samba-technical
mailing list