-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathremove-samba-section.py
147 lines (110 loc) · 3.61 KB
/
remove-samba-section.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
import os
import sys
from configobj import ConfigObj
import ldap
import commands
from pprint import pprint
import pyinotify
CONF="/etc/max-control/conf.inc.php"
SMB_CONF="/etc/samba/max-control.conf"
SHARED_DIR="/home/samba/groups/"
TO_ADD={'isos': {'comment': 'Archivos ISO',
'path': '/home/samba/shares/isos',
'valid users': ['@"Teachers"', '@"Domain Users"'],
'read list': ['@"Teachers"', '@"Domain Users"'],
'write list': '@"Teachers"',
'admin users': '@"Domain Admins"',
'read only': 'No',
'browseable': 'Yes',
'force create mode': '0664',
'force directory mode': '0664',
}
}
NOT_VALID_KEYS=['global', 'netlogon', 'profiles', 'homes', 'ebox-internal-backups', 'ebox-quarantine', 'print$']
def read_conf(varname):
f=open(CONF, 'r')
data=f.readlines()
f.close()
for line in data:
if line.startswith('define') and varname in line:
if len(line.split('"')) >= 3:
return line.split('"')[3]
if len(line.split("'")) >= 3:
return line.split("'")[3]
return ''
GROUPS=read_conf('LDAP_OU_GROUPS')
DOMAIN=read_conf('LDAP_DOMAIN')
def getGoupsShares():
sharedgroups=[]
l = ldap.initialize('ldap://localhost:389')
results = l.search_s(GROUPS,ldap.SCOPE_SUBTREE,'(cn=*)',['cn', 'memberUid', 'sambaGroupType', 'gidNumber'])
sharedgroups=[]
for group in results:
if "Teachers" in group[0]:
continue
if int(group[1]['gidNumber'][0]) < 2000:
continue
if int(group[1]['sambaGroupType'][0]) != 2:
continue
groupname=group[1]['cn'][0]
# if not os.path.isdir( os.path.join(SHARED_DIR, groupname) ):
# continue
sharedgroups.append(groupname)
return sharedgroups
print getGoupsShares()
sys.exit(0)
def waitForChanges(fname):
print "waitForChanges() fname=%s"%fname
res=commands.getoutput("inotifywait -e modify %s"%fname)
#print res
def loadFile(fname):
smb=ConfigObj('smb.conf')
return smb
def printConf(smb):
for section in smb:
print "[%s]"%section
if not smb[section]:
continue
for sub in smb[section]:
if type(smb[section][sub]) == type( [] ):
print " %s = %s" %(sub, ", ".join(smb[section][sub]))
else:
print " %s = %s" %(sub, smb[section][sub])
print "\n\n"
def diffConfs(old, new):
deleted={}
added={}
for section in old:
if section in new:
continue
else:
deleted[section]=old[section]
for section in new:
if section in old:
continue
else:
added[section]=new[section]
print "DELETED ",
pprint(deleted)
print "ADDED ",
pprint(added)
def callback(event):
if event.pathname != '/etc/samba/smb.conf':
return
if event.maskname != 'IN_MOVED_TO':
return
print event
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm, default_proc_fun=callback)
wm.add_watch('/etc/samba', pyinotify.ALL_EVENTS, rec=True, auto_add=True)
notifier.loop()
#notifier.loop(daemonize=True,
# pid_file='/var/run/max-control-samba.pid',
# force_kill=True,
# stdout='/var/log/max-control-samba.log')
#old=loadFile('smb.conf')
#print old.keys()
#waitForChanges('smb.conf')
#new=loadFile('smb.conf')
#diffConfs(old, new)