Ejemplo n.º 1
0
def setUid(uid, userName):
    try:
        fp = open(Globals.CIFS_USER_FILE, "a")
        fp.write("%s:%s\n" % (uid, userName))
        fp.close()
        return True
    except IOError, e:
        Utils.log("failed to write file %s: %s" % (Globals.CIFS_USER_FILE, str(e)))
        return False
Ejemplo n.º 2
0
def removeUser(userName):
    lines = Utils.readFile(Globals.CIFS_USER_FILE, lines=True)
    try:
        fp = open(Globals.CIFS_USER_FILE, "w")
        for line in lines:
            if not line.strip():
                continue
## junli.li remove the line of userName from CIFS_USER_FILE
            if line.strip().split(":")[1] == userName:
                continue
            fp.write("%s" % line)
        fp.close()
    except IOError, e:
        Utils.log("failed to write file %s: %s" % (Globals.CIFS_USER_FILE, str(e)))
        return False
Ejemplo n.º 3
0
def deleteCifsUser(data):
    code = "25003"
    reval = ""
    try:
        userName = data.userName
    except Exception,e:
        reval = "Error when deleting cifs user: "******"400 Bad Request", data = result)

    try:
        command = "%s/delete_user_cifs.py %s " % (Globals.BACKEND_SCRIPT, userName)
        status = Utils.runCommand(command, output=True, root=True, shell=True)
        if status["Status"] != 0:
            Utils.log("delete cifs user %s failure" % (userName))
            reval = status["Stderr"]
            raise
    
        if not removeUser(userName):
            Utils.log("Failed to remove cifs user %s from user.cifs" % (userName))
            reval = "Failed to remove cifs user "+ userName + " from user.cifs"
            raise
        return None
    except Exception,e:
        code,reval = "25003", "Error when delete cifs user" + userName + ": " + reval
        params = []
        params.append(userName)
        result = Utils.errorCode(code, reval, params)
        raise web.HTTPError(status = "400 Bad Request", data = result)