Section 6.6. Executing Server Scripts


6.6. Executing Server Scripts

This chapter concludes with a discussion of a small but widely useful set of parameters. The preexec and postexec options allow you to define a command to be executed on the server whenever a user connects or disconnects from a share. The preexec and postexec commands are executed in the user's own context, and the root preexec and root postexec variants are executed under the context of the root account.

Scripts can be specified with arguments to pass, which are the standard Samba % variables. You are limited only by your own imagination. Some clients might connect and disconnect to shares more often that you think, so it is best not to assume that a user will connect to a share only once per session.

For an example, we'll create a share for the server's anonymous FTP directory. This step allows a user to publish files via FTP without having to resort to using an FTP client. The root preexec command creates an individual folder for the user to upload files. The share definition appears as:

 [ftp]     path = /var/ftp/pub     read only = no     force create mode = 0004     force directory mode = 0005     root preexec = /etc/samba/scripts/mkftpdir.sh %u 

The contents of the mkftpdir.sh script are:

 #!/bin/bash if [ "x$1" == "x" ]; then     exit 1 fi if [ ! -d /var/ftp/pub/$1 ]; then     mkdir /var/ftp/pub/$1     chmod 755 /var/ftp/pub/$1     chown $1 /var/ftp/pub/$1 fi 

If desired, Samba can choose to honor or reject connections based on the return code from the preexec and root preexec commands. The preexec close (and root preexec close) can instruct smbd to evaluate the return code from the respective preexec command and reject the connection if the result is non-zero.

The pair of postexec commands are invoked when a user disconnects from a share. For example, when a user disconnects from a share containing removable media (such as a CD-ROM), the filesystem should be unmounted so that it can be removed. postexec commands are prime candidates for solving this category of problems.

Execution options are summarized in Table 6-13.

Table 6-13. Execution options

Parameter

Value

Description

Default

Scope

preexec

string

Specifies a command to be run under the context of the current user when connecting to the share.

""

Share

preexec close

boolean

Should smbd reject the share connection if the preexec command exits with a nonzero return code?

no

Share

postexec

string

Specifies a command to be run under the context of the current user when disconnecting from the share.

""

Share

root preexec

string

Specifies a command to be run under the context of the root user when connecting to the share.

""

Share

root preexec close

boolean

Should smbd reject the share connection if the root preexec command exits with a non-zero return code?

no

Share

root postexec

string

Specifies a command to be run under the context of the root user when disconnecting from the share.

""

Share





Using Samba
Using Samba: A File and Print Server for Linux, Unix & Mac OS X, 3rd Edition
ISBN: 0596007698
EAN: 2147483647
Year: 2004
Pages: 135

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net