1<HTML> 2<HEAD> 3<TITLE> 4[Chapter 6] 6.6 Logon Scripts</title><META NAME="DC.title" CONTENT=""><META NAME="DC.creator" CONTENT=""><META NAME="DC.publisher" CONTENT="O'Reilly & Associates, Inc."><META NAME="DC.date" CONTENT="1999-11-05T21:34:19Z"><META NAME="DC.type" CONTENT="Text.Monograph"><META NAME="DC.format" CONTENT="text/html" SCHEME="MIME"><META NAME="DC.source" CONTENT="" SCHEME="ISBN"><META NAME="DC.language" CONTENT="en-US"><META NAME="generator" CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"></head> 5<BODY BGCOLOR="#FFFFFF" TEXT="#000000" link="#990000" vlink="#0000CC"> 6<table BORDER="0" CELLPADDING="0" CELLSPACING="0" width="90%"> 7<tr> 8<td width="25%" valign="TOP"> 9<img hspace=10 vspace=10 src="gifs/samba.s.gif" 10alt="Using Samba" align=left valign=top border=0> 11</td> 12<td height="105" valign="TOP"> 13<br> 14<H2>Using Samba</H2> 15<font size="-1"> 16Robert Eckstein, David Collier-Brown, Peter Kelly 17<br>1st Edition November 1999 18<br>1-56592-449-5, Order Number: 4495 19<br>416 pages, $34.95 20</font> 21<p> <a href="http://www.oreilly.com/catalog/samba/">Buy the hardcopy</a> 22<p><a href="index.html">Table of Contents</a> 23</td> 24</tr> 25</table> 26<hr size=1 noshade> 27<!--sample chapter begins --> 28 29<center> 30<DIV CLASS="htmlnav"> 31<TABLE WIDTH="515" BORDER="0" CELLSPACING="0" CELLPADDING="0"> 32<TR> 33<TD ALIGN="LEFT" VALIGN="TOP" WIDTH="172"> 34<A CLASS="sect1" HREF="ch06_05.html" TITLE="6.5 Windows Domains"> 35<IMG SRC="gifs/txtpreva.gif" ALT="Previous: 6.5 Windows Domains" BORDER="0"></a></td><TD ALIGN="CENTER" VALIGN="TOP" WIDTH="171"> 36<B> 37<FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1"> 38<A CLASS="chapter" REL="up" HREF="ch06_01.html" TITLE="6. Users, Security, and Domains "> 39Chapter 6<br> 40Users, Security, and Domains </a></font></b></td><TD ALIGN="RIGHT" VALIGN="TOP" WIDTH="172"> 41<A CLASS="chapter" HREF="ch07_01.html" TITLE="7. Printing and Name Resolution"> 42<IMG SRC="gifs/txtnexta.gif" ALT="Next: 7. Printing and Name Resolution" BORDER="0"></a></td></tr></table> <hr noshade size=1></center> 43</div> 44<blockquote> 45<div> 46<H2 CLASS="sect1"> 47<A CLASS="title" NAME="ch06-38153"> 486.6 Logon Scripts</a></h2><P CLASS="para">Samba supports the execution of Windows logon scripts, which are scripts (.BAT or .CMD) that are executed on the client when a user logs on to a Windows domain. Note that these scripts are stored on the Unix side, but are transported across the network to the client side and executed once a user logs on. These scripts are invaluable for dynamically setting up network configurations for users when they log on. The downside is that because they run on Windows, they must use the Windows network configuration commands.</p><P CLASS="para"> 49If you would like more information on NET commands, we recommend the following O'Reilly handbooks: <EM CLASS="emphasis"> 50Windows NT in a Nutshell</em>, <EM CLASS="emphasis"> 51Windows 95 in a Nutshell</em>, and <EM CLASS="emphasis"> 52Windows 98 in a Nutshell.</em></p><P CLASS="para"> 53You can instruct Samba to use a logon script with the <CODE CLASS="literal"> 54logon</code> <CODE CLASS="literal"> 55script</code> option, as follows:</p><PRE CLASS="programlisting"> 56[global] 57 domain logons = yes 58 security = user 59 workgroup = SIMPLE 60 61 os level = 34 62 local master = yes 63 preferred master = yes 64 domain master = yes 65 logon script = %U.bat 66 67[netlogon] 68 comment = The domain logon service 69 path = /export/samba/logon 70 public = no 71 writeable = no 72 browsable = no</pre><P CLASS="para"> 73Note that this example uses the <CODE CLASS="literal"> 74%U</code> variable, which will individualize the script based on the user that is logging in. It is common to customize logon scripts based on the user or machine name that is logging onto the domain. These scripts can then be used to configure individual settings for users or clients.</p><P CLASS="para"> 75Each logon script should be stored at the base of the <CODE CLASS="literal"> 76[netlogon]</code> share. For example, if the base of the <CODE CLASS="literal"> 77[netlogon]</code> share is <I CLASS="filename"> 78/export/samba/logon</i> and the logon script is <I CLASS="filename"> 79jeff.bat</i>, the file should be located at <I CLASS="filename"> 80/export/samba/logon/jeff.bat</i>. When a user logs on to a domain that contains a startup script, he or she will see a small dialog that informs them that the script is executing, as well as any output the script generates in an MS-DOS-like box.</p><P CLASS="para"> 81One warning: because these scripts are loaded by Windows and executed on the Windows side, they must consist of DOS formatted carriage-return/linefeed characters instead of Unix carriage returns. It's best to use a DOS- or Windows-based editor to create them.</p><P CLASS="para"> 82Here is an example of a logon script that sets the current time to match that of the Samba server and maps two network drives, <CODE CLASS="literal"> 83h</code> and <CODE CLASS="literal"> 84i</code>, to individual shares on the server:</p><PRE CLASS="programlisting"> 85# Reset the current time to that shown by the server. 86# We must have the "time server = yes" option in the 87# smb.conf for this to work. 88 89echo Setting Current Time... 90net time \\hydra /set /yes 91 92# Here we map network drives to shares on the Samba 93# server 94echo Mapping Network Drives to Samba Server Hydra... 95net use h: \\hydra\data 96net use i: \\hydra\network</pre><DIV CLASS="sect2"> 97<H3 CLASS="sect2"> 98<A CLASS="title" NAME="ch06-pgfId-960385"> 996.6.1 Roaming profiles</a></h3><P CLASS="para"> 100<I CLASS="firstterm"> 101</i>In Windows 95 and NT, each user can have his or her own <I CLASS="firstterm"> 102profile</i>. A profile bundles information such as: the appearance of a user's desktop, the applications that appear on the start menus, the background, and other miscellaneous items. If the profile is stored on a local disk, it's called a <I CLASS="firstterm"> 103local profile</i>, since it describes what a user's environment is like on one machine. If the profile is stored on a server, on the other hand, the user can download the same profile to any client machine that is connected to the server. The latter is called a <I CLASS="firstterm"> 104roaming profile</i> because the user can roam around from machine to machine and still use the same profile. This makes it particularly convenient when someone might be logging in from his or her desk one day and from a portable in the field the next. <A CLASS="xref" HREF="ch06_06.html#ch06-71393"> 105Figure 6.6</a> illustrates local and roaming profiles. </p><H4 CLASS="figure"> 106<A CLASS="title" NAME="ch06-71393"> 107Figure 6.6: Local profiles versus roaming profiles</a></h4><IMG CLASS="graphic" SRC="figs/sam.0606.gif" ALT="Figure 6.6"><P CLASS="para"> 108 109 110<!-- 2.0.7 amendment begins, davecb --> 111<P>Samba will provide roaming profiles if it is configured for domain logons 112and you set <CODE CLASS="literal">logon path</CODE> to the user's home 113directory and <CODE CLASS="literal">logon home </CODE> to a 114subdirectory of the user's home directory used to store profiles. These 115options are typically used with one of the user variables, as shown in this 116example: 117<PRE CLASS="programlisting"> 118[global] 119 domain logons = yes 120 security = user 121 workgroup = SIMPLE 122 os level = 34 123 local master = yes 124 preferred master = yes 125 domain master = yes 126 127 logon home = \\%N\%U 128 logon path = \\%N\%U\profile <!-- from the man page --> 129</PRE> 130<P> Samba versions previous to 2.0.6 allowed Win9X machines to store 131profiles in separate shares, but that prevented the clients from setting 132their <CODE CLASS="literal">logon path</CODE> so they could get their home 133directory mounted by saying "net use /home". This was corrected in 1342.0.6.</P> 135 136<!-- end of profiles modification --> 137<!-- WARNING: we never warn anywhere that "Windows clients can sometimes 138maintain a connection to the [homes] share, even though there is 139no user logged in. Therefore, it is vital that the logon path does not 140include a reference to the homes share." I read the above as being 141equivalen to the homes share, just not leiterally [homes]. I expect 142the bug will persist. davecb--> 143 144 145Once a user initially logs on, the Windows client will create a <I CLASS="filename"> 146user.dat</i> or <I CLASS="filename"> 147ntuser.dat</i> file - depending on which operating system the client is running. The client then uploads the contents of the desktop, the Start Menu, the Network Neighborhood, and the programs folders in individual folders in the directory. When the user subsequently logs on, those contents will be downloaded from the server and activated for the client machine with which the user is logging on. When he or she logs off, those contents will be uploaded back on the server until the next time the user connects. If you look at the directory listing of a profile folder, you'll see the following:</p><PRE CLASS="programlisting"> 148# ls -al 149 150total 321 151drwxrwxr-x 9 root simple Jul 21 20:44 . 152drwxrwxr-x 4 root simple Jul 22 14:32 .. 153drwxrwx--- 3 fred develope Jul 12 07:15 Application Data 154drwxrwx--- 3 fred develope Jul 12 07:15 Start Menu 155drwxrwx--- 2 fred develope Jul 12 07:15 cookies 156drwxrwx--- 2 fred develope Jul 12 07:15 desktop 157drwxrwx--- 7 fred develope Jul 12 07:15 history 158drwxrwx--- 2 fred develope Jul 12 07:15 nethood 159drwxrwx--- 2 fred develope Jul 19 21:05 recent 160-rw------- 1 fred develope Jul 21 21:59 user.dat</pre><P CLASS="para"> 161The <I CLASS="filename"> 162user.dat</i> files are binary configuration files, created automatically by Windows. They can be edited with the Profile Editor on a Windows client, but they can be somewhat tricky to get correct. Samba supports them correctly for all clients up to NT 5.0 beta, but they're still relatively new<I CLASS="firstterm"></i>.</p><P CLASS="para"> 163Hints and HOWTOs for handling logon scripts are available in the Samba documentation tree, in both <I CLASS="filename"> 164docs/textdocs/DOMAIN.txt</i> and <I CLASS="filename"> 165docs/textdocs/PROFILES.txt</i>.<I CLASS="firstterm"> 166</i> </p></div><DIV CLASS="sect2"> 167<H3 CLASS="sect2"> 168<A CLASS="title" NAME="ch06-pgfId-961462"> 1696.6.2 Mandatory profiles</a></h3><P CLASS="para">Users can also have <I CLASS="firstterm"> 170mandatory profiles</i>, which are roaming profiles that they cannot change. For example, with a mandatory profile, if a user adds a command to the Start Menu on Tuesday, it will be gone when he or she logs in again on Wednesday. The mandatory profile is simply a <I CLASS="filename"> 171user.dat</i> file that has been renamed to <I CLASS="filename"> 172user.man</i> and made read-only on the Unix server. It normally contains settings that the administrator wishes to ensure the user always executes. For example, if an administrator wants to create a fixed user configuration, he or she can do the following:</p><OL CLASS="orderedlist"> 173<LI CLASS="listitem"> 174<P CLASS="para"> 175<A CLASS="listitem" NAME="ch06-pgfId-957763"> 176</a>Create the read-write directory on the Samba server. </p></li><LI CLASS="listitem"> 177<P CLASS="para"> 178<A CLASS="listitem" NAME="ch06-pgfId-957764"> 179</a>Set the <CODE CLASS="literal"> 180logon</code> <CODE CLASS="literal"> 181path</code> option in the <EM CLASS="emphasis"> 182smb.conf</em> file to point to this directory.</p></li><LI CLASS="listitem"> 183<P CLASS="para"> 184<A CLASS="listitem" NAME="ch06-pgfId-957765"> 185</a>Logon as the user from Windows 95/98 to have the client populate the directory. </p></li><LI CLASS="listitem"> 186<P CLASS="para"> 187<A CLASS="listitem" NAME="ch06-pgfId-957766"> 188</a>Rename the resulting <I CLASS="filename"> 189user.dat</i> to <I CLASS="filename"> 190user.man</i>.</p></li><LI CLASS="listitem"> 191<P CLASS="para"> 192<A CLASS="listitem" NAME="ch06-pgfId-957767"> 193</a>Make the directory and its contents read only.</p></li></ol><P CLASS="para"> 194Mandatory profiles are fairly unusual. Roaming profiles, on the other hand, are one of the more desirable features of Windows that Samba can support.</p></div><DIV CLASS="sect2"> 195<H3 CLASS="sect2"> 196<A CLASS="title" NAME="ch06-pgfId-962637"> 1976.6.3 Logon Script Options</a></h3><P CLASS="para"> 198<A CLASS="xref" HREF="ch06_06.html#ch06-46661">Table 6.10</a> summarizes the options commonly used in association with Windows domain logon scripts. </p><br> 199<TABLE CLASS="table" BORDER="1" CELLPADDING="3"> 200<CAPTION CLASS="table"> 201<A CLASS="title" NAME="ch06-46661"> 202Table 6.10: Logon Script Options </a></caption><THEAD CLASS="thead"> 203<TR CLASS="row" VALIGN="TOP"> 204<TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 205<P CLASS="para"> 206Option</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 207<P CLASS="para"> 208Parameters</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 209<P CLASS="para"> 210Function</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 211<P CLASS="para"> 212Default</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 213<P CLASS="para"> 214Scope</p></th></tr></thead><TBODY CLASS="tbody"> 215<TR CLASS="row" VALIGN="TOP"> 216<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 217<P CLASS="para"> 218<CODE CLASS="literal"> 219logon script</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 220<P CLASS="para"> 221string (DOS path)</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 222<P CLASS="para"> 223Name of DOS/NT batch file</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 224<P CLASS="para"> 225None</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 226<P CLASS="para"> 227Global</p></td></tr><TR CLASS="row" VALIGN="TOP"> 228<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 229<P CLASS="para"> 230<CODE CLASS="literal"> 231logon path</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 232<P CLASS="para"> 233string (UNC server and share name)</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 234<P CLASS="para"> 235Location of roaming profile for user</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 236<P CLASS="para"> 237<CODE CLASS="literal"> 238\\%N\%U\profile</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 239<P CLASS="para"> 240Global</p></td></tr><TR CLASS="row" VALIGN="TOP"> 241<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 242<P CLASS="para"> 243<CODE CLASS="literal"> 244logon drive</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 245<P CLASS="para"> 246string (drive letter)</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 247<P CLASS="para"> 248Specifies the logon drive for a home directory (NT only)</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 249<P CLASS="para"> 250<CODE CLASS="literal"> 251Z</code>:</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 252<P CLASS="para"> 253Global</p></td></tr><TR CLASS="row" VALIGN="TOP"> 254<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 255<P CLASS="para"> 256<CODE CLASS="literal"> 257logon home</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 258<P CLASS="para"> 259string (UNC server and share name)</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 260<P CLASS="para"> 261Specifies a location for home directories for clients logging on to the domain</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 262<P CLASS="para"> 263<CODE CLASS="literal"> 264\\%N\%U</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 265<P CLASS="para"> 266Global</p></td></tr></tbody></table><DIV CLASS="sect3"> 267<H4 CLASS="sect3"> 268<A CLASS="title" NAME="ch06-pgfId-962334"> 2696.6.3.1 logon script</a></h4><P CLASS="para"> 270This option specifies a Windows .BAT or .CMD file with lines ending in carriage-return/line feed that will be executed on the client after a user has logged on to the domain. Each logon script should be stored at the base of a share entitled <CODE CLASS="literal"> 271[netlogin]</code> (see the section <A CLASS="xref" HREF="ch06_05.html#ch06-36822"> 272Section 6.5.1</a> for details.) This option frequently uses the <CODE CLASS="literal"> 273%U</code> or <CODE CLASS="literal"> 274%m</code> variables (user or NetBIOS name) to point to an individual script. For example:</p><PRE CLASS="programlisting"> 275logon script = %U.bat</pre><P CLASS="para"> 276will execute a script based on the username located at the base of the <CODE CLASS="literal"> 277[netlogin]</code> share. If the user who is connecting is <CODE CLASS="literal"> 278fred</code> and the path of the <CODE CLASS="literal"> 279[netlogin]</code> share maps to the directory <I CLASS="filename"> 280/export/samba/netlogin</i>, the script should be <I CLASS="filename"> 281/export/samba/netlogin/fred.bat</i>. Because these scripts are downloaded to the client and executed on the Windows side, they must consist of DOS formatted carriage-return/linefeed characters instead of Unix carriage returns.</p></div><DIV CLASS="sect3"> 282<H4 CLASS="sect3"> 283<A CLASS="title" NAME="ch06-pgfId-962671"> 2846.6.3.2 logon path</a></h4><P CLASS="para"> 285This option provides a location for roaming profiles. When the user logs on, a roaming profile will be downloaded from the server to the client and activated for the user who is logging on. When the user logs off, those contents will be uploaded back on the server until the next time the user connects. </p><P CLASS="para"> 286It is often more secure to create a separate share exclusively for storing user profiles:</p><PRE CLASS="programlisting"> 287logon path = \\hydra\profile\%U</pre><P CLASS="para"> 288For more informaiton on this option, see the section <A CLASS="xref" HREF="ch06_06.html"> 289Section 6.6, Logon Scripts</a>, earlier in this chapter.</p></div><DIV CLASS="sect3"> 290<H4 CLASS="sect3"> 291<A CLASS="title" NAME="ch06-pgfId-962332"> 2926.6.3.3 logon drive</a></h4><P CLASS="para"> 293This option specifies the drive letter on an NT client to which the home directory specified with the <CODE CLASS="literal"> 294logon</code> <CODE CLASS="literal"> 295home</code> option will be mapped. Note that this option will work with Windows NT clients only. For example:</p><PRE CLASS="programlisting"> 296logon home = I:</pre><P CLASS="para"> 297You should always use drive letters that will not conflict with fixed drives on the client machine. The default is Z:, which is a good choice because it is as far away from A:, C:, and D: as possible.</p></div><DIV CLASS="sect3"> 298<H4 CLASS="sect3"> 299<A CLASS="title" NAME="ch06-pgfId-962319"> 3006.6.3.4 logon home </a></h4><P CLASS="para"> 301This option specifies the location of a user's home directory for use by the DOS NET commands. For example, to specify a home directory as a share on a Samba server, use the following:</p><PRE CLASS="programlisting"> 302logon home = \\hydra\%U</pre><P CLASS="para"> 303Note that this works nicely with the <CODE CLASS="literal"> 304[homes]</code> service, although you can specify any directory you wish. Home directories can be mapped with a logon script using the following command:</p><PRE CLASS="programlisting"> 305NET USE I: /HOME</pre><P CLASS="para"> 306In addition, you can use the User Environment Profile under User Properties in the Windows NT User Manager to verify that the home directory has automatically been set. </p></div></div><DIV CLASS="sect2"> 307<H3 CLASS="sect2"> 308<A CLASS="title" NAME="ch06-pgfId-960476"> 3096.6.4 Other Connection Scripts</a></h3><P CLASS="para">After a user successfully makes a connection to any Samba share, you may want the Samba server to execute a program on its side to prepare the share for use. Samba allows scripts to be executed before and after someone connects to a share. You do not need to be using Windows domains to take advantage of the options. <A CLASS="xref" HREF="ch06_06.html#ch06-67528"> 310Table 6.11</a> introduces some of the configuration options provided for setting up users. </p><br> 311<TABLE CLASS="table" BORDER="1" CELLPADDING="3"> 312<CAPTION CLASS="table"> 313<A CLASS="title" NAME="ch06-67528"> 314Table 6.11: Connection Script Options </a></caption><THEAD CLASS="thead"> 315<TR CLASS="row" VALIGN="TOP"> 316<TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 317<P CLASS="para"> 318Option</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 319<P CLASS="para"> 320Parameters</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 321<P CLASS="para"> 322Function</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 323<P CLASS="para"> 324Default</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 325<P CLASS="para"> 326Scope</p></th></tr></thead><TBODY CLASS="tbody"> 327<TR CLASS="row" VALIGN="TOP"> 328<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 329<P CLASS="para"> 330<CODE CLASS="literal"> 331root preexec</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 332<P CLASS="para"> 333string (Unix command)</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 334<P CLASS="para"> 335Sets a command to run as <CODE CLASS="literal"> 336root</code>, before connecting to the share.</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 337<P CLASS="para"> 338None</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 339<P CLASS="para"> 340Share</p></td></tr><TR CLASS="row" VALIGN="TOP"> 341<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 342<P CLASS="para"> 343<CODE CLASS="literal"> 344preexec (exec)</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 345<P CLASS="para"> 346string (Unix command)</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 347<P CLASS="para"> 348Sets a Unix command to run as the user before connecting to the share.</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 349<P CLASS="para"> 350None</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 351<P CLASS="para"> 352Share</p></td></tr><TR CLASS="row" VALIGN="TOP"> 353<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 354<P CLASS="para"> 355<CODE CLASS="literal"> 356postexec</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 357<P CLASS="para"> 358string (Unix command)</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 359<P CLASS="para"> 360Sets a Unix command to run as the user after disconnecting from the share.</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 361<P CLASS="para"> 362None</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 363<P CLASS="para"> 364Share</p></td></tr><TR CLASS="row" VALIGN="TOP"> 365<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 366<P CLASS="para"> 367<CODE CLASS="literal"> 368root postexec</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 369<P CLASS="para"> 370string (Unix command)</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 371<P CLASS="para"> 372Sets a Unix command to run as <CODE CLASS="literal"> 373root</code> after disconnecting from the share.</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 374<P CLASS="para"> 375None</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 376<P CLASS="para"> 377Share</p></td></tr></tbody></table><DIV CLASS="sect3"> 378<H4 CLASS="sect3"> 379<A CLASS="title" NAME="ch06-pgfId-960575"> 3806.6.4.1 root preexec</a></h4><P CLASS="para"> 381The first form of the logon command is called <CODE CLASS="literal"> 382root</code> <CODE CLASS="literal"> 383preexec</code>. This option specifies a Unix command as its value that will be run <EM CLASS="emphasis"> 384as the root user</em> before any connection to a share is completed. You should use this option specifically for performing actions that require root privilege. For example, <CODE CLASS="literal"> 385root</code> <CODE CLASS="literal"> 386preexec</code> can be used to mount CD-ROMs for a share that makes them available to the clients, or to create necessary directories. If no <CODE CLASS="literal"> 387root</code> <CODE CLASS="literal"> 388preexec</code> option is specified, there is no default action. Here is an example of how you can use the command to mount a CD-ROM:</p><PRE CLASS="programlisting"> 389[homes] 390 browseable = no 391 writeable = yes 392 root preexec = /etc/mount /dev/cdrom2</pre><P CLASS="para"> 393Remember that these commands will be run as the root user. Therefore, in order to ensure security, users should never be able to modify the target of the <CODE CLASS="literal"> 394root</code> <CODE CLASS="literal"> 395preexec</code> command.</p></div><DIV CLASS="sect3"> 396<H4 CLASS="sect3"> 397<A CLASS="title" NAME="ch06-pgfId-960582"> 3986.6.4.2 preexec</a></h4><P CLASS="para"> 399The next option run before logon is the <CODE CLASS="literal"> 400preexec</code> option, sometimes just called <CODE CLASS="literal"> 401exec</code>. This is an ordinary unprivileged command run by Samba as the user specified by the variable <CODE CLASS="literal"> 402%u</code>. For example, a common use of this option is to perform logging, such as the following:</p><PRE CLASS="programlisting"> 403[homes] 404<CODE CLASS="userinput"><B>preexec = echo "%u connected to %S from %m (%I)\" >>/tmp/.log</b></code> </pre><P CLASS="para"> 405Be warned that any information the command sends to standard output will not be seen by the user, but is instead thrown away. If you intend to use a <CODE CLASS="literal"> 406preexec</code> script, you should ensure that it will run correctly before having Samba invoke it.</p></div><DIV CLASS="sect3"> 407<H4 CLASS="sect3"> 408<A CLASS="title" NAME="ch06-pgfId-960594"> 4096.6.4.3 postexec</a></h4><P CLASS="para"> 410Once the user disconnects from the share, the command specified with <CODE CLASS="literal"> 411postexec</code> is run as the user on the Samba server to do any necessary cleanup. This option is essentially the same as the <CODE CLASS="literal"> 412preexec</code> option. Again, remember that the command is run as the user represented by <CODE CLASS="literal"> 413%u</code> and any information sent to standard output will be ignored.</p></div><DIV CLASS="sect3"> 414<H4 CLASS="sect3"> 415<A CLASS="title" NAME="ch06-pgfId-960596"> 4166.6.4.4 root postexec</a></h4><P CLASS="para"> 417Following the <CODE CLASS="literal"> 418postexec</code> option, the <CODE CLASS="literal"> 419root</code> <CODE CLASS="literal"> 420postexec</code> command is run, if one has been specified. Again, this option specifies a Unix command as its value that will be run <EM CLASS="emphasis"> 421as the </em><EM CLASS="emphasis">root user</em> before disconnecting from a share. You should use this option specifically for performing actions that require root privilege.</p></div></div><DIV CLASS="sect2"> 422<H3 CLASS="sect2"> 423<A CLASS="title" NAME="ch06-pgfId-960610"> 4246.6.5 Working with NIS and NFS</a></h3><P CLASS="para"> 425Finally, Samba has the ability to work with NIS and NIS+. If there is more than one file server, and each runs Samba, it may be desirable to have the SMB client connect to the server whose disks actually house the user's home directory. It isn't normally a good idea to ship files across the network once via NFS to a Samba server, only to be sent across the network once again to the client via SMB. (For one thing, it's slow - about 30 percent of normal Samba speed). Therefore, there are a pair of options to tell Samba that NIS knows the name of the right server and indicate in which NIS map the information lives.</p><P CLASS="para"> 426<A CLASS="xref" HREF="ch06_06.html#ch06-27466"> 427Table 6.12</a> introduces some of the other configuration options specifically for setting up users. </p><br> 428<TABLE CLASS="table" BORDER="1" CELLPADDING="3"> 429<CAPTION CLASS="table"> 430<A CLASS="title" NAME="ch06-27466"> 431Table 6.12: NIS Options </a></caption><THEAD CLASS="thead"> 432<TR CLASS="row" VALIGN="TOP"> 433<TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 434<P CLASS="para"> 435Option</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 436<P CLASS="para"> 437Parameters</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 438<P CLASS="para"> 439Function</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 440<P CLASS="para"> 441Default</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 442<P CLASS="para"> 443Scope</p></th></tr></thead><TBODY CLASS="tbody"> 444<TR CLASS="row" VALIGN="TOP"> 445<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 446<P CLASS="para"> 447<CODE CLASS="literal"> 448nis homedir</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 449<P CLASS="para"> 450boolean</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 451<P CLASS="para"> 452If <CODE CLASS="literal"> 453yes</code>, use NIS instead of <I CLASS="filename"> 454/etc/passwd</i> to look up the path of a user's home directory</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 455<P CLASS="para"> 456<CODE CLASS="literal"> 457no</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 458<P CLASS="para"> 459Global</p></td></tr><TR CLASS="row" VALIGN="TOP"> 460<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 461<P CLASS="para"> 462<CODE CLASS="literal"> 463homedir map</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 464<P CLASS="para"> 465string (NIS map name)</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 466<P CLASS="para"> 467Sets the NIS map to use to look up a user's home directory</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 468<P CLASS="para"> 469None</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 470<P CLASS="para"> 471Global</p></td></tr></tbody></table><DIV CLASS="sect3"> 472<H4 CLASS="sect3"> 473<A CLASS="title" NAME="ch06-pgfId-960612"> 4746.6.5.1 nis homedir and homedir map</a></h4><P CLASS="para"> 475The <CODE CLASS="literal"> 476nis</code> <CODE CLASS="literal"> 477homedir</code> and <CODE CLASS="literal"> 478homedir</code> <CODE CLASS="literal"> 479map</code> options are for Samba servers on network sites where Unix home directories are provided using NFS, the automounter, and NIS (Yellow Pages).</p><P CLASS="para"> 480The <CODE CLASS="literal"> 481nis</code> <CODE CLASS="literal"> 482homedir</code> option indicates that the home directory server for the user needs to be looked up in NIS. The <CODE CLASS="literal"> 483homedir</code> <CODE CLASS="literal"> 484map</code> option tells Samba what NIS map to look in for the server that has the user's home directory. The server needs to be a Samba server, so the client can do an SMB connect to it, and the other Samba servers need to have NIS installed so they can do the lookup.</p><P CLASS="para"> 485For example, if user <CODE CLASS="literal"> 486joe</code> asks for a share called <CODE CLASS="literal"> 487[joe]</code>, and the <CODE CLASS="literal"> 488nis</code> <CODE CLASS="literal"> 489homedir</code> option is set to <CODE CLASS="literal"> 490yes</code>, Samba will look in the file specified by <CODE CLASS="literal"> 491homedir</code> <CODE CLASS="literal"> 492map</code> for a home directory for <CODE CLASS="literal"> 493joe</code>. If it finds one, Samba will return the associated machine name to the client. The client will then try to connect to <EM CLASS="emphasis"> 494that</em> machine and get the share from there. Enabling NIS lookups looks like the following:</p><PRE CLASS="programlisting"> 495[globals] 496 nis homedir = yes 497 homedir map = amd.map</pre></div></div></div></blockquote> 498<div> 499<center> 500<hr noshade size=1><TABLE WIDTH="515" BORDER="0" CELLSPACING="0" CELLPADDING="0"> 501<TR> 502<TD ALIGN="LEFT" VALIGN="TOP" WIDTH="172"> 503<A CLASS="sect1" HREF="ch06_05.html" TITLE="6.5 Windows Domains"> 504<IMG SRC="gifs/txtpreva.gif" ALT="Previous: 6.5 Windows Domains" BORDER="0"></a></td><TD ALIGN="CENTER" VALIGN="TOP" WIDTH="171"> 505<A CLASS="book" HREF="index.html" TITLE=""> 506<IMG SRC="gifs/txthome.gif" ALT="" BORDER="0"></a></td><TD ALIGN="RIGHT" VALIGN="TOP" WIDTH="172"> 507<A CLASS="chapter" HREF="ch07_01.html" TITLE="7. Printing and Name Resolution"> 508<IMG SRC="gifs/txtnexta.gif" ALT="Next: 7. Printing and Name Resolution" BORDER="0"></a></td></tr><TR> 509<TD ALIGN="LEFT" VALIGN="TOP" WIDTH="172"> 5106.5 Windows Domains</td><TD ALIGN="CENTER" VALIGN="TOP" WIDTH="171"> 511<A CLASS="index" HREF="inx.html" TITLE="Book Index"> 512<IMG SRC="gifs/index.gif" ALT="Book Index" BORDER="0"></a></td><TD ALIGN="RIGHT" VALIGN="TOP" WIDTH="172"> 5137. Printing and Name Resolution</td></tr></table><hr noshade size=1></center> 514</div> 515 516<!-- End of sample chapter --> 517<CENTER> 518<FONT SIZE="1" FACE="Verdana, Arial, Helvetica"> 519<A HREF="http://www.oreilly.com/"> 520<B>O'Reilly Home</B></A> <B> | </B> 521<A HREF="http://www.oreilly.com/sales/bookstores"> 522<B>O'Reilly Bookstores</B></A> <B> | </B> 523<A HREF="http://www.oreilly.com/order_new/"> 524<B>How to Order</B></A> <B> | </B> 525<A HREF="http://www.oreilly.com/oreilly/contact.html"> 526<B>O'Reilly Contacts<BR></B></A> 527<A HREF="http://www.oreilly.com/international/"> 528<B>International</B></A> <B> | </B> 529<A HREF="http://www.oreilly.com/oreilly/about.html"> 530<B>About O'Reilly</B></A> <B> | </B> 531<A HREF="http://www.oreilly.com/affiliates.html"> 532<B>Affiliated Companies</B></A><p> 533<EM>© 1999, O'Reilly & Associates, Inc.</EM> 534</FONT> 535</CENTER> 536</BODY> 537</html> 538