def removeVolumeShare(volumepath): hasfind = False hasfilt = False line = h23.getContent("/etc/samba/smb.conf") i = 0 while i < len(line): if line[i].find("path =") != -1: j = line[i].find("=") tmpd = line[i][j + 1:] tmpd = tmpd.strip() if tmpd.find(volumepath) != -1: hasfind = True i += 1 if line[i].find("veto files") != -1: hasfilt = True break i += 1 if hasfind == False: return 0 if hasfind == True: i -= 2 k = 7 if hasfilt == True: k = 8 del line[i:i + k] h24.fileWriteLines("/etc/samba/smb.conf", line) h25.cpSmbConfig() h26.restartSMB()
def removeCifsShare (origDirName): hasfind = False hasfilt = False #print origDirName line = h23.getContent("/etc/samba/smb.conf") i = 0 while i < len(line): if line[i].find("path =") != -1: j = line[i].find("=") tmpd = line[i][j+1:] tmpd = tmpd.strip() #print tmpd if tmpd == origDirName: hasfind = True i += 1 if line[i].find("veto files") !=-1: hasfilt = True break i += 1 if hasfind == False: return 0 if hasfind == True: i -= 2 k = 7 if hasfilt == True: k = 8 del line[i:i+k] h24.fileWriteLines("/etc/samba/smb.conf",line) h25.cpSmbConfig () h26.restartSMB ()
def hasFind(shareName, sharePath, readlist, writelist, validusers, origDirName, shareDirName): hasfind = 0 findfilter = 0 line = h23.getContent("/etc/samba/smb.conf") i = 0 while i < len(line): if line[i].find("path =") != -1: j = line[i].find('=') tmp = line[i][j + 1:] tmp = tmp.strip() if tmp == origDirName: hasfind = 1 i = i + 1 if line[i].find("veto files =") != -1: findfilter = 1 break i = i + 1 k = 0 #print line[k] tmp2 = shareName tmp2 = tmp2.lower() while k < len(line): if line[k].find("[") == 0: tmp1 = line[k] tmp1 = tmp1.strip() if tmp1 == tmp2: #print line[k+1][0:-1] #print sharePath if line[k + 1][0:-1] != sharePath: return 0 k = k + 1 #print line if hasfind == 1: i = i - 2 line[i] = shareName if findfilter == 1: i = i + 4 else: i = i + 3 line[i] = readlist i = i + 1 line[i] = writelist i = i + 1 line[i] = validusers # print line else: line.append("\n") line.append(shareName) line.append(sharePath) line.append("\tpublic = no") line.append(readlist) line.append(writelist) line.append(validusers) return line # print line
def hasFind (shareName, sharePath, readlist, writelist, validusers, origDirName, shareDirName): hasfind = 0 findfilter = 0 line = h23.getContent("/etc/samba/smb.conf") i = 0 while i < len (line): if line[i].find("path =") != -1: j = line[i].find('='); tmp = line[i][j+1:] tmp = tmp.strip() if tmp == origDirName: hasfind = 1 i = i + 1 if line[i].find("veto files =") != -1: findfilter = 1 break i = i + 1 k = 0 #print line[k] tmp2 = shareName tmp2 = tmp2.lower() while k < len (line): if line[k].find("[") == 0: tmp1 = line[k] tmp1 = tmp1.strip() if tmp1 == tmp2: #print line[k+1][0:-1] #print sharePath if line[k+1][0:-1] != sharePath: return 0 k = k + 1 #print line if hasfind == 1: i = i - 2 line[i] = shareName if findfilter == 1: i = i + 4 else: i = i + 3 line[i] = readlist i = i + 1 line[i] = writelist i = i + 1 line[i] = validusers # print line else: line.append("\n") line.append(shareName) line.append(sharePath) line.append("\tpublic = no") line.append(readlist) line.append(writelist) line.append(validusers) return line # print line
def getCifsShareDir(): line = h23.getContent("/etc/samba/smb.conf") a = [] i = 0 while i < len(line): if line[i].find("path =") != -1: j = line[i].find("=") tmp = line[i][j+1:] tmp = tmp.strip() a.append(tmp) i += 1 # print a return a
def getShareInfo(origDirName): line = h23.getContent("/etc/samba/smb.conf") # print origDirName shIf = [] shDN = "\0" rl = "\0" wl = "\0" ru = [] wu = [] i = 0 while i < len(line): if line[i].find("path =") != -1: j = line[i].find("=") tmpd = line[i][j + 1:] tmpd = tmpd.strip() # tmpd = tmpd[0:-1] # print tmpd if tmpd == origDirName: i += 1 if line[i].find("veto files =") != -1: i -= 2 shDN = line[i][1:-2] i += 4 rl = line[i] i += 1 wl = line[i] else: i -= 2 shDN = line[i][1:-2] i += 3 rl = line[i] i += 1 wl = line[i] i += 1 j = rl.find("=") tmp = rl[j + 1:] tmp = tmp.strip() if tmp != "\0": ru = re.split(r',', tmp) # print ru j = wl.find("=") tmp = wl[j + 1:] tmp = tmp.strip() if tmp != "\0": wu = re.split(r',', tmp) k = 0 while k < len(ru): a = [] if ru[k].find("@") != -1: a.append(ru[k]) a.append(0) a.append(1) else: a.append(ru[k]) a.append(0) a.append(0) shIf.append(a) k += 1 k = 0 while k < len(wu): a = [] if wu[k].find("@") != -1: a.append(wu[k]) a.append(1) a.append(1) else: a.append(wu[k]) a.append(1) a.append(0) shIf.append(a) k += 1 Info = [] Info.append(shDN) Info.append(shIf) # print Info return Info
def getShareInfo(origDirName): line = h23.getContent("/etc/samba/smb.conf") # print origDirName shIf = [] shDN = "\0" rl = "\0" wl = "\0" ru = [] wu = [] i = 0 while i < len(line): if line[i].find("path =") != -1: j = line[i].find("=") tmpd = line[i][j+1:] tmpd = tmpd.strip() # tmpd = tmpd[0:-1] # print tmpd if tmpd == origDirName: i += 1 if line[i].find("veto files =") != -1: i -= 2 shDN = line[i][1:-2] i += 4 rl = line[i] i +=1 wl = line[i] else: i -= 2 shDN = line[i][1:-2] i += 3 rl = line[i] i += 1 wl = line[i] i += 1 j = rl.find("=") tmp = rl[j+1:] tmp = tmp.strip() if tmp != "\0": ru = re.split(r',',tmp) # print ru j = wl.find("=") tmp = wl[j+1:] tmp = tmp.strip() if tmp != "\0": wu = re.split(r',',tmp) k = 0 while k < len(ru): a = [] if ru[k].find("@") != -1: a.append(ru[k]) a.append(0) a.append(1) else: a.append(ru[k]) a.append(0) a.append(0) shIf.append(a) k += 1 k = 0 while k < len(wu): a = [] if wu[k].find("@") != -1: a.append(wu[k]) a.append(1) a.append(1) else: a.append(wu[k]) a.append(1) a.append(0) shIf.append(a) k += 1 Info = [] Info.append(shDN) Info.append(shIf) # print Info return Info
def cpSmbConfig(): a = [] line = h23.getContent("/etc/samba/smb.conf") i = 0 while i < len(line): if line[i].find("valid users =") != -1: j = line[i].find("=") tmp = line[i][j + 1:] tmp = tmp.strip() tmp1 = re.split(r',', tmp) j = 0 while j < len(tmp1): a.append(tmp1[j]) j = j + 1 i = i + 1 os.system("rm -rf /sysvol/etc/samba/smb.conf.*") #print a k = 0 while k < len(a): str = "\\cp /sysvol/etc/samba/smb.conf /sysvol/etc/samba/smb.conf." + a[ k].strip() os.system(str) #print str k = k + 1 k = 0 while k < len(a): filepath = "/sysvol/etc/samba/smb.conf." + a[k].strip() tmp2 = h23.getContent(filepath) #print len(tmp2) j = 0 while j < len(tmp2): if tmp2[j].find('valid users =') != -1: b = [] hasfind = 0 #print j #print len(tmp2) l = tmp2[j].find("=") tmp3 = tmp2[j][l + 1:] #print tmp3 tmp3 = tmp3.strip() tmp4 = re.split(r',', tmp3) #print tmp4 n = 0 while n < len(tmp4): b.append(tmp4[n]) n = n + 1 m = 0 while m < len(b): #print b[m] #print a[k] if b[m] == a[k]: hasfind = 1 break m = m + 1 if hasfind == 1: #print "GGGGGGGG" #print tmp2 tmp2[j - 1:0] = ["\tbrowseable = no\n"] #print tmp2 #print j j = j + 1 #print j else: j = j + 1 j = j + 1 else: j = j + 1 #print filepath #print tmp2 h24.fileWriteLines(filepath, tmp2) k = k + 1
def cpSmbConfig(): a = [] line = h23.getContent("/etc/samba/smb.conf") i = 0 while i < len(line): if line[i].find("valid users =") != -1: j = line[i].find("=") tmp = line[i][j + 1 :] tmp = tmp.strip() tmp1 = re.split(r",", tmp) j = 0 while j < len(tmp1): a.append(tmp1[j]) j = j + 1 i = i + 1 os.system("rm -rf /sysvol/etc/samba/smb.conf.*") # print a k = 0 while k < len(a): str = "\\cp /sysvol/etc/samba/smb.conf /sysvol/etc/samba/smb.conf." + a[k].strip() os.system(str) # print str k = k + 1 k = 0 while k < len(a): filepath = "/sysvol/etc/samba/smb.conf." + a[k].strip() tmp2 = h23.getContent(filepath) # print len(tmp2) j = 0 while j < len(tmp2): if tmp2[j].find("valid users =") != -1: b = [] hasfind = 0 # print j # print len(tmp2) l = tmp2[j].find("=") tmp3 = tmp2[j][l + 1 :] # print tmp3 tmp3 = tmp3.strip() tmp4 = re.split(r",", tmp3) # print tmp4 n = 0 while n < len(tmp4): b.append(tmp4[n]) n = n + 1 m = 0 while m < len(b): # print b[m] # print a[k] if b[m] == a[k]: hasfind = 1 break m = m + 1 if hasfind == 1: # print "GGGGGGGG" # print tmp2 tmp2[j - 1 : 0] = ["\tbrowseable = no\n"] # print tmp2 # print j j = j + 1 # print j else: j = j + 1 j = j + 1 else: j = j + 1 # print filepath # print tmp2 h24.fileWriteLines(filepath, tmp2) k = k + 1