This file is indexed.

/usr/share/sadms-2.0.15/globs.py is in sadms 2.0.15.repack-0ubuntu2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
#!/usr/bin/python
# -*-coding: UTF-8 -*-
# bbou@ac-toulouse.fr
# GPL license
# 2006-11-16 10:31:38  
# globs.py

import pygtk
pygtk.require("2.0")
from gtk import *
import gtk.glade
import string
import re
import stat

import runner

#######################################################################
#	GLOBALS
#######################################################################

sysSetting={
	'testparm':'testparm -vs 2> /dev/null',
	'getSep':"testparm -sv 2> /dev/null | grep '^[[:space:]]*winbind separator[[:space:]]*=' | awk '{print $4}'",
	'getDomain':"testparm -sv 2> /dev/null | grep '^[[:space:]]workgroup[[:space:]]*=' | awk '{print $3}'",
	'getUidRange':"testparm -sv 2> /dev/null | grep '^[[:space:]]idmap uid[[:space:]]*=' | awk '{print $4}'",
	'getGidRange':"testparm -sv 2> /dev/null | grep '^[[:space:]]idmap gid[[:space:]]*=' | awk '{print $4}'",
	'docs':{'default':'file:///usr/share/doc/sadms-%s/%s',
		'redhat':'file:///usr/share/doc/sadms-%s/%s',
		'debian':'file:///usr/share/doc/sadms/%s',
		'suse':'file:///usr/share/doc/packages/sadms/%s',
		'mandriva':'file:///usr/share/doc/sadms-%s/%s'},
	'browser':{'default':'/usr/bin/firefox',
		'redhat':'/usr/bin/firefox',
		'debian':'/usr/bin/firefox',
		'suse':'/usr/bin/firefox',
		'mandriva':'/usr/bin/mozilla-firefox'},
	'pidof':{'default':'/sbin/pidof',
		'redhat':'/sbin/pidof',
		'debian':'/bin/pidof',
		'suse':'/sbin/pidof',
		'mandriva':'/sbin/pidof'},

	'getUsers':"getent passwd | grep -v '^$' | cut -f 1 -d ':' | sort",
	'getGroups':"getent group | grep -v '^$' | cut -f 1 -d ':' | sort",
	'getUserId':"id -u %USER%",
	'getGroupId':"getent group \"%GROUP%\" 2> /dev/null | awk 'BEGIN{FS=\":\"}{print $3}'",
	'signalSmb':'kill -HUP `pidof smbd` 2> /dev/null',
	'signalNmb':'kill -HUP `pidof nmbd` 2> /dev/null',
	'signalWinbind':'kill -HUP `pidof winbindd` 2> /dev/null',
	'readFile':'cat "%FILE%"',
	'writeFile':'cat - > "%FILE%" <<EOF\n%TEXT%\nEOF',
	'exists':'sh -c \'if [ -e "%FSOBJECT%" ]; then echo true; else echo false; fi\'',
	'getVersion':'cat version | head -n 1',
	'getDistribution':'sh -c \'if [ -f /etc/debian_version ]; then echo "debian"; else if [ -f /etc/SuSE-release ]; then echo "suse"; else if [ -e /etc/mandrake-release -o -e /etc/mandriva-release ]; then echo "mandriva"; else if [ -e /etc/redhat-release ]; then echo "redhat"; else echo "default"; fi; fi; fi; fi\'',
}

definedProps={}

#######################################################################
#	GlobalsManager
#######################################################################

class SubjectChooser:

	IMAGE=0
	TEXT=1

	USER=0
	GROUP=1

	pixbufs=[]

	def __init__(self,dialog,listview):
		self.dialog=dialog
		self.listview=listview
		
		# header
		self.listview.set_headers_visible(False)

		# selection
		self.listview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)

		# model
		self.model=ListStore(gtk.gdk.Pixbuf,str)
		self.listview.set_model(self.model)

		# columns
		column=gtk.TreeViewColumn('')
		cell=gtk.CellRendererPixbuf()
		column.pack_start(cell,True)
		column.add_attribute(cell,'pixbuf',SubjectChooser.IMAGE)
		self.listview.append_column(column)

		column=gtk.TreeViewColumn('subject')
		cell=gtk.CellRendererText()
		column.pack_start(cell,True)
		column.add_attribute(cell,'text',SubjectChooser.TEXT)
		self.listview.append_column(column)

		# images
		if SubjectChooser.pixbufs==[]:
			SubjectChooser.pixbufs=self.setupImages()
                return
        
	def setupImages(self):
		imageFile=['user-hidden.png','group-hidden.png']
		pixbufs=[]
		for i in range(len(imageFile)):
        		pixbufs.append(gtk.gdk.pixbuf_new_from_file('pixmaps/'+imageFile[i]))
		return pixbufs

	def clear(self):
		self.model.clear()
		return

	def set(self,subjects,subjecttype):
		for i in subjects:
			self.model.append([SubjectChooser.pixbufs[subjecttype],i])
		return

	def getSelection(self):
		selection=self.listview.get_selection()
		(model,pathlist)=selection.get_selected_rows()
		return [model[model.get_iter(path)][SubjectChooser.TEXT] for path in pathlist]

	# wrappers 
	
	def run(self):
		return self.dialog.run()

	def hide(self):
		self.dialog.hide()
		return

#######################################################################

class BooleanProperty:

	def __init__(self,defineToggle,toggle,tag):
		self.dirty=None
		self.defineToggle=defineToggle
		self.toggle=toggle
		self.tag=tag
		self.defineToggle.set_data('master',self)
		self.toggle.set_data('master',self)
		definedProps[tag]=self
		return

	def set(self,value):
		#print '%s=%s' %(self.tag,value)
		if value==None:
			self.defineToggle.set_active(False)
			self.toggle.set_active(False)
		else:
			self.defineToggle.set_active(True)
			if value=='Yes':
				self.toggle.set_active(True)
			else:
				self.toggle.set_active(False)
		self.dirty=False
		return
		
	def get(self):
		return self.defineToggle.get_active(),self.toggle.get_active()
		
class MultipleProperty:

	def __init__(self,defineToggle,combo,tag):
		self.dirty=None
		self.defineToggle=defineToggle
		self.combo=combo
		self.tag=tag
		self.defineToggle.set_data('master',self)
		self.combo.set_data('master',self)
		definedProps[tag]=self
		return
		
	def set(self,value):
		#print '%s=<%s>' %(self.tag,value)
		if value==None:
			self.defineToggle.set_active(False)
		else:
			self.defineToggle.set_active(True)
			i=self.find(value)
			if i==None:
				self.combo.prepend_text(value)
				self.combo.set_active(0)
			else:
				self.combo.set_active(i)
		self.dirty=False
		return

	def get(self):
		value=self.combo.get_active_text()
		if value=='<none>':
			value=''
		return self.defineToggle.get_active(),value
		
	def find(self,value):
		if value=='':
			value='<none>'
		model=self.combo.get_model()
		i=model.get_iter_first()
		while i:
			if model.get_value(i,0)==value:
				return model.get_path(i)[0]
			i=model.iter_next(i)
		return None

class UsersProperty(MultipleProperty):

	def __init__(self,defineToggle,combo,tag,users):
		MultipleProperty.__init__(self,defineToggle,combo,tag)
		for u in users:
			self.combo.append_text(u)
		return

class StringProperty:

	def __init__(self,defineToggle,entry,tag):
		self.dirty=None
		self.defineToggle=defineToggle
		self.entry=entry
		self.tag=tag
		self.defineToggle.set_data('master',self)
		self.entry.set_data('master',self)
		definedProps[tag]=self
		return
		
	def set(self,value):
		#print '%s=<%s>' %(self.tag,value)
		if value==None:
			self.defineToggle.set_active(False)
		else:
			self.defineToggle.set_active(True)
			self.entry.set_text(value)
		self.dirty=False
		return
		
	def get(self):
		return self.defineToggle.get_active(),self.entry.get_text()
		
class MultipleUsersProperty(StringProperty):

	def __init__(self,defineToggle,entry,button,tag):
		StringProperty.__init__(self,defineToggle,entry,tag)
		self.button=button
		self.button.set_data('master',self)
		return

class MaskProperty(StringProperty):

	def __init__(self,defineToggle,entry,button,tag):
		StringProperty.__init__(self,defineToggle,entry,tag)
		self.button=button
		self.button.set_data('master',self)
		return

	def intToMode(self,m):
		#print oct(m)
		ur=m & stat.S_IRUSR!=0
		uw=m & stat.S_IWUSR!=0
		ux=m & stat.S_IXUSR!=0
		gr=m & stat.S_IRGRP!=0
		gw=m & stat.S_IWGRP!=0
		gx=m & stat.S_IXGRP!=0
		wr=m & stat.S_IROTH!=0
		ww=m & stat.S_IWOTH!=0
		wx=m & stat.S_IXOTH!=0
		return ur,uw,ux,gr,gw,gx,wr,ww,wx

	def modeToInt(self,ur,uw,ux,gr,gw,gx,wr,ww,wx):
		mode=0
		if ur:
			mode=mode | stat.S_IRUSR
		if uw:
			mode=mode | stat.S_IWUSR
		if ux:
			mode=mode | stat.S_IXUSR
		if gr:
			mode=mode | stat.S_IRGRP
		if gw:
			mode=mode | stat.S_IWGRP
		if gx:
			mode=mode | stat.S_IXGRP
		if wr:
			mode=mode | stat.S_IROTH
		if ww:
			mode=mode | stat.S_IWOTH
		if wx:
			mode=mode | stat.S_IXOTH
		return mode

class RangeProperty:

	def __init__(self,defineToggle,spinFrom,spinTo,tag):
		self.dirty=None
		self.defineToggle=defineToggle
		self.spinFrom=spinFrom
		self.spinTo=spinTo
		self.tag=tag
		self.defineToggle.set_data('master',self)
		self.spinFrom.set_data('master',self)
		self.spinTo.set_data('master',self)
		definedProps[tag]=self
		return
		
	def set(self,value):
		print "set ",value
		if value==None:
			self.defineToggle.set_active(False)
		else:
			self.defineToggle.set_active(True)
			r=value.split('-')
			if len(r)==2:
				self.spinFrom.set_value(float(r[0]))
				self.spinTo.set_value(float(r[1]))
			else:
				self.spinFrom.set_value(500)
				self.spinTo.set_value(32000)
		self.dirty=False
		return
		
	def get(self):
		return self.defineToggle.get_active(),'%d-%d' % (self.spinFrom.get_value(),self.spinTo.get_value())

#######################################################################

class GlobalsManager:
	
	def __init__(self):
		self.runner=runner.GtkRunner()
		self.uidRange=[]
		self.gidRange=[]
		
		prefix='%s%s' % (self.getDomain(),self.getSep())
		self.users=self.getUsers()
		self.users=[u.replace(prefix,'',1) for u in self.users]
		self.groups=self.getGroups()
		self.groups=[g.replace(prefix,'',1) for g in self.groups]
		self.nisGroups=['@'+g for g in self.groups]
		self.usersGroups=self.users+self.nisGroups

		handlers={
			'on_destroy':			self.exit,
			'on_ok_clicked':		self.exitOk,
			'on_cancel_clicked':		self.exit,
			'on_apply_clicked':		self.applyGlobs,

			'on_browseUsers_clicked':	self.browseUsers,
			'on_browseMask_clicked':	self.browseMask,
			'on_refresh_clicked':		self.forceRefresh,
			'on_about_activate':		self.about,
			'on_help_clicked':		self.help,

			'on_checkDefine_toggled':	self.checkDefineToggled,
			'on_check_toggled':		self.checkToggled,
			'on_entry_changed':		self.entryChanged,
			'on_combo_changed':		self.comboChanged,
			'on_spin_changed':		self.spinChanged,
		}

		self.widgets=gtk.glade.XML('globs.glade')
		self.widgets.signal_autoconnect(handlers)
		self.dialog=self['globals']
		self.usersDialog=self['usersDialog']
		self.permsDialog=self['permsDialog']
		self.aboutDialog=self['aboutDialog']

		self.subjectChooser=SubjectChooser(self.usersDialog,self['usersView'])
		
		# users
		self.winbindSeparatorProp=MultipleUsersProperty(self['validUsersDefineToggle'],self['validUsersEntry'],self['validUsersBrowseButton'],'valid users')
		self.winbindSeparatorProp=MultipleUsersProperty(self['readUsersDefineToggle'],self['readUsersEntry'],self['readUsersBrowseButton'],'read list')
		self.winbindSeparatorProp=MultipleUsersProperty(self['writeUsersDefineToggle'],self['writeUsersEntry'],self['writeUsersBrowseButton'],'write list')
		self.winbindSeparatorProp=MultipleUsersProperty(self['adminUsersDefineToggle'],self['adminUsersEntry'],self['adminUsersBrowseButton'],'admin users')

		# groups
		self.winbindEnumGroupsProp=BooleanProperty(self['winbindEnumGroupsDefineToggle'],self['winbindEnumGroupsToggle'],'winbind enum groups')
		self.winbindNestedGroupsProp=BooleanProperty(self['winbindNestedGroupsDefineToggle'],self['winbindNestedGroupsToggle'],'winbind nested groups')

		# winbind
		self.winbindSeparatorProp=MultipleProperty(self['winbindSeparatorDefineToggle'],self['winbindSeparatorCombo'],'winbind separator')
		self.winbindUseDefaultDomainProp=BooleanProperty(self['winbindUseDefaultDomainDefineToggle'],self['winbindUseDefaultDomainToggle'],'winbind use default domain')
		# shares
		self.clientSigningProp=MultipleProperty(self['clientSigningDefineToggle'],self['clientSigningCombo'],'client signing')
		self.serverSigningProp=MultipleProperty(self['serverSigningDefineToggle'],self['serverSigningCombo'],'server signing')
		self.createMaskProp=MaskProperty(self['createMaskDefineToggle'],self['createMaskEntry'],self['createMaskBrowseButton'],'create mask')
		self.directoryMaskProp=MaskProperty(self['directoryMaskDefineToggle'],self['directoryMaskEntry'],self['directoryMaskBrowseButton'],'directory mask')

		# id map
		minuid,maxuid=self.getUidRange()
		self.uidRangeProp=RangeProperty(self['idmapUidDefineToggle'],self['idmapUidFromSpin'],self['idmapUidToSpin'],'idmap uid')
		self.gidRangeProp=RangeProperty(self['idmapGidDefineToggle'],self['idmapGidFromSpin'],self['idmapGidToSpin'],'idmap gid')
		self.idmapBackendProp=MultipleProperty(self['idmapBackendDefineToggle'],self['idmapBackendCombo'],'idmap backend')
		self.idmapBackendProp.combo.append_text("rid:BUILTIN=500-%d,%s=%d-%d" %(minuid-1,self.getDomain(),minuid,maxuid))

		# templates
		self.templateHomeDirProp=MultipleProperty(self['templateHomedirDefineToggle'],self['templateHomedirCombo'],'template homedir')
		self.templateShellProp=MultipleProperty(self['templateShellDefineToggle'],self['templateShellCombo'],'template shell')
		#self.templatePrimaryGroupProp=UsersProperty(self['templatePrimaryGroupDefineToggle'],self['templatePrimaryGroupCombo'],'template primary group',self.groups)

		# hosts
		self.hostsAllowProp=StringProperty(self['hostsAllowDefineToggle'],self['hostsAllowEntry'],'hosts allow')
		self.hostsDenyProp=StringProperty(self['hostsDenyDefineToggle'],self['hostsDenyEntry'],'hosts deny')
		self.winsServerProp=StringProperty(self['winsServerDefineToggle'],self['winsServerEntry'],'wins server')
		self.nameResolveOrderProp=MultipleProperty(self['nameResolveOrderDefineToggle'],self['nameResolveOrderCombo'],'name resolve order')
		self.winsSupportProp=BooleanProperty(self['winsSupportDefineToggle'],self['winsSupportToggle'],'wins support')

		# perms
		self.urCheck=self['permsURCheck']
		self.uwCheck=self['permsUWCheck']
		self.uxCheck=self['permsUXCheck']
		self.grCheck=self['permsGRCheck']
		self.gwCheck=self['permsGWCheck']
		self.gxCheck=self['permsGXCheck']
		self.wrCheck=self['permsWRCheck']
		self.wwCheck=self['permsWWCheck']
		self.wxCheck=self['permsWXCheck']
		return

	def __getitem__(self, key):
        	return self.widgets.get_widget(key)

	def exit(self,*options):
		if __name__ == "__main__":
			gtk.main_quit()
		else:
			self.dialog.destroy()	
		return
				
	def exitOk(self,*options):
		self.applyGlobs()
		self.exit()
		return

	# apply

	def applyGlobs(self,*options):
		self.atexit=[]
		changes=[[k,definedProps[k].get()] for k in definedProps.keys() if definedProps[k].dirty]
		if len(changes)>0:		
			lines=self.getConf()
			begin,end=self.clip(lines,'global')
			if begin!=-1 and end!=-1:
				glines=lines[begin:end]
				#self.printConf(glines[begin:end])
				for key,data in changes:
					define,value=data
					#print '%s %s=%s' % (define,key,value)

					# special processing hook
					self.hookActions(define,key,value)

					# change config
					lineno=self.find(key,glines)
					if define:
						if lineno!=-1:
							#print 'FOUND <%s> at line %d <%s>' % (key,lineno,glines[lineno])
							glines[lineno:lineno+1]=['\t%s = %s' % (key,value)]
							#print 'REDEFINED <%s> at line %d <%s>' % (key,lineno,glines[lineno])
						else:
							#print 'NOT FOUND <%s>' % (key)
							gend=len(glines)
							glines[gend:gend]=['\t%s = %s' % (key,value)]
							#print 'DEFINED <%s> at line %d <%s>' % (key,gend,glines[gend])	
					else:
						if lineno!=-1:
							#print 'FOUND <%s> at line %d <%s>' % (key,lineno,glines[lineno])
							glines[lineno:lineno+1]=[]
							#print 'UNDEFINE REMOVED %s at line %d' % (key,lineno)
							
						else:
							#print 'NOT FOUND <%s> at line %d <%s>' % (key,lineno,glines[lineno])
							#print 'UNDEFINE NO OP'
							pass							
					#self.printConfKey(glines,key)

				#self.printConf(glines)
				lines[begin:end]=glines
				self.setConf(lines)

				# at exit
				for job in self.atexit:
					f,args=job
					f(*args)

				# signal running daemons
				status,output=self.signalWinbind()
				#print 'hup winbind=%s %s' % (status,output)
				status,output=self.signalNmb()
				#print 'hup nmb=%s %s' % (status,output)
				status,output=self.signalSmb()
				#print 'hup smb=%s %s' % (status,output)
		return

	def hookActions(self,define,key,value):
		if key=='winbind separator':
			if not define:
				value='\\'
			domain=self.getDomain()
			oldprefix='%s%s' % (domain,self.getSep())
			newprefix='%s%s' % (domain,value)
			if newprefix!=oldprefix:
				self.atexit.append((self.changeSeparator,(oldprefix,newprefix)))
		return

	def changeSeparator(self,oldprefix,newprefix):
		#print oldprefix,newprefix
		conf=self.getConf()
		for i in range(len(conf)):
			if conf[i].find(oldprefix)!=-1:
				conf[i]=conf[i].replace(oldprefix,newprefix)
		#self.printConf(conf)
		self.setConf(conf)
		return

	# dirty bit callbacks

	def checkDefineToggled(self,widget,*options):
		master=widget.get_data('master')
		master.dirty=True
		return

	def checkToggled(self,widget,*options):
		master=widget.get_data('master')
		master.dirty=True
		return

	def comboChanged(self,widget,*options):
		master=widget.get_data('master')
		master.dirty=True
		return

	def entryChanged(self,widget,*options):
		master=widget.get_data('master')
		master.dirty=True
		return

	def spinChanged(self,widget,*options):
		master=widget.get_data('master')
		master.dirty=True
		return

	# browse users

	def putPrefix(self,s,isUser,prefix,inDomain):
		if s.startswith('builtin/'):
			return s
		if inDomain!=None:
			isInDomain=inDomain(s,isUser)
			if not isInDomain:
				return s
		return '%s%s' % (prefix,s)
		
	def browseUsers(self,button,*options):
		sep=self.getSep()
		domain=self.getDomain()
		prefix='%s%s' % (domain,sep)

		master=button.get_data('master')
		self.subjectChooser.clear()
		self.subjectChooser.set(self.users,SubjectChooser.USER)
		self.subjectChooser.set(self.nisGroups,SubjectChooser.GROUP)
		response=self.subjectChooser.run()
		self.subjectChooser.hide()
		if response==gtk.RESPONSE_OK:
			selection=self.subjectChooser.getSelection()
			users=[u for u in selection if u[0]!='@']
			users=['"%s"' % (self.putPrefix(u,True,prefix,self.inDomain)) for u in users]
			groups=[g for g in selection if g[0]=='@']
			groups=['"@%s"' % (self.putPrefix(g[1:],False,prefix,self.inDomain)) for g in groups]
			all=users+groups
			master.set(','.join(all))
		#else:
		#	master.set('')
		master.dirty=True
		return
		
	def browseMask(self,button,*options):
		master=button.get_data('master')
		defined,mode=master.get()
		try:
			mode=int(mode,8)
		except:
			return
		ur,uw,ux,gr,gw,gx,wr,ww,wx=master.intToMode(mode)
		self.urCheck.set_active(ur)
		self.uwCheck.set_active(uw)
		self.uxCheck.set_active(ux)
		self.grCheck.set_active(gr)
		self.gwCheck.set_active(gw)
		self.gxCheck.set_active(gx)
		self.wrCheck.set_active(wr)
		self.wwCheck.set_active(ww)
		self.wxCheck.set_active(wx)
		response=self.permsDialog.run()
		self.permsDialog.hide()
		if response==gtk.RESPONSE_OK:
			ur=self.urCheck.get_active()
			uw=self.uwCheck.get_active()
			ux=self.uxCheck.get_active()
			gr=self.grCheck.get_active()
			gw=self.gwCheck.get_active()
			gx=self.gxCheck.get_active()
			wr=self.wrCheck.get_active()
			ww=self.wwCheck.get_active()
			wx=self.wxCheck.get_active()
			mode=master.modeToInt(ur,uw,ux,gr,gw,gx,wr,ww,wx)
			master.set(oct(mode))
			master.dirty=True
		return

	# config file

	def printConf(self,lines):
		print '%d' % (len(lines))
		print 'vvv'
		for line in lines:
			print line
		print '^^^'
		return

	def printConfKey(self,lines,key):
		print '%d' % (len(lines))
		print 'vvv'
		for line in lines:
			if line.find(key)!=-1:
				print line
		print '^^^'
		return

	def find(self,key,lines):
		#key=key.replace(' ','\s*')
		#regexp='^[\s;#]*'+key+'\s*=.*$'
		regexp='^[\s]*'+key+'\s*=.*$'
		for i in range(0,len(lines)):
			#print key,lines[i]
			if re.match(regexp,lines[i]):
				return i
		return -1

	def clip(self,lines,section):
		begin,end=(-1,-1)
		for i in range(0,len(lines)):
			if re.match('^\['+section+'\]$',lines[i]):
				begin=i
			elif begin!=-1 and end==-1 and re.match('^\[.*\]$',lines[i]):
				end=i
			i=i+1
					
		if begin!=-1 and end==-1:
			end=i
		return begin,end

	def parse(self,lines):
		props={}
		for line in lines:
			# garbage line
			if re.match('^$',line):
				continue
			# section header line
			if re.match('^\[global\]$',line):
				continue
			# property line
			prop=line.split('=')
			name=prop[0].strip()
			value='='.join(prop[1:]).strip()
			props[name]=value
        	return props

	# refresh
	
	def forceRefresh(self,*options):
		self.refresh()
		return

	def refresh(self):
		cl=sysSetting['testparm']
		status,output=self.runToString(cl)
		if not status:
			return None
		lines=output.strip('\n\r ').splitlines()
		begin,end=self.clip(lines,'global')
		if [begin,end]==(-1,-1):
			return None
		lines=lines[begin:end]
		props=self.parse(lines)
		
		#print props
		for k in definedProps.keys():
			if props.has_key(k):
				definedProps[k].set(props[k])
			else:
				definedProps[k].set(None)
        	return

	def help(self,*options):
		distribution=self.getDistribution()
		browser=sysSetting['browser'][distribution]
		urlbase=sysSetting['docs'][distribution]
		if distribution=="suse" or distribution=="debian":
			url=urlbase % ('globs.html')
		else:
			url=urlbase % (self.getVersion(),'globs.html')
		os.spawnv(os.P_NOWAIT,browser,[browser,url])
		return

	def getVersion(self):
		cl=sysSetting['getVersion']
		status,output=self.runToString(cl)
		return output

	def about(self,*options):
		self.aboutDialog.show()
		return

	#######################################################################
	#	HELPERS
	#######################################################################
		
	def runToString(self,cl):
		status,output=self.runner.runToString(cl)
		return status,output

	def exists(self,path):
		cl=sysSetting['exists']
		cl=cl.replace('%FSOBJECT%',path)
		status,output=self.runToString(cl)
		if not status:
			return False
		output=output.strip('\n\r ')
		return output=='true'
		
	def getConf(self):
		cl=sysSetting['readFile']
		cl=cl.replace('%FILE%','/etc/samba/smb.conf')
		status,output=self.runToString(cl)
		if not status:
			return []
		output=output.strip('\n\r ')
		return output.splitlines()

	def setConf(self,lines):
		text='\n'.join(lines)
		cl=sysSetting['writeFile']
		cl=cl.replace('%TEXT%',text)
		cl=cl.replace('%FILE%','/etc/samba/smb.conf')
		status,output=self.runToString(cl)
		return
				
	def getUsers(self):
		cl=sysSetting['getUsers']
	        status,output=self.runToString(cl)
		if not status:
			return []
		output=output.strip('\n\r ')
		users=output.splitlines()
		return users
	
	def getGroups(self):
		cl=sysSetting['getGroups']
	        status,output=self.runToString(cl)
		if not status:
			return []
		output=output.strip('\n\r ')
		groups=output.splitlines()
		return groups

	def getSep(self):
		cl=sysSetting['getSep']
		status,output=self.runToString(cl)
		if status:
			return output.strip('\n\r ')
		return ''

	def getDomain(self):
		cl=sysSetting['getDomain']
		status,output=self.runToString(cl)
		if status:
			return output.strip('\n\r ')
		return ''

	def inDomain(self,subject,isUser):
		if self.uidRange==[]:
			self.uidRange=self.getUidRange()
		if self.gidRange==[]:
			self.gidRange=self.getGidRange()

		if isUser:
			cl=sysSetting['getUserId']
			cl=cl.replace('%USER%',subject)
		else:
			cl=sysSetting['getGroupId']
			cl=cl.replace('%GROUP%',subject)
	        status,output=self.runToString(cl)
		if not status:
			return False
		try:
			subjectid=int(output.strip('\n\r '))
		except:
			return False;
		if isUser:
			domainrange=self.uidRange
		else:
			domainrange=self.gidRange
		return domainrange[0]<=subjectid<=domainrange[1]
	
	def getUidRange(self):
		cl=sysSetting['getUidRange']
	        status,output=self.runToString(cl)
		if not status or output=="":	
			return 10000,60000
		else:
			low,high=output.strip('\n\r ').split('-')
			return [int(low),int(high)]
		
	def getGidRange(self):
		cl=sysSetting['getGidRange']
	        status,output=self.runToString(cl)
		if not status or output=="":	
			return 10000,60000
		else:
			low,high=output.strip('\n\r ').split('-')
			return [int(low),int(high)]
		
	def getDistribution(self):
		cl=sysSetting['getDistribution']
		status,output=self.runToString(cl)
		if status:
			return output.strip('\n\r ')
		return 'default'

	def signalSmb(self):
		cl=sysSetting['signalSmb']
	        status,output=self.runToString(cl)
		return status,output

	def signalNmb(self):
		cl=sysSetting['signalNmb']
	        status,output=self.runToString(cl)
		return status,output

	def signalWinbind(self):
		cl=sysSetting['signalWinbind']
	        status,output=self.runToString(cl)
		return status,output

#######################################################################
#	MAIN
#######################################################################

import sys
import os

if __name__ == "__main__":
	
	e=sys.argv[0]
	e=os.path.realpath(e)
	d=os.path.dirname(e)
	os.chdir(d)
	s=GlobalsManager()
	s.refresh()

	gtk.main()

__author__='Bernard Bou <bou@ac-toulouse.fr>'