dsdb: Ensure "authenticated users" is processed for group memberships
[Samba/gebeck_regimport.git] / examples / scripts / shares / python / modify_samba_config.py
blob88b3fcb39445df0e04094b19a3dfb500dd8f6f36
1 #!/usr/bin/env python
2 ######################################################################
3 ##
4 ## Simple add/delete/change share command script for Samba
5 ##
6 ## Copyright (C) Gerald Carter 2004.
7 ##
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; either version 3 of the License, or
11 ## (at your option) any later version.
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details.
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
21 ######################################################################
23 import sys, os
24 from SambaConfig import SambaConf
27 ## ##
28 ## check the command line args ##
29 ## ##
30 delete_mode = False
31 if len(sys.argv) == 3:
32 delete_mode = True
33 print "Deleting share..."
34 elif len(sys.argv) == 5:
35 print "Adding/Updating share..."
36 else:
37 print "Usage: %s configfile share [path] [comments]" % sys.argv[0]
38 sys.exit(1)
41 ## ##
42 ## read and parse the config file ##
43 ## ##
45 confFile = SambaConf()
47 confFile.ReadConfig( sys.argv[1] )
48 if not confFile.valid:
49 exit( 1 )
51 if delete_mode:
52 if not confFile.isService( sys.argv[2] ):
53 sys.stderr.write( "Asked to delete non-existent service! [%s]\n" % sys.argv[2] )
54 sys.exit( 1 )
56 confFile.DelService( sys.argv[2] )
57 else:
58 ## make the path if it doesn't exist. Bail out if that fails
59 if ( not os.path.isdir(sys.argv[3]) ):
60 try:
61 os.makedirs( sys.argv[3] )
62 os.chmod( sys.argv[3], 0777 )
63 except os.error:
64 sys.exit( 1 )
66 ## only add a new service -- if it already exists, then
67 ## just set the options
68 if not confFile.isService( sys.argv[2] ):
69 confFile.AddService( sys.argv[2], ['##', '## Added by modify_samba_config.py', '##'] )
70 confFile.SetServiceOption( sys.argv[2], "path", sys.argv[3] )
71 confFile.SetServiceOption( sys.argv[2], "comment", sys.argv[4] )
72 confFile.SetServiceOption( sys.argv[2], "read only", "no" )
74 ret = confFile.Flush()
76 sys.exit( ret )