diff options
Diffstat (limited to 'examples/scripts')
-rw-r--r-- | examples/scripts/debugging/linux/backtrace | 41 | ||||
-rw-r--r-- | examples/scripts/debugging/solaris/README | 28 | ||||
-rw-r--r-- | examples/scripts/debugging/solaris/solaris-oops.sh | 55 | ||||
-rw-r--r-- | examples/scripts/eventlog/parselog.pl | 32 | ||||
-rw-r--r-- | examples/scripts/mount/mount.smbfs | 115 | ||||
-rwxr-xr-x | examples/scripts/printing/cups/smbaddprinter.pl | 39 | ||||
-rwxr-xr-x | examples/scripts/printing/cups/smbdelprinter.pl | 25 | ||||
-rwxr-xr-x | examples/scripts/shares/perl/modify_samba_config.pl | 168 | ||||
-rw-r--r-- | examples/scripts/shares/python/SambaConfig.py | 314 | ||||
-rw-r--r-- | examples/scripts/shares/python/SambaParm.py | 83 | ||||
-rwxr-xr-x | examples/scripts/shares/python/generate_parm_table.py | 222 | ||||
-rwxr-xr-x | examples/scripts/shares/python/modify_samba_config.py | 77 | ||||
-rw-r--r-- | examples/scripts/shares/python/smbparm.py | 373 | ||||
-rwxr-xr-x | examples/scripts/users_and_groups/adduserstogroups.pl | 166 | ||||
-rwxr-xr-x | examples/scripts/users_and_groups/createdomobj.pl | 157 | ||||
-rw-r--r-- | examples/scripts/wins_hook/README | 8 | ||||
-rw-r--r-- | examples/scripts/wins_hook/dns_update | 94 |
17 files changed, 1997 insertions, 0 deletions
diff --git a/examples/scripts/debugging/linux/backtrace b/examples/scripts/debugging/linux/backtrace new file mode 100644 index 0000000000..2ea6a4d00a --- /dev/null +++ b/examples/scripts/debugging/linux/backtrace @@ -0,0 +1,41 @@ +#! /bin/sh +# +# Author: Andrew Tridgell <tridge at samba dot org> + +# we want everything on stderr, so the program is not disturbed +exec 1>&2 + +BASENAME=$( basename $0) + +test -z ${GDB_BIN} && GDB_BIN=$( type -p gdb) +if [ -z ${GDB_BIN} ]; then + echo "ERROR: ${BASENAME} needs an installed gdb. " + exit 1 +fi + +if [ -z $1 ]; then + echo "ERROR: ${BASENAME} needs a PID. " + exit 1 +fi +PID=$1 + +# use /dev/shm as default temp directory +test -d /dev/shm && \ + TMP_BASE_DIR=/dev/shm || \ + TMP_BASE_DIR=/var/tmp +TMPFILE=$( mktemp -p ${TMP_BASE_DIR} backtrace.XXXXXX) +if [ $? -ne 0 ]; then + echo "ERROR: ${basename} can't create temp file in ${TMP_BASE_DIR}. " + exit 1 +fi + +cat << EOF > "${TMPFILE}" +set height 0 +up 8 +bt full +quit +EOF + +${GDB_BIN} -x "${TMPFILE}" "/proc/${PID}/exe" "${PID}" + +/bin/rm -f "${TMPFILE}" diff --git a/examples/scripts/debugging/solaris/README b/examples/scripts/debugging/solaris/README new file mode 100644 index 0000000000..9e336805e5 --- /dev/null +++ b/examples/scripts/debugging/solaris/README @@ -0,0 +1,28 @@ +Last update: John H Terpstra - June 27, 2005 + +Subject: This directory will contain debugging tools and tips. + +Notes: Identification and confirmation of some bugs can be difficult. + When such bugs are encountered it is necessary to provide as + sufficient detailed debugging information to assist the developer + both by providing incontrivertable proof of the problem, but also + precise information regarding the values of variables being processed + at the time the problem strikes. + + This directory is the ideal place to locate useful hints, tips and + methods that will help Samba users to provide the information that + developers need. + +============================ Solaris Method A ============================== +File: solaris-oops.sh +Contributor: David Collier-Brown +Date: June 27, 2005 +Method and Use: +To the global stanza of smb.conf add: + panic action = /usr/local/bin/solaris-oops.sh %d + +When the panic action is initiated a voluntary core dump file will be placed +in /var/tmp. Use this method with "log level = 10" and an smbd binary that +has been built with the '-g' option. +============================================================================ + diff --git a/examples/scripts/debugging/solaris/solaris-oops.sh b/examples/scripts/debugging/solaris/solaris-oops.sh new file mode 100644 index 0000000000..82c49efdf6 --- /dev/null +++ b/examples/scripts/debugging/solaris/solaris-oops.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# +# solaris_panic_action -- capture supporting information after a failure +# +ProgName=`basename $0` +LOGDIR=/usr/local/samba/var + +main() { + pid=$1 + + if [ $# -lt 1 ]; then + say "$ProgName error: you must supply a pid" + say "Usage: $0 pid" + exit 1 + fi + cat >>$LOGDIR/log.solaris_panic_action <<! + +`date` +State information and vountary core dump for process $pid + +Related processes were: +`/usr/bin/ptree $pid` + +Stack(s) were: +`/usr/bin/pstack $pid` + +Flags were: +`/usr/bin/pflags $pid` + +Credentials were: +`/usr/bin/pcred $pid` + +Libraries used were: +`/usr/bin/pldd $pid` + +Signal-handler settings were: +`/usr/bin/psig $pid` + +Files and devices in use were: +`/usr/bin/pfiles $pid` + +Directory in use was: +`/usr/bin/pwdx $pid` + + +A voluntary core dump was placed in /var/tmp/samba_solaris_panic_action_gcore.$pid +`gcore -o /var/tmp/samba_solaris_panic_action_gcore $pid` +! +} + +say() { + echo "$@" 1>&2 +} + +main "$@" diff --git a/examples/scripts/eventlog/parselog.pl b/examples/scripts/eventlog/parselog.pl new file mode 100644 index 0000000000..0c21a94103 --- /dev/null +++ b/examples/scripts/eventlog/parselog.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl +###################################################################### +## +## Simple parselog script for Samba +## +## Copyright (C) Brian Moran 2005. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see <http://www.gnu.org/licenses/>. +## +###################################################################### + +## usage: tail -f /var/log/syslog | parselog.pl | eventlogadm "Application" + +while(<>) { + chomp(); + @le = split '\s+',$_,5; + $ln = $le[4]; + $cname = $le[3]; + $outstr = sprintf "TMG: %d\nTMW: %d\nEID: 1000\nETP: INFO\nECT: 0\nRS2: 0\nCRN: 0\nUSL: 0\nSRC: Syslog\nSRN: $cname\nSTR: $ln\nDAT:\n\n",time(),time(); + print $outstr; +} diff --git a/examples/scripts/mount/mount.smbfs b/examples/scripts/mount/mount.smbfs new file mode 100644 index 0000000000..3b57bc5141 --- /dev/null +++ b/examples/scripts/mount/mount.smbfs @@ -0,0 +1,115 @@ +#!/bin/bash +# Debian mount.smbfs compatibility wrapper +# Copyright 2007, Steve Langasek <vorlon at debian.org> +# Licensed under the GNU General Public License, version 2. See the +# file /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>. + +# This script accepts all documented mount options for mount.smbfs, +# passing through those that are also recognized by mount.cifs, +# converting those that are not recognized but map to available cifs +# options, and warning about the use of options for which no equivalent +# exists. + +# known bugs: quoted spaces in arguments are not passed intact + +set -e + +# reverse the order of username and password in a "username" parameter, +# taking care to leave any "%password" bit intact + +reverse_username_workgroup() { + local workgroup password username + + username="$1" + case "$username" in + *%*) password="${username#*%}" + username="${username%%%*}" + ;; + *) ;; + esac + case "$username" in + */*) workgroup="${username#*/}" + username="${username%%/*}" + ;; + *) ;; + esac + if [ -n "$workgroup" ]; then + username="$workgroup\\$username" + fi + if [ -n "$password" ]; then + username="$username%$password" + fi + echo "$username" +} + + +# parse out the mount options that have been specified using -o, and if +# necessary, convert them for use by mount.cifs + +parse_mount_options () { + local OLD_IFS IFS options option username + OLD_IFS="$IFS" + IFS="," + options="" + workgroup="" + password="" + + for option in $@; do + case "$option" in + sockopt=* | scope=* | codepage=* | ttl=* | debug=*) + echo "Warning: ignoring deprecated smbfs option '$option'" >&2 + ;; + + krb) + options="$options${options:+,}sec=krb5" + ;; + + guest) + echo "Warning: mapping 'guest' to 'guest,sec=none'" >&2 + options="$options${options:+,}guest,sec=none" + ;; + + # username and workgroup are reversed in username= arguments, + # so need to be parsed out + username=*/*) + IFS="$OLD_IFS" + username="${option#username=}" + username="$(reverse_username_workgroup "$username")" + IFS="," + options="$options${options:+,}username=$username" + ;; + + *) + options="$options${options:+,}$option" + ;; + esac + done + IFS="$OLD_IFS" + echo $options +} + +args=() +while [ "$#" -gt 0 ]; do + case "$1" in + -o*) + arg=${1#-o} + shift + if [ -z "$arg" ]; then + arg=$1 + shift + fi + arg="$(parse_mount_options "$arg")" + if [ -n "$arg" ]; then + args=("${args[@]}" "-o" "$arg") + fi + ;; + *) + args=("${args[@]}" "$1") + shift + ;; + esac +done + +USER="$(reverse_username_workgroup "$USER")" + +exec /sbin/mount.cifs "${args[@]}" diff --git a/examples/scripts/printing/cups/smbaddprinter.pl b/examples/scripts/printing/cups/smbaddprinter.pl new file mode 100755 index 0000000000..aee2020bfc --- /dev/null +++ b/examples/scripts/printing/cups/smbaddprinter.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl +## Add printer script for samba, APW, and cups +## Copyright (C) Jeff Hardy <hardyjm@potsdam.edu> 2004 +## +## This program is free software; you can redistribute it +## and/or modify it under the terms of the GNU General +## Public License as published by the Free Software Foundation; +## Either version 3 of the License, or (at your option) any +## later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public +## License along with this program; if not, see <http://www.gnu.org/licenses/>. + +@argv = @ARGV; + +# take in args +my $lpname=shift(@argv); # printer name +my $shname=shift(@argv); # share name -> used for CUPS queue name +my $portname=shift(@argv); # port name +my $drivername=shift(@argv); # driver name -> used for CUPS description +my $location=shift(@argv); # location -> used for CUPS device URI +my $win9x=shift(@argv); # win9x location + +#check for location syntax +#if no protocol specified... +if ($location !~ m#:/#){ + #assume an lpd printer + $location = "lpd://".$location; +} +#else, simply pass the URI on to the lpadmin command + +#run the cups lpadmin command to add the printer +system("/usr/sbin/lpadmin -p $shname -D \"$drivername\" -E -v $location"); + diff --git a/examples/scripts/printing/cups/smbdelprinter.pl b/examples/scripts/printing/cups/smbdelprinter.pl new file mode 100755 index 0000000000..23adeb719c --- /dev/null +++ b/examples/scripts/printing/cups/smbdelprinter.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl +## Delete printer script for samba, APW, and cups +## Copyright (C) Gerald (Jerry) Carter <jerry@samba.rog> 2004 +## +## This program is free software; you can redistribute it +## and/or modify it under the terms of the GNU General +## Public License as published by the Free Software Foundation; +## Either version 3 of the License, or (at your option) any +## later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public +## License along with this program; if not, see <http://www.gnu.org/licenses/>. + +@argv = @ARGV; + +# take in args +my $lpname=shift(@argv); # printer name + +system("/usr/sbin/lpadmin -x $lpname"); + diff --git a/examples/scripts/shares/perl/modify_samba_config.pl b/examples/scripts/shares/perl/modify_samba_config.pl new file mode 100755 index 0000000000..20b613aba8 --- /dev/null +++ b/examples/scripts/shares/perl/modify_samba_config.pl @@ -0,0 +1,168 @@ +#!/usr/bin/perl + +###################################################################### +## +## Simple add/delete/change share command script for Samba +## +## Copyright (C) Gerald Carter 2004. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see <http://www.gnu.org/licenses/>. +## +###################################################################### + +use POSIX qw(tmpnam); + +## +## local variables +## +my $delete_mode = undef; +my $add_mode = undef; +my $tmp_file_name = undef; + + +## check for correct parameters +if ($#ARGV == 1) { + $delete_mode = 1; +} +elsif ($#ARGV == 4) { + $add_mode = 1; +} +else { + print "Usage: $0 configfile share [path] [comment]\n"; + exit -1; +} + +## first param is always the config file +open (CONFIGFILE, "$ARGV[0]") || die "Unable to open $ARGV[0] for reading!\n"; + +## FIXME!! Right now we throw away all comments in the file. +while (<CONFIGFILE>) { + + chomp($_); + + ## eat leading whitespace + $_ =~ s/^\s*//; + + ## eat trailing whitespace + $_ =~ s/\s*$//; + + + ## throw away comments + next if (($_ =~ /^#/) || ($_ =~ /^;/)); + + ## set the current section name for storing the hash + if ($_ =~ /^\[.*\]$/) { + + $_ = substr($_, 1, length($_)-2); + + if ( length($_) ) { + $section = $_; + } + else { + print "Bad Section Name - no closing ]\n"; + exit -1; + } + + next; + } + + ## check for a param = value + if ($_ =~ /=/) { + ($param, $value) = split (/=/, $_,2); + $param =~ s/./\l$&/g; + $param =~ s/\s+//g; + $value =~ s/^\s+//; + + $config{$section}{$param} = $value; + + next; + } + + ## should have a hash of hashes indexed by section name +} +close (CONFIGFILE); + +## +## We have the smb.conf in our hash of hashes now. +## Add or delete +## +if ($add_mode) { + $config{$ARGV[1]}{'path'} = $ARGV[2]; + $config{$ARGV[1]}{'comment'} = $ARGV[3]; + $config{$ARGV[1]}{'max connections'} = $ARGV[4]; +} +elsif ($delete_mode) { + delete $config{$ARGV[1]}; +} + +## +## Print the resulting configuration +## +#do { +# $tmp_file_name = tmpnam(); +# print "Using temporary file - $tmp_file_name\n"; +#} while (!sysopen(TMP, $tmp_file_name, O_RDWR|O_CREAT|O_EXCL)); +$tmp_file_name = tmpnam(); +open (TMP, ">$tmp_file_name") || die "Unable to open temporary file for writing!\n"; + +PrintConfigFile(TMP); + +## now overwrite the original config file +close (TMP); +system ("cp -pf $ARGV[0] $ARGV[0].bak"); +system ("cp -pf $tmp_file_name $ARGV[0]"); +unlink $tmp_file_name; + + +exit 0; + + + + + +####################################################################################### +## PrintConfigFile() +## +sub PrintConfigFile { + my ($output) = @_; + + ## print the file back out, beginning with the global section + print $output "#\n# Generated by $0\n#\n"; + + PrintSection ($output, 'global', $config{'global'}); + + foreach $section (keys %config) { + + if ("$section" ne "global") { + print $output "## Section - [$section]\n"; + PrintSection ($output, $section, $config{$section}); + } + } + + print $output "#\n# end of generated smb.conf\n#\n"; +} + +####################################################################################### +## PrintSection() +## +sub PrintSection { + my ($outfile, $name, $section) = @_; + + print $outfile "[$name]\n"; + foreach $param (keys %$section) { + print $outfile "\t$param".' 'x(25-length($param)). " = $$section{$param}\n"; + } + print $outfile "\n"; + +} diff --git a/examples/scripts/shares/python/SambaConfig.py b/examples/scripts/shares/python/SambaConfig.py new file mode 100644 index 0000000000..3d4a47398c --- /dev/null +++ b/examples/scripts/shares/python/SambaConfig.py @@ -0,0 +1,314 @@ +import sys, string, SambaParm +from smbparm import parm_table + +###################################################################### +## +## smb.conf parser class +## +## Copyright (C) Gerald Carter 2004. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see <http://www.gnu.org/licenses/>. +## +###################################################################### + + +##################################################################### +## multi line Samba comment +class SambaComment: + + def __init__( self, comment ): + self.comment = comment + + def Dump( self, stream, whitespace=None ): + if not self.comment: + return + for line in self.comment: + if whitespace: + stream.write( whitespace ) + stream.write( line ) + stream.write( "\n" ) + + +##################################################################### +## string smb.conf parms +class SambaParameter : + + ## indexs into the parm table tuples + DisplayName = 0 + ObjectType = 1 + DefaultValue = 2 + Scope = 3 + + ## Stores a key into the parm_table and creates an + ## SambaParmXXX object to store the value + def __init__( self, name, value, comment=None ): + self.key = string.upper(string.strip(name)) + self.comment = None + assert parm_table.has_key( self.key ), "Bad parameter name! [%s]" % name + self.parm = parm_table[self.key][self.ObjectType]( value ) + if comment : + self.comment = SambaComment( comment ) + + #if not self.parm.valid: + # self.parm.SetValue( parm_table[self.key][self.DefaultValue] ) + + ## simple test for global or service parameter scope + def isGlobalParm( self ) : + return parm_table[self.key][Scope] + + ## dump <the parameter to stdout + def Dump( self, stream ): + if self.comment: + self.comment.Dump( stream, "\t" ) + stream.write( "\t%s = %s\n" % ( parm_table[self.key][self.DisplayName], self.parm.StringValue() )) + + +##################################################################### +## Class for parsing and modifying Smb.conf +class SambaConf: + + def __init__( self ): + self.services = {} + self.valid = True + self.services["GLOBAL"] = {} + self.services_order = [] + + + ## always return a non-empty line of input or None + ## if we hit EOF + def ReadLine( self, stream ): + result = None + input_str = None + + while True: + input_str = stream.readline() + + ## Are we done with the file ? + + if len(input_str) == 0: + return result + + ## we need one line of valid input at least + ## continue around the loop again if the result + ## string is empty + + input_str = string.strip( input_str ) + if len(input_str) == 0: + if not result: + continue + else: + return result + + ## we have > 1` character so setup the result + if not result: + result = "" + + ## Check for comments -- terminated by \n -- no continuation + + if input_str[0] == '#' or input_str[0] == ';' : + result = input_str + break + + ## check for line continuation + + if input_str[-1] == "\\" : + result += input_str[0:-1] + contine + + ## otherwise we have a complete line + result += input_str + break + + return result + + ## convert the parameter name to a form suitable as a dictionary key + def NormalizeParamName( self, param ): + return string.upper( string.join(string.split(param), "") ) + + ## Open the file and parse it into a services dictionary + ## if possible + def ReadConfig( self, filename ): + self.filename = filename + + try: + fconfig = open( filename, "r" ) + except IOError: + self.valid = False + return + + section_name = None + + ## the most recent seen comment is stored as an array + current_comment = [] + + while True: + + str = self.ReadLine( fconfig ) + if not str: + break + + ## Check for comments + if str[0] == '#' or str[0] == ';' : + current_comment.append( str ) + continue + + ## look for a next section name + if str[0]=='[' and str[-1]==']' : + section_name = str[1:-1] + self.AddService( section_name, current_comment ) + current_comment = [] + continue + + str_list = string.split( str, "=" ) + + if len(str_list) != 2 : + continue + + if not section_name : + print "parameter given without section name!" + break + + param = self.NormalizeParamName( str_list[0] ) + value = string.strip(str_list[1]) + + self.SetServiceOption( section_name, param, value, current_comment ) + self.dirty = False + + ## reset the comment strinf if we have one + current_comment = [] + + fconfig.close() + + ## Add a parameter to the global section + def SetGlobalOption( self, param, value, comment=None ) : + self.SetServiceOption( "GLOBAL", param, value, comment ) + + ## Add a parameter to a specific service + def SetServiceOption( self, servicename, param, value, comment=None ) : + service = string.upper(servicename) + parm = self.NormalizeParamName(param) + self.services[service]['_order_'].append( parm ) + self.services[service][parm] = SambaParameter( parm, value, comment ) + self.dirty = True + + ## remove a service from the config file + def DelService( self, servicename ) : + service = string.upper(servicename) + self.services[service] = None + self.dirty = True + + ## remove a service from the config file + def AddService( self, servicename, comment=None ) : + service = string.upper(servicename) + + self.services[service] = {} + self.services[service]['_order_'] = [] + + if ( comment ): + self.services[service]['_comment_'] = SambaComment( comment ) + + self.services_order.append( service ) + + self.dirty = True + + def isService( self, servicename ): + service = string.upper(servicename) + return self.services.has_key( service ) + + ## dump a single service to stream + def DumpService( self, stream, servicename ): + + ## comments first + if self.services[servicename].has_key( '_comment_' ): + self.services[servicename]['_comment_'].Dump( stream ) + + ## section header + stream.write( "[%s]\n" % (servicename) ) + + ## parameter = value + for parm in self.services[servicename]['_order_']: + self.services[servicename][parm].Dump(stream) + + ## dump the config to stream + def Dump( self, stream ): + self.DumpService( stream, "GLOBAL" ) + stream.write("\n") + + for section in self.services_order: + ## already handled the global section + if section == "GLOBAL": + continue + + ## check for deleted sections ## + if not self.services[section]: + continue + + self.DumpService( stream, section ) + stream.write( "\n" ) + + ## write out any changes to disk + def Flush( self ): + if not self.dirty: + return + + try: + fconfig = open( self.filename, "w" ) + except IOError: + sys.stderr.write( "ERROR!\n" ) + return 1 + + self.Dump( fconfig ) + fconfig.close() + return 0 + + def Services( self ): + service_list = [] + for section in self.services.keys(): + service_list.append( section ) + + return service_list + + def NumServices( self ): + return len(self.Services()) + + def Write( self, filename ): + self.filename = filename + self.valid = True + + if not self.dirty: + return + + self.Flush() + + + +###################################################################### +## Unit tests +###################################################################### + +if __name__ == "__main__" : + + x = SambaConf( ) + x.ReadConfig( sys.argv[1] ) + if not x.valid : + print "Bad file!" + sys.exit(1) + + x.Dump( sys.stdout ) + + + +## end of SambaConfig.py ###################################################### +############################################################################### + diff --git a/examples/scripts/shares/python/SambaParm.py b/examples/scripts/shares/python/SambaParm.py new file mode 100644 index 0000000000..82c99c84ac --- /dev/null +++ b/examples/scripts/shares/python/SambaParm.py @@ -0,0 +1,83 @@ +###################################################################### +## +## smb.conf parameter classes +## +## Copyright (C) Gerald Carter 2004. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see <http://www.gnu.org/licenses/>. +## +###################################################################### + +import string + +##################################################################### +## Base class for Samba smb.conf parameters +class SambaParm : + def __init__( self ) : + pass + + def StringValue( self ) : + return self.value + +##################################################################### +## Boolean smb,conf parm +class SambaParmBool( SambaParm ): + def __init__( self, value ) : + x = string.upper(value) + self.valid = True + + if x=="YES" or x=="TRUE" or x=="1": + self.value = True + elif x=="NO" or x=="FALSE" or x=="0": + self.value = False + else: + self.valid = False + return self + + def SetValue( self, value ) : + x = string.upper(value) + self.valid = True + + if x=="YES" or x=="TRUE" or x=="1": + self.value = True + elif x=="NO" or x=="FALSE" or x=="0": + self.value = False + else: + self.valid = False + return + + def StringValue( self ) : + if self.value : + return "yes" + else: + return "no" + +##################################################################### +## Boolean smb,conf parm (inverts) +class SambaParmBoolRev( SambaParmBool ) : + def __init__( self, value ): + SambaParmBool.__init__( self, value ) + if self.valid : + self.value = not self.value + + +##################################################################### +## string smb.conf parms +class SambaParmString( SambaParm ): + def __init__( self, value ): + self.value = value + self.valid = True + + + diff --git a/examples/scripts/shares/python/generate_parm_table.py b/examples/scripts/shares/python/generate_parm_table.py new file mode 100755 index 0000000000..1d2c5f246c --- /dev/null +++ b/examples/scripts/shares/python/generate_parm_table.py @@ -0,0 +1,222 @@ +#!/usr/bin/env python +###################################################################### +## +## Generate parameter dictionary from param/loadparm.c +## +## Copyright (C) Gerald Carter 2004. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see <http://www.gnu.org/licenses/>. +## +###################################################################### + +import re, string, sys, commands + +HEADER = """###################################################################### +## +## autogenerated file of smb.conf parameters +## generate_parm_table <..../param/loadparm.c> +## +## Copyright (C) Gerald Carter 2004. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see <http://www.gnu.org/licenses/>. +## +###################################################################### + +from SambaParm import SambaParmString, SambaParmBool, SambaParmBoolRev + +## boolean defines for parm_table +P_LOCAL = 0 +P_GLOBAL = 1 + +""" + +FOOTER = """##### end of smbparm.y ########################################## +#################################################################""" + +TESTPARM = "/usr/bin/testparm" + +## fields in Samba's parameter table +displayName = 0 +type = 1 +scope = 2 +variable = 3 +flags = 6 + +parm_table = {} +var_table = {} +def_values = {} +obj_table = { + 'P_BOOL' : 'SambaParmBool', + 'P_BOOLREV' : 'SambaParmBoolRev', + 'P_STRING' : 'SambaParmString', + 'P_USTRING' : 'SambaParmString', + 'P_GSTRING' : 'SambaParmString', + 'P_LIST' : 'SambaParmString', + 'P_ENUM' : 'SambaParmString', + 'P_CHAR' : 'SambaParmString', + 'P_OCTAL' : 'SambaParmString', + 'P_INTEGER' : 'SambaParmString', +} + +###################################################################### +## BEGIN MAIN CODE ## +###################################################################### + +## First thing is to build the dictionary of parmeter names ## +## based on the output from testparm ## + +cmd = "/usr/bin/testparm -s -v /dev/null" +( status, testparm_output ) = commands.getstatusoutput( cmd ) +if status: + sys.stderr.write( "Failed to execute testparm!\n%s\n" % testparm_output ) + + +## break the output into a list ## + +lines = string.split( testparm_output, "\n" ) + +## loop through list -- parameters in testparm output have ## +## whitespace at the beginning of the line ## + +pattern = re.compile( "^\s+" ) +for input_str in lines: + if not pattern.search( input_str ): + continue + input_str = string.strip( input_str ) + parts = string.split( input_str, "=" ) + parts[0] = string.strip( parts[0] ) + parts[1] = string.strip( parts[1] ) + key = string.upper( string.join(string.split(parts[0]), "") ) + new = parts[1].replace('\\', '\\\\') + def_values[key] = new + +## open loadparm.c and get the entire list of parameters ## +## including synonums ## + +if len(sys.argv) != 2: + print "Usage: %s <.../param/loadparm.c>" % ( sys.argv[0] ) + sys.exit( 1 ) + +try: + fconfig = open( sys.argv[1], "r" ) +except IOError: + print "%s does not exist!" % sys.argv[1] + sys.exit (1) + +## Loop through loadparm.c -- all parameters are either ## +## P_LOCAL or P_GLOBAL ## + +synonyms = [] +pattern = re.compile( '{".*P_[GL]' ) +while True: + input_str= fconfig.readline() + if len(input_str) == 0 : + break + input_str= string.strip(input_str) + + ## see if we have a patch for a parameter definition ## + + parm = [] + if pattern.search( input_str) : + + ## strip the surrounding '{.*},' ## + + input_str= input_str[1:-2] + parm = string.split(input_str, ",") + + ## strip the ""'s and upper case ## + + name = (string.strip(parm[displayName])[1:-1]) + key = string.upper( string.join(string.split(name), "") ) + var_name = string.strip( parm[variable] ) + + + ## try to catch synonyms -- if the parameter was not reported ## + ## by testparm, then save it and come back after we will out ## + ## the variable list ## + + if not def_values.has_key( key ): + synonyms.append( input_str) + continue + + + var_table[var_name] = key + + parmType = string.strip(parm[type]) + + parm_table[key] = [ name , string.strip(parm[type]), string.strip(parm[scope]), def_values[key] ] + +## Deal with any synonyms ## + +for input_str in synonyms: + parm = string.split(input_str, ",") + name = (string.strip(parm[displayName])[1:-1]) + key = string.upper( string.join(string.split(name), "") ) + var_name = string.strip( parm[variable] ) + + ## if there's no pre-existing key, then testparm doesn't know about it + if not var_table.has_key( var_name ): + continue + + ## just make a copy + parm_table[key] = parm_table[var_table[var_name]][:] + # parm_table[key][1] = parm[1] + parm_table[key][1] = string.strip(parm[1]) + +## ## +## print out smbparm.py ## +## ## + +try: + smbparm = open ( "smbparm.py", "w" ) +except IOError: + print "Cannot write to smbparm.py" + sys.exit( 1 ) + +smbparm.write( HEADER ) +smbparm.write( "parm_table = {\n" ) + +for x in parm_table.keys(): + key = "\"%s\"" % x + smbparm.write("\t%-25s: (\"%s\", %s, %s, \"%s\"),\n" % ( key, parm_table[x][0], + obj_table[parm_table[x][1]], parm_table[x][2], parm_table[x][3] )) + +smbparm.write( "}\n" ) + +smbparm.write( FOOTER ) +smbparm.write( "\n" ) + +sys.exit(0) + + +## ## +## cut-n-paste area ## +## ## + +for x in parm_table.keys(): + if def_values.has_key( x ): + parm_table[x].append( def_values[x] ) + else: + parm_table[x].append( "" ) diff --git a/examples/scripts/shares/python/modify_samba_config.py b/examples/scripts/shares/python/modify_samba_config.py new file mode 100755 index 0000000000..88b3fcb394 --- /dev/null +++ b/examples/scripts/shares/python/modify_samba_config.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +###################################################################### +## +## Simple add/delete/change share command script for Samba +## +## Copyright (C) Gerald Carter 2004. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see <http://www.gnu.org/licenses/>. +## +###################################################################### + +import sys, os +from SambaConfig import SambaConf + + +## ## +## check the command line args ## +## ## +delete_mode = False +if len(sys.argv) == 3: + delete_mode = True + print "Deleting share..." +elif len(sys.argv) == 5: + print "Adding/Updating share..." +else: + print "Usage: %s configfile share [path] [comments]" % sys.argv[0] + sys.exit(1) + + +## ## +## read and parse the config file ## +## ## + +confFile = SambaConf() + +confFile.ReadConfig( sys.argv[1] ) +if not confFile.valid: + exit( 1 ) + +if delete_mode: + if not confFile.isService( sys.argv[2] ): + sys.stderr.write( "Asked to delete non-existent service! [%s]\n" % sys.argv[2] ) + sys.exit( 1 ) + + confFile.DelService( sys.argv[2] ) +else: + ## make the path if it doesn't exist. Bail out if that fails + if ( not os.path.isdir(sys.argv[3]) ): + try: + os.makedirs( sys.argv[3] ) + os.chmod( sys.argv[3], 0777 ) + except os.error: + sys.exit( 1 ) + + ## only add a new service -- if it already exists, then + ## just set the options + if not confFile.isService( sys.argv[2] ): + confFile.AddService( sys.argv[2], ['##', '## Added by modify_samba_config.py', '##'] ) + confFile.SetServiceOption( sys.argv[2], "path", sys.argv[3] ) + confFile.SetServiceOption( sys.argv[2], "comment", sys.argv[4] ) + confFile.SetServiceOption( sys.argv[2], "read only", "no" ) + +ret = confFile.Flush() + +sys.exit( ret ) + diff --git a/examples/scripts/shares/python/smbparm.py b/examples/scripts/shares/python/smbparm.py new file mode 100644 index 0000000000..73637a7095 --- /dev/null +++ b/examples/scripts/shares/python/smbparm.py @@ -0,0 +1,373 @@ +###################################################################### +## +## autogenerated file of smb.conf parameters +## generate_parm_table <..../param/loadparm.c> +## +## Copyright (C) Gerald Carter 2004. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see <http://www.gnu.org/licenses/>. +## +###################################################################### + +from SambaParm import SambaParmString, SambaParmBool, SambaParmBoolRev + +## boolean defines for parm_table +P_LOCAL = 0 +P_GLOBAL = 1 + +parm_table = { + "PRELOADMODULES" : ("preload modules", SambaParmString, P_GLOBAL, ""), + "ONLYGUEST" : ("guest only", SambaParmBool, P_LOCAL, "No"), + "PRIVATEDIR" : ("private dir", SambaParmString, P_GLOBAL, "/etc/samba/private"), + "HIDESPECIALFILES" : ("hide special files", SambaParmBool, P_LOCAL, "No"), + "WINBINDENUMUSERS" : ("winbind enum users", SambaParmBool, P_GLOBAL, "Yes"), + "TIMESTAMPLOGS" : ("debug timestamp", SambaParmBool, P_GLOBAL, "Yes"), + "LDAPPASSWDSYNC" : ("ldap passwd sync", SambaParmString, P_GLOBAL, "no"), + "READBMPX" : ("read bmpx", SambaParmBool, P_GLOBAL, "No"), + "PASSWORDSERVER" : ("password server", SambaParmString, P_GLOBAL, "*"), + "COPY" : ("copy", SambaParmString, P_LOCAL, ""), + "MAXXMIT" : ("max xmit", SambaParmString, P_GLOBAL, "16644"), + "MINPRINTSPACE" : ("min print space", SambaParmString, P_LOCAL, "0"), + "CASESENSITIVE" : ("case sensitive", SambaParmString, P_LOCAL, "Auto"), + "LDAPIDMAPSUFFIX" : ("ldap idmap suffix", SambaParmString, P_GLOBAL, ""), + "NAMECACHETIMEOUT" : ("name cache timeout", SambaParmString, P_GLOBAL, "660"), + "MAPARCHIVE" : ("map archive", SambaParmBool, P_LOCAL, "Yes"), + "LANMANAUTH" : ("lanman auth", SambaParmBool, P_GLOBAL, "Yes"), + "NETBIOSSCOPE" : ("netbios scope", SambaParmString, P_GLOBAL, ""), + "MAXREPORTEDPRINTJOBS" : ("max reported print jobs", SambaParmString, P_LOCAL, "0"), + "CREATEMODE" : ("create mask", SambaParmString, P_LOCAL, "0744"), + "READLIST" : ("read list", SambaParmString, P_LOCAL, ""), + "WINBINDNESTEDGROUPS" : ("winbind nested groups", SambaParmBool, P_GLOBAL, "No"), + "COMMENT" : ("comment", SambaParmString, P_LOCAL, ""), + "PRINTER" : ("printer name", SambaParmString, P_LOCAL, ""), + "LMANNOUNCE" : ("lm announce", SambaParmString, P_GLOBAL, "Auto"), + "SYSLOGONLY" : ("syslog only", SambaParmBool, P_GLOBAL, "No"), + "LMINTERVAL" : ("lm interval", SambaParmString, P_GLOBAL, "60"), + "MANGLINGMETHOD" : ("mangling method", SambaParmString, P_GLOBAL, "hash2"), + "PROFILEACLS" : ("profile acls", SambaParmBool, P_LOCAL, "No"), + "LDAPGROUPSUFFIX" : ("ldap group suffix", SambaParmString, P_GLOBAL, ""), + "MAPTOGUEST" : ("map to guest", SambaParmString, P_GLOBAL, "Never"), + "NULLPASSWORDS" : ("null passwords", SambaParmBool, P_GLOBAL, "No"), + "ONLYUSER" : ("only user", SambaParmBool, P_LOCAL, "No"), + "UTMP" : ("utmp", SambaParmBool, P_GLOBAL, "No"), + "DONTDESCEND" : ("dont descend", SambaParmString, P_LOCAL, ""), + "PRINTING" : ("printing", SambaParmString, P_LOCAL, "cups"), + "SOCKETOPTIONS" : ("socket options", SambaParmString, P_GLOBAL, "TCP_NODELAY"), + "CLIENTUSESPNEGO" : ("client use spnego", SambaParmBool, P_GLOBAL, "Yes"), + "USESPNEGO" : ("use spnego", SambaParmBool, P_GLOBAL, "Yes"), + "FAKEOPLOCKS" : ("fake oplocks", SambaParmBool, P_LOCAL, "No"), + "FORCECREATEMODE" : ("force create mode", SambaParmString, P_LOCAL, "00"), + "SETDIRECTORY" : ("set directory", SambaParmBoolRev, P_LOCAL, "No"), + "SMBPORTS" : ("smb ports", SambaParmString, P_GLOBAL, "445 139"), + "LOCKDIR" : ("lock directory", SambaParmString, P_GLOBAL, "/var/lib/samba"), + "BROWSEABLE" : ("browseable", SambaParmBool, P_LOCAL, "Yes"), + "WINSPROXY" : ("wins proxy", SambaParmBool, P_GLOBAL, "No"), + "FORCEGROUP" : ("force group", SambaParmString, P_LOCAL, ""), + "NTSTATUSSUPPORT" : ("nt status support", SambaParmBool, P_GLOBAL, "Yes"), + "EXEC" : ("preexec", SambaParmString, P_LOCAL, ""), + "DOMAINLOGONS" : ("domain logons", SambaParmBool, P_GLOBAL, "No"), + "TEMPLATESHELL" : ("template shell", SambaParmString, P_GLOBAL, "/bin/false"), + "USESENDFILE" : ("use sendfile", SambaParmBool, P_LOCAL, "No"), + "USEMMAP" : ("use mmap", SambaParmBool, P_GLOBAL, "Yes"), + "VALIDUSERS" : ("valid users", SambaParmString, P_LOCAL, ""), + "DEBUGLEVEL" : ("log level", SambaParmString, P_GLOBAL, "0"), + "PRINTCAPCACHETIME" : ("printcap cache time", SambaParmString, P_GLOBAL, "0"), + "SOCKETADDRESS" : ("socket address", SambaParmString, P_GLOBAL, "0.0.0.0"), + "FORCEDIRECTORYMODE" : ("force directory mode", SambaParmString, P_LOCAL, "00"), + "MSDFSROOT" : ("msdfs root", SambaParmBool, P_LOCAL, "No"), + "ROOTPREEXEC" : ("root preexec", SambaParmString, P_LOCAL, ""), + "WRITEOK" : ("read only", SambaParmBoolRev, P_LOCAL, "Yes"), + "MAXLOGSIZE" : ("max log size", SambaParmString, P_GLOBAL, "5000"), + "FORCESECURITYMODE" : ("force security mode", SambaParmString, P_LOCAL, "00"), + "VFSOBJECT" : ("vfs objects", SambaParmString, P_LOCAL, ""), + "CHECKPASSWORDSCRIPT" : ("check password script", SambaParmString, P_GLOBAL, ""), + "DELETEPRINTERCOMMAND" : ("deleteprinter command", SambaParmString, P_GLOBAL, ""), + "OSLEVEL" : ("os level", SambaParmString, P_GLOBAL, "20"), + "ENUMPORTSCOMMAND" : ("enumports command", SambaParmString, P_GLOBAL, ""), + "DELETEUSERFROMGROUPSCRIPT": ("delete user from group script", SambaParmString, P_GLOBAL, ""), + "IDMAPGID" : ("idmap gid", SambaParmString, P_GLOBAL, ""), + "PREEXECCLOSE" : ("preexec close", SambaParmBool, P_LOCAL, "No"), + "UTMPDIRECTORY" : ("utmp directory", SambaParmString, P_GLOBAL, ""), + "DOSFILEMODE" : ("dos filemode", SambaParmBool, P_LOCAL, "No"), + "LOGFILE" : ("log file", SambaParmString, P_GLOBAL, ""), + "WORKGROUP" : ("workgroup", SambaParmString, P_GLOBAL, "WORKGROUP"), + "DIRECTORYSECURITYMASK" : ("directory security mask", SambaParmString, P_LOCAL, "0777"), + "ENCRYPTPASSWORDS" : ("encrypt passwords", SambaParmBool, P_GLOBAL, "Yes"), + "PRINTABLE" : ("printable", SambaParmBool, P_LOCAL, "No"), + "MAXPROTOCOL" : ("max protocol", SambaParmString, P_GLOBAL, "NT1"), + "KERNELOPLOCKS" : ("kernel oplocks", SambaParmBool, P_GLOBAL, "Yes"), + "NETBIOSALIASES" : ("netbios aliases", SambaParmString, P_GLOBAL, ""), + "ANNOUNCEAS" : ("announce as", SambaParmString, P_GLOBAL, "NT"), + "DIRECTORYMASK" : ("directory mask", SambaParmString, P_LOCAL, "0755"), + "MAPSYSTEM" : ("map system", SambaParmBool, P_LOCAL, "No"), + "CHANGENOTIFYTIMEOUT" : ("change notify timeout", SambaParmString, P_GLOBAL, "60"), + "WINBINDTRUSTEDDOMAINSONLY": ("winbind trusted domains only", SambaParmBool, P_GLOBAL, "No"), + "SHUTDOWNSCRIPT" : ("shutdown script", SambaParmString, P_GLOBAL, ""), + "FOLLOWSYMLINKS" : ("follow symlinks", SambaParmBool, P_LOCAL, "Yes"), + "MAPHIDDEN" : ("map hidden", SambaParmBool, P_LOCAL, "No"), + "GROUP" : ("force group", SambaParmString, P_LOCAL, ""), + "DENYHOSTS" : ("hosts deny", SambaParmString, P_LOCAL, ""), + "WINBINDCACHETIME" : ("winbind cache time", SambaParmString, P_GLOBAL, "300"), + "DELETEVETOFILES" : ("delete veto files", SambaParmBool, P_LOCAL, "No"), + "DISABLESPOOLSS" : ("disable spoolss", SambaParmBool, P_GLOBAL, "No"), + "MAXCONNECTIONS" : ("max connections", SambaParmString, P_LOCAL, "0"), + "WRITERAW" : ("write raw", SambaParmBool, P_GLOBAL, "Yes"), + "SERVERSIGNING" : ("server signing", SambaParmString, P_GLOBAL, "No"), + "VOLUME" : ("volume", SambaParmString, P_LOCAL, ""), + "UNIXPASSWORDSYNC" : ("unix password sync", SambaParmBool, P_GLOBAL, "No"), + "OBEYPAMRESTRICTIONS" : ("obey pam restrictions", SambaParmBool, P_GLOBAL, "No"), + "PASSWDCHATTIMEOUT" : ("passwd chat timeout", SambaParmString, P_GLOBAL, "2"), + "USER" : ("username", SambaParmString, P_LOCAL, ""), + "HIDEDOTFILES" : ("hide dot files", SambaParmBool, P_LOCAL, "Yes"), + "ROOTPOSTEXEC" : ("root postexec", SambaParmString, P_LOCAL, ""), + "PROTOCOL" : ("max protocol", SambaParmString, P_GLOBAL, "NT1"), + "LDAPADMINDN" : ("ldap admin dn", SambaParmString, P_GLOBAL, ""), + "DNSPROXY" : ("dns proxy", SambaParmBool, P_GLOBAL, "Yes"), + "OS2DRIVERMAP" : ("os2 driver map", SambaParmString, P_GLOBAL, ""), + "QUEUERESUMECOMMAND" : ("queueresume command", SambaParmString, P_LOCAL, ""), + "SERVERSCHANNEL" : ("server schannel", SambaParmString, P_GLOBAL, "Auto"), + "IDMAPUID" : ("idmap uid", SambaParmString, P_GLOBAL, ""), + "WINBINDENABLELOCALACCOUNTS": ("winbind enable local accounts", SambaParmBool, P_GLOBAL, "No"), + "PRINTERNAME" : ("printer name", SambaParmString, P_LOCAL, ""), + "NTACLSUPPORT" : ("nt acl support", SambaParmBool, P_LOCAL, "Yes"), + "LOGLEVEL" : ("log level", SambaParmString, P_GLOBAL, "0"), + "STATCACHE" : ("stat cache", SambaParmBool, P_GLOBAL, "Yes"), + "LPQCACHETIME" : ("lpq cache time", SambaParmString, P_GLOBAL, "30"), + "LEVEL2OPLOCKS" : ("level2 oplocks", SambaParmBool, P_LOCAL, "Yes"), + "LARGEREADWRITE" : ("large readwrite", SambaParmBool, P_GLOBAL, "Yes"), + "LDAPREPLICATIONSLEEP" : ("ldap replication sleep", SambaParmString, P_GLOBAL, "1000"), + "SECURITYMASK" : ("security mask", SambaParmString, P_LOCAL, "0777"), + "LDAPUSERSUFFIX" : ("ldap user suffix", SambaParmString, P_GLOBAL, ""), + "NETBIOSNAME" : ("netbios name", SambaParmString, P_GLOBAL, "PANTHER"), + "LOCKSPINCOUNT" : ("lock spin count", SambaParmString, P_GLOBAL, "3"), + "OPLOCKS" : ("oplocks", SambaParmBool, P_LOCAL, "Yes"), + "MINWINSTTL" : ("min wins ttl", SambaParmString, P_GLOBAL, "21600"), + "HOMEDIRMAP" : ("homedir map", SambaParmString, P_GLOBAL, ""), + "REMOTEANNOUNCE" : ("remote announce", SambaParmString, P_GLOBAL, ""), + "PREFERREDMASTER" : ("preferred master", SambaParmString, P_GLOBAL, "Auto"), + "SECURITY" : ("security", SambaParmString, P_GLOBAL, "USER"), + "AUTHMETHODS" : ("auth methods", SambaParmString, P_GLOBAL, ""), + "ENABLERIDALGORITHM" : ("enable rid algorithm", SambaParmBool, P_GLOBAL, "Yes"), + "LPRMCOMMAND" : ("lprm command", SambaParmString, P_LOCAL, ""), + "KERNELCHANGENOTIFY" : ("kernel change notify", SambaParmBool, P_GLOBAL, "Yes"), + "LOGONSCRIPT" : ("logon script", SambaParmString, P_GLOBAL, ""), + "PRESERVECASE" : ("preserve case", SambaParmBool, P_LOCAL, "Yes"), + "UNIXCHARSET" : ("unix charset", SambaParmString, P_GLOBAL, "UTF-8"), + "FORCEPRINTERNAME" : ("force printername", SambaParmBool, P_LOCAL, "No"), + "LDAPFILTER" : ("ldap filter", SambaParmString, P_GLOBAL, "(uid"), + "DELETEREADONLY" : ("delete readonly", SambaParmBool, P_LOCAL, "No"), + "ABORTSHUTDOWNSCRIPT" : ("abort shutdown script", SambaParmString, P_GLOBAL, ""), + "DFREECOMMAND" : ("dfree command", SambaParmString, P_GLOBAL, ""), + "VETOFILES" : ("veto files", SambaParmString, P_LOCAL, ""), + "LOCKING" : ("locking", SambaParmBool, P_LOCAL, "Yes"), + "EASUPPORT" : ("ea support", SambaParmBool, P_LOCAL, "No"), + "MAXSMBDPROCESSES" : ("max smbd processes", SambaParmString, P_GLOBAL, "0"), + "HIDEFILES" : ("hide files", SambaParmString, P_LOCAL, ""), + "PASSWDCHATDEBUG" : ("passwd chat debug", SambaParmBool, P_GLOBAL, "No"), + "SMBPASSWDFILE" : ("smb passwd file", SambaParmString, P_GLOBAL, "/etc/samba/private/smbpasswd"), + "GETQUOTACOMMAND" : ("get quota command", SambaParmString, P_GLOBAL, ""), + "OPLOCKCONTENTIONLIMIT" : ("oplock contention limit", SambaParmString, P_LOCAL, "2"), + "DOMAINMASTER" : ("domain master", SambaParmString, P_GLOBAL, "Auto"), + "DELETESHARECOMMAND" : ("delete share command", SambaParmString, P_GLOBAL, ""), + "INVALIDUSERS" : ("invalid users", SambaParmString, P_LOCAL, ""), + "POSIXLOCKING" : ("posix locking", SambaParmBool, P_LOCAL, "Yes"), + "INCLUDE" : ("include", SambaParmString, P_LOCAL, ""), + "ALGORITHMICRIDBASE" : ("algorithmic rid base", SambaParmString, P_GLOBAL, "1000"), + "FORCEDIRECTORYSECURITYMODE": ("force directory security mode", SambaParmString, P_LOCAL, "00"), + "ANNOUNCEVERSION" : ("announce version", SambaParmString, P_GLOBAL, "4.9"), + "USERNAMEMAP" : ("username map", SambaParmString, P_GLOBAL, ""), + "MANGLEDNAMES" : ("mangled names", SambaParmBool, P_LOCAL, "Yes"), + "ROOTDIRECTORY" : ("root directory", SambaParmString, P_GLOBAL, ""), + "DEBUGHIRESTIMESTAMP" : ("debug hires timestamp", SambaParmBool, P_GLOBAL, "No"), + "LOGONDRIVE" : ("logon drive", SambaParmString, P_GLOBAL, ""), + "LOCALMASTER" : ("local master", SambaParmBool, P_GLOBAL, "Yes"), + "ROOTPREEXECCLOSE" : ("root preexec close", SambaParmBool, P_LOCAL, "No"), + "CONFIGFILE" : ("config file", SambaParmString, P_GLOBAL, ""), + "USECLIENTDRIVER" : ("use client driver", SambaParmBool, P_LOCAL, "No"), + "MINPROTOCOL" : ("min protocol", SambaParmString, P_GLOBAL, "CORE"), + "ADDUSERTOGROUPSCRIPT" : ("add user to group script", SambaParmString, P_GLOBAL, ""), + "MAPACLINHERIT" : ("map acl inherit", SambaParmBool, P_LOCAL, "No"), + "DELETEUSERSCRIPT" : ("delete user script", SambaParmString, P_GLOBAL, ""), + "WINBINDUID" : ("idmap uid", SambaParmString, P_GLOBAL, ""), + "READRAW" : ("read raw", SambaParmBool, P_GLOBAL, "Yes"), + "WINBINDENUMGROUPS" : ("winbind enum groups", SambaParmBool, P_GLOBAL, "Yes"), + "PASSWORDLEVEL" : ("password level", SambaParmString, P_GLOBAL, "0"), + "MAXPRINTJOBS" : ("max print jobs", SambaParmString, P_LOCAL, "1000"), + "PRINTCAP" : ("printcap name", SambaParmString, P_GLOBAL, ""), + "LOADPRINTERS" : ("load printers", SambaParmBool, P_GLOBAL, "Yes"), + "DEFAULT" : ("default service", SambaParmString, P_GLOBAL, ""), + "GUESTACCOUNT" : ("guest account", SambaParmString, P_GLOBAL, "nobody"), + "AUTOSERVICES" : ("preload", SambaParmString, P_GLOBAL, ""), + "WRITEABLE" : ("read only", SambaParmBoolRev, P_LOCAL, "Yes"), + "CLIENTLANMANAUTH" : ("client lanman auth", SambaParmBool, P_GLOBAL, "Yes"), + "MESSAGECOMMAND" : ("message command", SambaParmString, P_GLOBAL, ""), + "UNIXEXTENSIONS" : ("unix extensions", SambaParmBool, P_GLOBAL, "Yes"), + "LDAPPASSWORDSYNC" : ("ldap passwd sync", SambaParmString, P_GLOBAL, "no"), + "AFSUSERNAMEMAP" : ("afs username map", SambaParmString, P_GLOBAL, ""), + "SYSLOG" : ("syslog", SambaParmString, P_GLOBAL, "1"), + "SETPRIMARYGROUPSCRIPT" : ("set primary group script", SambaParmString, P_GLOBAL, ""), + "DEADTIME" : ("deadtime", SambaParmString, P_GLOBAL, "0"), + "RESTRICTANONYMOUS" : ("restrict anonymous", SambaParmString, P_GLOBAL, "0"), + "USERNAMELEVEL" : ("username level", SambaParmString, P_GLOBAL, "0"), + "DISPLAYCHARSET" : ("display charset", SambaParmString, P_GLOBAL, "LOCALE"), + "FORCEUSER" : ("force user", SambaParmString, P_LOCAL, ""), + "HOSTSDENY" : ("hosts deny", SambaParmString, P_LOCAL, ""), + "HIDEUNWRITEABLEFILES" : ("hide unwriteable files", SambaParmBool, P_LOCAL, "No"), + "DOSCHARSET" : ("dos charset", SambaParmString, P_GLOBAL, "CP850"), + "DOSFILETIMES" : ("dos filetimes", SambaParmBool, P_LOCAL, "No"), + "REALM" : ("realm", SambaParmString, P_GLOBAL, ""), + "LDAPSUFFIX" : ("ldap suffix", SambaParmString, P_GLOBAL, ""), + "LPPAUSECOMMAND" : ("lppause command", SambaParmString, P_LOCAL, ""), + "FAKEDIRECTORYCREATETIMES": ("fake directory create times", SambaParmBool, P_LOCAL, "No"), + "MAGICSCRIPT" : ("magic script", SambaParmString, P_LOCAL, ""), + "WRITECACHESIZE" : ("write cache size", SambaParmString, P_LOCAL, "0"), + "BLOCKSIZE" : ("block size", SambaParmString, P_LOCAL, "1024"), + "LOCKSPINTIME" : ("lock spin time", SambaParmString, P_GLOBAL, "10"), + "ACLCOMPATIBILITY" : ("acl compatibility", SambaParmString, P_GLOBAL, ""), + "MSDFSPROXY" : ("msdfs proxy", SambaParmString, P_LOCAL, ""), + "POSTEXEC" : ("postexec", SambaParmString, P_LOCAL, ""), + "HIDEUNREADABLE" : ("hide unreadable", SambaParmBool, P_LOCAL, "No"), + "WIDELINKS" : ("wide links", SambaParmBool, P_LOCAL, "Yes"), + "STRICTSYNC" : ("strict sync", SambaParmBool, P_LOCAL, "No"), + "PRINTCAPNAME" : ("printcap name", SambaParmString, P_GLOBAL, ""), + "PREFEREDMASTER" : ("preferred master", SambaParmString, P_GLOBAL, "Auto"), + "MAXMUX" : ("max mux", SambaParmString, P_GLOBAL, "50"), + "VETOOPLOCKFILES" : ("veto oplock files", SambaParmString, P_LOCAL, ""), + "WINBINDSEPARATOR" : ("winbind separator", SambaParmString, P_GLOBAL, "\\"), + "NISHOMEDIR" : ("NIS homedir", SambaParmBool, P_GLOBAL, "No"), + "AVAILABLE" : ("available", SambaParmBool, P_LOCAL, "Yes"), + "KEEPALIVE" : ("keepalive", SambaParmString, P_GLOBAL, "300"), + "USERNAME" : ("username", SambaParmString, P_LOCAL, ""), + "PRINTCOMMAND" : ("print command", SambaParmString, P_LOCAL, ""), + "LPRESUMECOMMAND" : ("lpresume command", SambaParmString, P_LOCAL, ""), + "USEKERBEROSKEYTAB" : ("use kerberos keytab", SambaParmBool, P_GLOBAL, "No"), + "HOSTSALLOW" : ("hosts allow", SambaParmString, P_LOCAL, ""), + "MAXOPENFILES" : ("max open files", SambaParmString, P_GLOBAL, "10000"), + "PARANOIDSERVERSECURITY" : ("paranoid server security", SambaParmBool, P_GLOBAL, "Yes"), + "WTMPDIRECTORY" : ("wtmp directory", SambaParmString, P_GLOBAL, ""), + "ADDPRINTERCOMMAND" : ("addprinter command", SambaParmString, P_GLOBAL, ""), + "PRINTERADMIN" : ("printer admin", SambaParmString, P_LOCAL, ""), + "WINSSERVER" : ("wins server", SambaParmString, P_GLOBAL, ""), + "LDAPTIMEOUT" : ("ldap timeout", SambaParmString, P_GLOBAL, "15"), + "LOCKDIRECTORY" : ("lock directory", SambaParmString, P_GLOBAL, "/var/lib/samba"), + "LOGONHOME" : ("logon home", SambaParmString, P_GLOBAL, "\\%N\%U"), + "MINPASSWDLENGTH" : ("min password length", SambaParmString, P_GLOBAL, "5"), + "CLIENTPLAINTEXTAUTH" : ("client plaintext auth", SambaParmBool, P_GLOBAL, "Yes"), + "CSCPOLICY" : ("csc policy", SambaParmString, P_LOCAL, "manual"), + "ADDSHARECOMMAND" : ("add share command", SambaParmString, P_GLOBAL, ""), + "MANGLINGCHAR" : ("mangling char", SambaParmString, P_LOCAL, "~"), + "DIRECTORY" : ("path", SambaParmString, P_LOCAL, ""), + "DEBUGTIMESTAMP" : ("debug timestamp", SambaParmBool, P_GLOBAL, "Yes"), + "ALLOWHOSTS" : ("hosts allow", SambaParmString, P_LOCAL, ""), + "FSTYPE" : ("fstype", SambaParmString, P_LOCAL, "NTFS"), + "BLOCKINGLOCKS" : ("blocking locks", SambaParmBool, P_LOCAL, "Yes"), + "LDAPSSL" : ("ldap ssl", SambaParmString, P_GLOBAL, ""), + "PAMPASSWORDCHANGE" : ("pam password change", SambaParmBool, P_GLOBAL, "No"), + "GUESTOK" : ("guest ok", SambaParmBool, P_LOCAL, "No"), + "DEFAULTDEVMODE" : ("default devmode", SambaParmBool, P_LOCAL, "No"), + "MAXDISKSIZE" : ("max disk size", SambaParmString, P_GLOBAL, "0"), + "ADDMACHINESCRIPT" : ("add machine script", SambaParmString, P_GLOBAL, ""), + "MANGLEPREFIX" : ("mangle prefix", SambaParmString, P_GLOBAL, "1"), + "DISABLENETBIOS" : ("disable netbios", SambaParmBool, P_GLOBAL, "No"), + "LOGONPATH" : ("logon path", SambaParmString, P_GLOBAL, "\\%N\%U\profile"), + "IDMAPBACKEND" : ("idmap backend", SambaParmString, P_GLOBAL, ""), + "SHORTPRESERVECASE" : ("short preserve case", SambaParmBool, P_LOCAL, "Yes"), + "CUPSSERVER" : ("cups server", SambaParmString, P_GLOBAL, ""), + "NTPIPESUPPORT" : ("nt pipe support", SambaParmBool, P_GLOBAL, "Yes"), + "READONLY" : ("read only", SambaParmBool, P_LOCAL, "Yes"), + "MACHINEPASSWORDTIMEOUT" : ("machine password timeout", SambaParmString, P_GLOBAL, "604800"), + "PIDDIRECTORY" : ("pid directory", SambaParmString, P_GLOBAL, "/var/run"), + "PUBLIC" : ("guest ok", SambaParmBool, P_LOCAL, "No"), + "DEBUGPID" : ("debug pid", SambaParmBool, P_GLOBAL, "No"), + "GUESTONLY" : ("guest only", SambaParmBool, P_LOCAL, "No"), + "DELETEGROUPSCRIPT" : ("delete group script", SambaParmString, P_GLOBAL, ""), + "CUPSOPTIONS" : ("cups options", SambaParmString, P_LOCAL, ""), + "PASSWDCHAT" : ("passwd chat", SambaParmString, P_GLOBAL, "*new*password* %n\n *new*password* %n\n *changed*"), + "STRICTLOCKING" : ("strict locking", SambaParmString, P_LOCAL, "Yes"), + "TEMPLATEHOMEDIR" : ("template homedir", SambaParmString, P_GLOBAL, "/home/%D/%U"), + "WINBINDGID" : ("idmap gid", SambaParmString, P_GLOBAL, ""), + "INHERITPERMISSIONS" : ("inherit permissions", SambaParmBool, P_LOCAL, "No"), + "TIMESERVER" : ("time server", SambaParmBool, P_GLOBAL, "No"), + "BROWSELIST" : ("browse list", SambaParmBool, P_GLOBAL, "Yes"), + "HOSTNAMELOOKUPS" : ("hostname lookups", SambaParmBool, P_GLOBAL, "No"), + "DOSFILETIMERESOLUTION" : ("dos filetime resolution", SambaParmBool, P_LOCAL, "No"), + "CREATEMASK" : ("create mask", SambaParmString, P_LOCAL, "0744"), + "WINSHOOK" : ("wins hook", SambaParmString, P_GLOBAL, ""), + "DEFAULTCASE" : ("default case", SambaParmString, P_LOCAL, "lower"), + "PATH" : ("path", SambaParmString, P_LOCAL, ""), + "SHOWADDPRINTERWIZARD" : ("show add printer wizard", SambaParmBool, P_GLOBAL, "Yes"), + "WINSPARTNERS" : ("wins partners", SambaParmString, P_GLOBAL, ""), + "ENABLEPRIVILEGES" : ("enable privileges", SambaParmBool, P_GLOBAL, "No"), + "VFSOBJECTS" : ("vfs objects", SambaParmString, P_LOCAL, ""), + "STRICTALLOCATE" : ("strict allocate", SambaParmBool, P_LOCAL, "No"), + "PREEXEC" : ("preexec", SambaParmString, P_LOCAL, ""), + "WINSSUPPORT" : ("wins support", SambaParmBool, P_GLOBAL, "No"), + "HOSTMSDFS" : ("host msdfs", SambaParmBool, P_GLOBAL, "No"), + "AFSTOKENLIFETIME" : ("afs token lifetime", SambaParmString, P_GLOBAL, "604800"), + "PRINTOK" : ("printable", SambaParmBool, P_LOCAL, "No"), + "TEMPLATEPRIMARYGROUP" : ("template primary group", SambaParmString, P_GLOBAL, "nobody"), + "PASSWDPROGRAM" : ("passwd program", SambaParmString, P_GLOBAL, ""), + "SYNCALWAYS" : ("sync always", SambaParmBool, P_LOCAL, "No"), + "QUEUEPAUSECOMMAND" : ("queuepause command", SambaParmString, P_LOCAL, ""), + "BINDINTERFACESONLY" : ("bind interfaces only", SambaParmBool, P_GLOBAL, "No"), + "MAXWINSTTL" : ("max wins ttl", SambaParmString, P_GLOBAL, "518400"), + "GETWDCACHE" : ("getwd cache", SambaParmBool, P_GLOBAL, "Yes"), + "MAGICOUTPUT" : ("magic output", SambaParmString, P_LOCAL, ""), + "ADMINUSERS" : ("admin users", SambaParmString, P_LOCAL, ""), + "DIRECTORYMODE" : ("directory mask", SambaParmString, P_LOCAL, "0755"), + "CLIENTSIGNING" : ("client signing", SambaParmString, P_GLOBAL, "auto"), + "PASSDBBACKEND" : ("passdb backend", SambaParmString, P_GLOBAL, "smbpasswd"), + "CASESIGNAMES" : ("case sensitive", SambaParmString, P_LOCAL, "Auto"), + "SETQUOTACOMMAND" : ("set quota command", SambaParmString, P_GLOBAL, ""), + "LPQCOMMAND" : ("lpq command", SambaParmString, P_LOCAL, ""), + "SERVERSTRING" : ("server string", SambaParmString, P_GLOBAL, "Samba 3.0.11pre2-SVN-build-4840"), + "DEFAULTSERVICE" : ("default service", SambaParmString, P_GLOBAL, ""), + "WINBINDUSEDEFAULTDOMAIN": ("winbind use default domain", SambaParmBool, P_GLOBAL, "No"), + "INTERFACES" : ("interfaces", SambaParmString, P_GLOBAL, ""), + "ROOTDIR" : ("root directory", SambaParmString, P_GLOBAL, ""), + "ADDUSERSCRIPT" : ("add user script", SambaParmString, P_GLOBAL, ""), + "CLIENTNTLMV2AUTH" : ("client NTLMv2 auth", SambaParmBool, P_GLOBAL, "No"), + "FORCEUNKNOWNACLUSER" : ("force unknown acl user", SambaParmBool, P_LOCAL, "No"), + "MANGLEDMAP" : ("mangled map", SambaParmString, P_LOCAL, ""), + "NTLMAUTH" : ("ntlm auth", SambaParmBool, P_GLOBAL, "Yes"), + "INHERITACLS" : ("inherit acls", SambaParmBool, P_LOCAL, "No"), + "HOSTSEQUIV" : ("hosts equiv", SambaParmString, P_GLOBAL, ""), + "ALLOWTRUSTEDDOMAINS" : ("allow trusted domains", SambaParmBool, P_GLOBAL, "Yes"), + "MINPASSWORDLENGTH" : ("min password length", SambaParmString, P_GLOBAL, "5"), + "USERS" : ("username", SambaParmString, P_LOCAL, ""), + "PRELOAD" : ("preload", SambaParmString, P_GLOBAL, ""), + "DEBUGUID" : ("debug uid", SambaParmBool, P_GLOBAL, "No"), + "CHANGESHARECOMMAND" : ("change share command", SambaParmString, P_GLOBAL, ""), + "BROWSABLE" : ("browseable", SambaParmBool, P_LOCAL, "Yes"), + "ENHANCEDBROWSING" : ("enhanced browsing", SambaParmBool, P_GLOBAL, "Yes"), + "PANICACTION" : ("panic action", SambaParmString, P_GLOBAL, ""), + "LDAPMACHINESUFFIX" : ("ldap machine suffix", SambaParmString, P_GLOBAL, ""), + "UPDATEENCRYPTED" : ("update encrypted", SambaParmBool, P_GLOBAL, "No"), + "MAXTTL" : ("max ttl", SambaParmString, P_GLOBAL, "259200"), + "WRITABLE" : ("read only", SambaParmBoolRev, P_LOCAL, "Yes"), + "SHAREMODES" : ("share modes", SambaParmBool, P_LOCAL, "Yes"), + "REMOTEBROWSESYNC" : ("remote browse sync", SambaParmString, P_GLOBAL, ""), + "STOREDOSATTRIBUTES" : ("store dos attributes", SambaParmBool, P_LOCAL, "No"), + "CLIENTSCHANNEL" : ("client schannel", SambaParmString, P_GLOBAL, "Auto"), + "WRITELIST" : ("write list", SambaParmString, P_LOCAL, ""), + "ADDGROUPSCRIPT" : ("add group script", SambaParmString, P_GLOBAL, ""), + "OPLOCKBREAKWAITTIME" : ("oplock break wait time", SambaParmString, P_GLOBAL, "0"), + "TIMEOFFSET" : ("time offset", SambaParmString, P_GLOBAL, "0"), + "LDAPDELETEDN" : ("ldap delete dn", SambaParmBool, P_GLOBAL, "No"), + "AFSSHARE" : ("afs share", SambaParmBool, P_LOCAL, "No"), + "ROOT" : ("root directory", SambaParmString, P_GLOBAL, ""), + "NAMERESOLVEORDER" : ("name resolve order", SambaParmString, P_GLOBAL, "lmhosts wins host bcast"), +} +##### end of smbparm.y ########################################## +################################################################# diff --git a/examples/scripts/users_and_groups/adduserstogroups.pl b/examples/scripts/users_and_groups/adduserstogroups.pl new file mode 100755 index 0000000000..6759428774 --- /dev/null +++ b/examples/scripts/users_and_groups/adduserstogroups.pl @@ -0,0 +1,166 @@ +#!/usr/bin/perl + +# +# adduserstogroups.pl +# +# add single or continuously numbered domain users +# to a given single group or list of groups +# +# Copyright (C) Michael Adam <obnox@samba.org> 2007 +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see <http://www.gnu.org/licenses/>. +# + +# +# WARNING: This script is still rather crude. +# + +use strict; +use Getopt::Std; + +my $net_cmd = "net"; + +# defaults: + +my $server; +my $num_members = 1; +my $startmem; # if empty, don't add numbers to member prefix +my $member_prefix; # name prefix for member +my $num_groups = 1; +my $startgroup; # if empty, don't add numbers to group prefix +my $group_prefix; # name prefix for group +my $path; # path to rpcclient command +my $net_path = $net_cmd; +my $creds; + +sub usage { + print "USAGE: $0 [-h] -S server -U user\%pass \\\n" + . "\t-m member [-s startmem] [-n nummem] \\\n" + . "\t-g group [-G startgroup] [-N numgroups] \\\n" + . "\t[-P path]\n"; +} + +# parse commandline: + +my %options = (); +getopts("U:S:m:s:n:g:G:N:P:h", \%options); + +if (exists($options{h})) { + usage(); + exit 0; +} + +if (exists($options{g})) { + $group_prefix = $options{g}; +} +else { + print "ERROR: mandatory argument '-g' missing\n"; + usage(); + exit 1; +} + +if (exists($options{U})) { + $creds = "-U $options{U}"; + if ($creds !~ '%') { + print "ERROR: you need to specify credentials in the form -U user\%pass\n"; + usage(); + exit 1; + } +} +else { + print "ERROR: mandatory argument '-U' missing\n"; + usage(); + exit 1; +} + +if (exists($options{S})) { + $server = $options{S}; +} +else { + print "ERROR: madatory argument '-S' missing\n"; + usage(); + exit 1; +} + +if (exists($options{s})) { + $startmem = $options{s}; +} + +if (exists($options{n})) { + $num_members = $options{n}; +} + +if (exists($options{m})) { + $member_prefix = $options{m}; +} +else { + print "ERROR: mandatory argument '-m' missing\n"; + usage(); + exit 1; +} + +if (exists($options{G})) { + $startgroup = $options{G}; +} + +if (exists($options{N})) { + $num_groups = $options{N}; +} + +if (exists($options{P})) { + $path = $options{p}; + $net_path = "$path/$net_cmd"; +} + +if (@ARGV) { + print "ERROR: junk on the command line ('" . join(" ", @ARGV) . "')...\n"; + usage(); + exit 1; +} + +# utility functions: + +sub do_add { + my $member_name = shift; + my $group_name = shift; + print "adding member $member_name to group $group_name\n"; + system("$net_path rpc -I $server ".$creds." group addmem $group_name $member_name"); +} + +sub add_group_loop { + my $member_name = shift; + + if ("x$startgroup" eq "x") { + do_add($member_name, $group_prefix); + } + else { + for (my $groupnum = 1; $groupnum <= $num_groups; ++$groupnum) { + do_add($member_name, + sprintf("%s%.05d", $group_prefix, $startgroup + $groupnum - 1)); + } + } +} + + +# main: + +if ("x$startmem" eq "x") { + add_group_loop($member_prefix); +} +else { + for (my $memnum = 1; $memnum <= $num_members; ++$memnum) { + add_group_loop(sprintf("%s%.05d", $member_prefix, $startmem + $memnum - 1)); + } +} + diff --git a/examples/scripts/users_and_groups/createdomobj.pl b/examples/scripts/users_and_groups/createdomobj.pl new file mode 100755 index 0000000000..60f34b84f2 --- /dev/null +++ b/examples/scripts/users_and_groups/createdomobj.pl @@ -0,0 +1,157 @@ +#!/usr/bin/perl + +# +# createdomobj.pl +# +# create single or continuously numbered domain +# users/groups/aliases via rpc +# +# Copyright (C) Michael Adam <obnox@samba.org> 2007 +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see <http://www.gnu.org/licenses/>. +# + +# +# WARNING: This script is still rather crude. +# + +use strict; +use Getopt::Std; + + +my $target_type = "group"; # what type of object to create +my $rpc_cmd = "createdom".$target_type; +my $rpccli_cmd = "rpcclient"; + +# defaults: + +my $server; +my $num_targets = 1; +my $startnum; # if empty, don't add numbers to prefix +my $prefix = $target_type; # name-prefix +my $path; # path to rpcclient command +my $rpccli_path = $rpccli_cmd; +my $creds; + +sub usage { + print "USAGE: $0 [-h] -S server -U user\%pass [-p prefix] \\\n" + . "\t[-t {alias|group|user}] [-s startnum] [-n numobjs] [-P path] \n"; +} + +# parse commandline: + +my %options = (); +getopts("U:t:S:s:n:p:P:h", \%options); + +if (exists($options{h})) { + usage(); + exit 0; +} + +if (exists($options{t})) { + $target_type = $options{t}; + if ($target_type !~ /^(alias|user|group)$/) { + print "ERROR: invalid target type given\n"; + usage(); + exit 1; + } + $rpc_cmd = "createdom".$target_type; +} + +if (exists($options{U})) { + $creds = "-U $options{U}"; + if ($creds !~ '%') { + print "ERROR: you need to specify credentials in the form -U user\%pass\n"; + usage(); + exit 1; + } +} +else { + print "ERROR: mandatory argument '-U' missing\n"; + usage(); + exit 1; +} + +if (exists($options{S})) { + $server = $options{S}; +} +else { + print "ERROR: madatory argument '-S' missing\n"; + usage(); + exit 1; +} + +if (exists($options{s})) { + $startnum = $options{s}; +} + +if (exists($options{n})) { + $num_targets = $options{n}; +} + +if (exists($options{p})) { + $prefix = $options{p}; +} + +if (exists($options{P})) { + $path = $options{p}; + $rpccli_path = "$path/$rpccli_cmd"; +} + +if (@ARGV) { + print "ERROR: junk on the command line ('" . join(" ", @ARGV) . "')...\n"; + usage(); + exit 1; +} + +# utility functions: + +sub open_rpc_pipe { + print "opening rpc pipe\n"; + open(IPC, "| $rpccli_cmd $server $creds -d0") or + die "error opening rpc pipe."; +} + +sub close_rpc_pipe { + print "closing rpc pipe\n"; + close(IPC); +} + +sub do_create { + my $target_name = shift; + print "creating $target_type $target_name\n"; + print IPC "$rpc_cmd $target_name\n"; +} + +# main: + +open_rpc_pipe(); + +if ("x$startnum" eq "x") { + do_create($prefix); +} +else { + for (my $num = 1; $num <= $num_targets; ++$num) { + do_create(sprintf "%s%.05d", $prefix, $startnum + $num - 1); + if (($num) % 500 == 0) { + printf("500 ".$target_type."s created\n"); + close_rpc_pipe(); + sleep 2; + open_rpc_pipe(); + } + } +} + +close_rpc_pipe(); + diff --git a/examples/scripts/wins_hook/README b/examples/scripts/wins_hook/README new file mode 100644 index 0000000000..1147f57e22 --- /dev/null +++ b/examples/scripts/wins_hook/README @@ -0,0 +1,8 @@ +This is an example script for doing dynamic DNS updates from the WINS +database. You use this by putting the full path to the script in the +"wins hook" option in smb.conf. Remember to mark the script executable +and to set the right domain at the top of the script. + +See the BIND documentation for how to enable dynamic DNS +updates. Remember to restrict the updates as far as you can to reduce +the security risks inherent in dynamic DNS. diff --git a/examples/scripts/wins_hook/dns_update b/examples/scripts/wins_hook/dns_update new file mode 100644 index 0000000000..a4c1a79ab9 --- /dev/null +++ b/examples/scripts/wins_hook/dns_update @@ -0,0 +1,94 @@ +#!/bin/sh +# +# Example script for "wins hook". This attempts to update the DNS with +# new A records for the NETBIOS name that Samba passes us. We do this +# the simple way, by deleting all DNS records for the name and then +# readding all the expected 'A' records. +# +# Written by Stephen Rothwell <sfr@linuxcare.com> +# + +# +# Configurable things +# +# The domain in which to create names +# YOU MUST CHANGE THIS +# N.B. include the trailing dot +# +# It is a good idea to use a subdomain of your primary domain to ensure +# that rogue machines can't take over (or delete) important names on +# your network. +DOMAIN=wins.example.com. + +# +# The DNS TTL to give the records (in seconds) +# +TTL=3600 +# +# NETBIOS name types that we want to create DNS records for: +# 20 is server +# 00 is workstation +# 03 is user +# +USEFUL_TYPES="20 00 03" +# +# The name of a cache file to use to avoid continual updates +# of the same name and IP addresses. If you comment this out +# then the cache is not kept at all. +# +#CACHE_FILE=/usr/local/samba/var/wins_update.cache + +if [ $# -lt 4 ]; then + echo "Usage: $0 op name type ttl [ip_addr ...]" 1>&2 + echo " op is one of add, refresh, delete" 1>&2 + echo " name is the NETBIOS name" 1>&2 + echo " type is the NETBIOS name type" 1>&2 + echo " ttl is the NETBIOS time to live" 1>&2 + echo " ip_addr's are the remaining IP addresses for this name" 1>&2 + exit 1 +fi + +NSUPDATE=`which nsupdate` +[ -x "$NSUPDATE" ] || NSUPDATE=/usr/bin/nsupdate +[ -x "$NSUPDATE" ] || NSUPDATE=/sbin/nsupdate +[ -x "$NSUPDATE" ] || NSUPDATE=/usr/sbin/nsupdate +[ -x "$NSUPDATE" ] || { + echo "Cannot find nsupdate." 1>&2 + exit 1 +} + +OP=$1 +NAME=$2 +TYPE=$3 +WINS_TTL=$4 +shift 4 +IP_ADDRS="$@" + +do_update=0 +for i in $USEFUL_TYPES +do + [ "$TYPE" = "$i" ] && do_update=1 +done +[ $do_update = 1 ] || exit 0 + +if [ -n "$CACHE_FILE" ]; then + if [ -r "$CACHE_FILE" ]; then + fgrep -q -x -i "$NAME $IP_ADDRS" "$CACHE_FILE" && + exit 0 + grep -v -i "^$NAME " "$CACHE_FILE" >"$CACHE_FILE".$$ + fi + echo "$NAME $IP_ADDRS" >>"$CACHE_FILE".$$ + mv "$CACHE_FILE" "$CACHE_FILE".old 2>/dev/null + mv "$CACHE_FILE".$$ "$CACHE_FILE" +fi + +{ + echo update delete $NAME.$DOMAIN + for i in $IP_ADDRS + do + echo update add $NAME.$DOMAIN $TTL A $i + done + echo +} 2>/dev/null | $NSUPDATE >/dev/null 2>&1 & + +exit 0 |