svn commit: lorikeet r381 - in trunk/sangria/src: .
amit at samba.org
amit at samba.org
Sun Jul 24 09:33:09 GMT 2005
Author: amit
Date: 2005-07-24 09:33:08 +0000 (Sun, 24 Jul 2005)
New Revision: 381
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=lorikeet&rev=381
Log:
amit regmi
Modified:
trunk/sangria/src/make_smb_conf.py
trunk/sangria/src/smb_tools.py
Changeset:
Modified: trunk/sangria/src/make_smb_conf.py
===================================================================
--- trunk/sangria/src/make_smb_conf.py 2005-07-23 09:43:19 UTC (rev 380)
+++ trunk/sangria/src/make_smb_conf.py 2005-07-24 09:33:08 UTC (rev 381)
@@ -407,6 +407,11 @@
print " the share is already there "
def SetPathOfShare(self, shareName , pathOfShare, serverObject):
+ ''' set the path and include the basic permissions
+ like ...
+ read-only = yes
+ browesable = yes
+ '''
x = serverObject
# check if the path exists ... If it does not ... create .. it
if( not os.path.isdir(pathOfShare)):
@@ -420,7 +425,9 @@
x.AddService(shareToAdd , ['##','## added by modify.py ','##'])
x.SetServiceOption(shareName , "path" , pathOfShare)
x.SetServiceOption(shareName , "comment" ,"no comment")
- x.SetServiceOption(shareName , "read only" ,"no")
+ x.SetServiceOption(shareName , "read only" ,"no")
+ x.SetServiceOption(shareName , "browesable" ,"yes")
+
def deleteShare(self, shareToDelete , serverObject):
''' here we delete the share if present already in the smb.conf file '''
Modified: trunk/sangria/src/smb_tools.py
===================================================================
--- trunk/sangria/src/smb_tools.py 2005-07-23 09:43:19 UTC (rev 380)
+++ trunk/sangria/src/smb_tools.py 2005-07-24 09:33:08 UTC (rev 381)
@@ -49,11 +49,47 @@
return return_str
+ def listUnixUserAccountsInPasswd(self , pathOfPasswdFile ):
+ '''
+ returns a LIST of the Unix user names
+ returns 0 on failure
+ returns -1 on Access Denied
+ '''
+
+ splitted_output1 = []
+ return_list1 = []
+ if (self.Am_I_Root()):
+ cmd1 = "cat %s" %pathOfPasswdFile
+ ( status1, cmd_output1 ) = commands.getstatusoutput( cmd1 )
+ if status1:
+ print " system error \n"
+ print cmd_output1
+ return 0
+
+ else:
+ # the output obtained is a string as a whole
+ splitted_output1 = string.split(cmd_output1,'\n')
+ for line1 in splitted_output1:
+ # again split and chuck out the first split ...
+ temp1 = string.split(line1 , ":")
+ return_list1.append(temp1[0])
+ #print temp1[0]
+
+ return return_list1
+
+ else:
+ print " You don't have root access "
+ return -1
+
+
+
def listUserAccountsInSmbpasswd(self):
- ''' returns a LIST of the user names on
- 0 on failure and
'''
+ returns a LIST of the user names on Samba
+ returns 0 on failure
+ returns -1 on Access Denied
+ '''
splitted_output1 = []
return_list1 = []
@@ -79,6 +115,7 @@
else:
print " You don't have root access "
+ return -1
@@ -101,6 +138,7 @@
else:
print " You don't have root access "
+ return -1
def serverRefresh(self):
@@ -120,6 +158,7 @@
return 1
else:
print " You don't have root access "
+ return -1
def SMBmountPath(self, mountSourcePath , mountDestPath , loginName , loginPassword):
''' mount a given path to a location mentioned ..
@@ -140,6 +179,7 @@
else:
print " You don't have root access "
+ return -1
def SMBumountPath(self, umountPath ):
@@ -161,8 +201,72 @@
else:
print " You don't have root access "
+ return -1
+ def addSambaAccount( self, SMBaccountID , SMBpassword ):
+
+ ''' it is assumed that the SMBaccountID is already there as a Unix User account
+ here we also update the smbpasswd database so as to include each unix users
+ as a potential accounts for samba'''
+ if (self.Am_I_Root()):
+ cmd3 = "cat /etc/passwd | /usr/bin/mksmbpasswd.sh > /etc/samba/smbpasswd"
+ ( status3, cmd_output3 ) = commands.getstatusoutput( cmd3 )
+ if status3:
+ print cmd_output3
+ else:
+ print " /etc/samba/smbpasswd updated successfully"
+
+ cmd3 = "smbpasswd %s %s" %(SMBaccountID, SMBpassword)
+ #print cmd3
+ ( status3, cmd_output3 ) = commands.getstatusoutput( cmd3 )
+ if status3:
+ print cmd_output3
+ return 0
+
+ else:
+ print " %s added as a samba user successfully" %(SMBaccountID)
+ return 1
+
+ else:
+ print " You don't have root access "
+ return -1
+
+ def delSambaAccount( self, SMBaccountID ):
+ ''' smbpasswd -x rrr .... this cmd is used to remove an account
+ succeeds if the unixusername rrr exists ... '''
+ ''' it is assumed that the SMBaccountID is already there as a Unix User account '''
+ if (self.Am_I_Root()):
+ cmd3 = "smbpasswd -x %s" %(SMBaccountID)
+ #print cmd3
+ ( status3, cmd_output3 ) = commands.getstatusoutput( cmd3 )
+ if status3:
+ print cmd_output3
+ return 0
+
+ else:
+ print " %s is deleted successfully" %(SMBaccountID)
+ return 1
+
+ else:
+ print " You don't have root access "
+
+ def changeSMBpassword(self, SMBaccountID , newSMBpassword ):
+ ''' change the smb accout password
+ return 1 on success
+ return 0 on failure
+ return -1 on Access Denied
+ '''
+ ret = self.addSambaAccount( SMBaccountID , newSMBpassword )
+ return ret
+
+ def enableDisableSMBaccount(self , accountID, e_for_enable_d_for_Disable):
+
+
+
+ pass
+
+
def downloadPath(self, path):
pass
@@ -173,21 +277,24 @@
# a server object
s = Server("/home/amit/test/smb.conf")
- #tring = s.sendMessageToMachine("hi dear" , "dracula" , "ar")
-
- s.checkAccountInSmbpasswd("all")
-
- #list = s.listUserAccountsInSmbpasswd()
+## tring = s.sendMessageToMachine("hi dear" , "dracula" , "ar")
+## s.checkAccountInSmbpasswd("all")
+## list = s.listUserAccountsInSmbpasswd()
+## print list[0]
+## print list[-1]
+## s.serverRefresh()
+## s.SMBmountPath("//ar/cd_write" , "/mnt/cdrom" , "amit", "nepali" )
+## s.SMBumountPath("/mnt/cdrom")
+## s.addSambaAccount("kkk","kkk")
+## s.changeSMBpassword("kkk" , "newpass")
+## print " hit enter to delete the just created account "
+## raw_input()
+## s.delSambaAccount("rrr")
- #print list[0]
- #print list[-1]
+## list1 = s.listUnixUserAccountsInPasswd("/etc/passwd")
+## print list1[0]
+## print list1[-2]
+## print list1[-1]
- #s.serverRefresh()
-
- #s.SMBmountPath("//ar/cd_write" , "/mnt/cdrom" , "amit", "nepali" )
-
- s.SMBumountPath("/mnt/cdrom")
-
-
print "done"
More information about the samba-cvs
mailing list