Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.4 kB
2
Indexable
Never
import sys , subprocess


SORTIE ="./global-user.ldif"




def execute():
    command = subprocess.Popen(["ldapadd","-x","-D","cn=Directory Manager,dc=localdomain","-W","-f",SORTIE],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
    print(command.stdout.read().decode("utf-8"))
    command.stdout.close()


def writeInLdif(name : str , username:str , uid:int , login:str , mdp:str ):
    with open("SORTIE","w") as sortie : 
        sortie.write("dn: uid="+login+",ou=People,dc=localdomain\n"+
                     "objectClass: top\n"+
                     "objectClass: inetorgperson\n"+
                     "objectClass: posixAccount\n"+
                     "cn: "+name+" "+username+"\n"+
                     "sn: "+username+"\n"+
                     "givenname: "+name+"\n"+
                     "userPassword: "+mdp+"\n"+
                     "uidNumber:"+uid+"\n"+
                     "gidNumber: 100\n"+
                     "homeDirectory: /home/"+username+"\n"+
                     "loginShell: /bin/bash\n")




def main():
    if len(sys.argv) == 0:
        print("Usage: python3 mkglobal-user.py <username>")
        return 1
    name = sys.argv[1]
    prenom = sys.argv[2]
    uid = sys.argv[3]
    login = sys.argv[4]
    mdp = sys.argv[5]
    print(sys.argv)
    print(f"username: {prenom}")
    print(f"uid: {uid}")
    writeInLdif(name , prenom , uid , login , mdp)



if __name__ == "__main__":
    main()
Leave a Comment