Exemplo n.º 1
0
def setShareDetails(shareName, description, public=False, sambaConfig=None):
    debugOutput("Setting share details for %s" % shareName)

    if not sambaConfig and shareName not in getShares():
        return

    # Get the group name of this share.
    shareGroup = groupNameFromShare(shareName)

    if not sambaConfig:
        sambaConfig = system.readFromFile(SAMBA_CONFIG)
        saveConfig = True
    else:
        saveConfig = False

    # Update the comment field
    newSambaConfig = surgicalConfigSet(sambaConfig, shareName, "comment",
                                       description)

    # Update guest access to the share
    # TODO: guest only, valid users
    if public:
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "valid users", "")
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "guest ok", "yes")
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "guest only", "yes")
        if not system.isUserInGroup("nobody", shareGroup):
            system.addUserToGroup("nobody", shareGroup)
    else:
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "valid users",
                                           "@%s root" % shareGroup)
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "guest ok", "no")
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "guest only", "no")
        if system.isUserInGroup("nobody", shareGroup):
            system.removeUserFromGroup("nobody", shareGroup)

    if saveConfig:
        if newSambaConfig != sambaConfig:
            system.writeToFile(SAMBA_CONFIG, newSambaConfig)
            restart()
    else:
        return newSambaConfig
Exemplo n.º 2
0
def setSharePermission(username, shareName, permission) :
  debugOutput("")
  if shareName not in getShares() :
    return

  curPermission = getSharePermission(username, shareName)
  if curPermission == permission :
    return
  
  sharePath = os.path.join(SAMBA_SHARES_PATH, shareName)
  shareGroup = grp.getgrgid(os.stat(sharePath).st_gid)
  
  # Add the user to the share's group.
  if permission == True :
    system.addUserToGroup(username, shareGroup.gr_name)
  else :
    system.removeUserFromGroup(username, shareGroup.gr_name)

  # Make sure samba uses up-to-date group info by restarting it
  restart()
Exemplo n.º 3
0
def setSharePermission(username, shareName, permission):
    debugOutput("")
    if shareName not in getShares():
        return

    curPermission = getSharePermission(username, shareName)
    if curPermission == permission:
        return

    sharePath = os.path.join(SAMBA_SHARES_PATH, shareName)
    shareGroup = grp.getgrgid(os.stat(sharePath).st_gid)

    # Add the user to the share's group.
    if permission == True:
        system.addUserToGroup(username, shareGroup.gr_name)
    else:
        system.removeUserFromGroup(username, shareGroup.gr_name)

    # Make sure samba uses up-to-date group info by restarting it
    restart()
Exemplo n.º 4
0
def setShareDetails(shareName, description, public=False, sambaConfig=None) :
  debugOutput("Setting share details for %s" % shareName)

  if not sambaConfig and shareName not in getShares() :
    return
 
  # Get the group name of this share.
  shareGroup = groupNameFromShare(shareName)
  
  if not sambaConfig :
    sambaConfig = system.readFromFile(SAMBA_CONFIG)
    saveConfig = True
  else :
    saveConfig = False

  # Update the comment field
  newSambaConfig = surgicalConfigSet(sambaConfig, shareName, "comment", description)
  
  # Update guest access to the share
  # TODO: guest only, valid users
  if public :
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "valid users", "")
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "guest ok", "yes")
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "guest only", "yes")
    if not system.isUserInGroup("nobody", shareGroup) :
      system.addUserToGroup("nobody", shareGroup)
  else :
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "valid users", "@%s root" % shareGroup)
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "guest ok", "no")
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "guest only", "no")
    if system.isUserInGroup("nobody", shareGroup) :
      system.removeUserFromGroup("nobody", shareGroup)
  
  if saveConfig :
    if newSambaConfig != sambaConfig :
      system.writeToFile(SAMBA_CONFIG, newSambaConfig)
      restart()
  else :
    return newSambaConfig