svn commit: lorikeet r420 - in trunk/sangria/src/LatestDesign: classes classes/ServerObjects classes/UserPrivileges test

amit at samba.org amit at samba.org
Mon Aug 15 17:18:43 GMT 2005


Author: amit
Date: 2005-08-15 17:18:42 +0000 (Mon, 15 Aug 2005)
New Revision: 420

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=lorikeet&rev=420

Log:
class UserPrivileges added . Methods to start , restart and stop the daemons aka server added in ServerClass.py
Added:
   trunk/sangria/src/LatestDesign/classes/UserPrivileges/
   trunk/sangria/src/LatestDesign/classes/UserPrivileges/UserPrivilegesClass.py
Modified:
   trunk/sangria/src/LatestDesign/classes/ServerObjects/ServerClass.py
   trunk/sangria/src/LatestDesign/test/test.py


Changeset:
Modified: trunk/sangria/src/LatestDesign/classes/ServerObjects/ServerClass.py
===================================================================
--- trunk/sangria/src/LatestDesign/classes/ServerObjects/ServerClass.py	2005-08-15 02:14:38 UTC (rev 419)
+++ trunk/sangria/src/LatestDesign/classes/ServerObjects/ServerClass.py	2005-08-15 17:18:42 UTC (rev 420)
@@ -112,10 +112,7 @@
             return p_list
         else:
             return None
-                    
-                
-                
-            
+                               
 
     def ListOptionsInShare(self , shareName):
         return self.Parser.services[string.upper(shareName)]['_order_']
@@ -192,41 +189,46 @@
         
 
     def RefreshServer(self):
-	''' to be implemented at last '''
-        pass
+	cmd = "smbcontrol smbd reload-config"
+        ( status, cmd_output ) = commands.getstatusoutput( cmd )
+        if status:
+            return 0
+        return 1
+    
+    
+    def StopDaemon(self , Daemon):
+        
+        cmd = "pidof %s"%Daemon 
+        ( status, cmd_output ) = commands.getstatusoutput( cmd )
+        daemon_pids = string.split( cmd_output )
 
-    def RestartServer(self):
-        self.StopServers()
-        self.StartServers()
+        for pid in daemon_pids:
+            cmd = "kill -9 %s" %pid
+            commands.getstatusoutput( cmd )
+            
+    def StartDaemon(self , Daemon):
 
-    def StopServers(self):
+        cmd = "%s/%s -D"%(self.ServerPath , Daemon)
+        ( status, cmd_output ) = commands.getstatusoutput( cmd )
+        if status:
+            return 0
+        return 1
+        
 
-        list_of_commands = []
-        list_of_commands.append("%s/smbd stop" %self.ServerPath)
-        list_of_commands.append("%s/smbd stop" %self.ServerPath)
-        list_of_commands.append("%s/winbindd stop"%self.ServerPath)
+    def StopServer(self):
 
-        for cmd1 in list_of_commands:
-            ( status, cmd_output ) = commands.getstatusoutput( cmd1 )
-            if status:
-                    print cmd_output
-                    return 0
-        return 1
+        for daemon in ['smbd' , 'nmbd' , 'winbindd']:  
+            self.StopDaemon(daemon)
+        
+    def StartServer(self):
+        for daemon in ['smbd' , 'nmbd' , 'winbindd']:  
+            self.StartDaemon(daemon)
 
-    def StartServers(self):
-        list_of_commands = []
-        list_of_commands.append("%s/smbd start"  %self.ServerPath)
-        list_of_commands.append("%s/smbd start"  %self.ServerPath)
-        list_of_commands.append("%s/winbindd start"  %self.ServerPath)
+    def RestartServer(self):
+        self.StopServer()
+        self.StartServer()
+        
 
-        for cmd1 in list_of_commands:
-            ( status, cmd_output ) = commands.getstatusoutput( cmd1 )
-            if status:
-                    print cmd_output
-                    return 0
-        return 1
-    
-
     def RemoveShare(self, delShareName ):    
         ''' the sharename is supplied as input '''
         if not self.Parser.isService(delShareName):
@@ -258,10 +260,10 @@
         ( status, cmd_output ) = commands.getstatusoutput( cmd )
         output_list = string.split(cmd_output,'\n')
         if status:
-            output_list.append(" Error in Server Configuration ")
+            output_list.append("<font color = red> Error in Server Configuration </font>")
             return output_list
         else:
-            output_list.append(" Congratulations !   Server  Tested  OK")
+            output_list.append("<font color = red> Congratulations !   Server  Tested  OK </font>")
             return output_list
 
     def CleanGlobalParameters(self , ParamList ):
@@ -341,7 +343,8 @@
 
             # here we have to ensure that the server also joins the domain .... net join -Uroot%djlajf
             self.CommitChanges()
-            self.RestartServer() 
+            self.RestartServer()
+            
             # now join the domain .. ExtraParamTupleList would be having the necessary details for domain joining 
             
             if 'WORKGROUP' in self.ListOptionsInShare('GLOBAL'):

Added: trunk/sangria/src/LatestDesign/classes/UserPrivileges/UserPrivilegesClass.py
===================================================================
--- trunk/sangria/src/LatestDesign/classes/UserPrivileges/UserPrivilegesClass.py	2005-08-15 02:14:38 UTC (rev 419)
+++ trunk/sangria/src/LatestDesign/classes/UserPrivileges/UserPrivilegesClass.py	2005-08-15 17:18:42 UTC (rev 420)
@@ -0,0 +1,34 @@
+
+import commands
+
+class UserPrivileges:
+
+    def __init__(self , ServerObject):  # the server object is to be passed ... 
+        ''' here  .. enable privileges = yes ... is to be fixed up in the server .... '''
+        ServerObject.SetOptionValuePairInService( 'GLOBAL' , 'enable privileges' , 'yes' )
+        ServerObject.CommitChanges()
+        ServerObject.RestartServer()
+
+    def GrantUserPrivilege(self, Server , Admin , UserName , Right):
+        ''' check if the user exists and then assign the privilege '''
+
+        cmd = "net -S \"%s\" -U \"%s\" rpc rights grant \"%s\" \'%s\'" %(Server , Admin , UserName , Right)
+        ( status, cmd_output ) = commands.getstatusoutput( cmd )
+        if status:
+                print cmd_output
+                return 0
+        else:
+            return cmd_output
+        
+
+    def RevokeUserPrivilege(self, Server , Admin , UserName , Right):
+
+        cmd = "net -S \"%s\" -U \"%s\" rpc rights revoke \"%s\" \'%s\'" %(Server , Admin , UserName , Right)
+        ( status, cmd_output ) = commands.getstatusoutput( cmd )
+        if status:
+                print cmd_output
+                return 0
+        else:
+            return cmd_output
+        
+    

Modified: trunk/sangria/src/LatestDesign/test/test.py
===================================================================
--- trunk/sangria/src/LatestDesign/test/test.py	2005-08-15 02:14:38 UTC (rev 419)
+++ trunk/sangria/src/LatestDesign/test/test.py	2005-08-15 17:18:42 UTC (rev 420)
@@ -3,6 +3,7 @@
 sys.path.append('../classes/ServerObjects')
 sys.path.append('../classes/AccountManager')
 sys.path.append('../classes/GroupManager')
+sys.path.append('../classes/UserPrivileges')
 
 sys.path.append('../parser')
 from smbparm import parm_table
@@ -15,23 +16,30 @@
 from AccountManagerClass import SambaUser
 from GroupManagerClass import GroupManager
 
+from UserPrivilegesClass import UserPrivileges
 
+
 if __name__ == "__main__":
 
     print
     
     s = Server("/home/amit/test/smb.conf" , "/usr/sbin/")
 
-    f_list = s.ListTypeOfShares('f')
-    for name in f_list:
-        print "file---- %s"%name
+    s.RestartServer()
 
-    f_list = s.ListTypeOfShares('p')
-    for name in f_list:
-        print "print---- %s"%name
+##    priv = UserPrivileges(s)
+##    priv.GrantUserPrivilege("pant" , "root" , "amit" , "SeMachineAccountPrivilege")
 
-    s.SetPrintStyle("CUPS")
-    s.CommitChanges()
+##    f_list = s.ListTypeOfShares('f')
+##    for name in f_list:
+##        print "file---- %s"%name
+##
+##    f_list = s.ListTypeOfShares('p')
+##    for name in f_list:
+##        print "print---- %s"%name
+##
+##    s.SetPrintStyle("CUPS")
+##    s.CommitChanges()
 
 ##    list = s.ListShares()
 ##    for name in list:



More information about the samba-cvs mailing list