예제 #1
0
parser.add_argument("-n", "--dry-run", action="store_true", dest="dry", help="run but do not add users to idm")
parser.add_argument("-l", "--logfile", dest="logfile", help="change logfile location")
parser.add_argument(
    "-y", "--no-confirm", action="store_false", dest="confirm", help="do not confirm user attributes after ldap search"
)
parser.add_argument("--uid", action="store_true", dest="uid", help="update the users uid")
parser.add_argument("usernames", nargs="*")

# create parser
args = parser.parse_args()

logging.basicConfig(format="%(asctime)s :: %(message)s", level=logging.CRITICAL)
logging.info("START")
logging.debug(args)

dstring = ""
if args.dry == True:
    dstring = "--dry-run selected, no changes will be made to idm regardless of confirmation!\n"

userattrs = []
notfound = []
# pull user attributes from AD with ldap query
for user in args.usernames:
    sres = ldap_tools.ldapsearch(user, "bash")
    if sres != "NOUSER":
        userattrs.append(sres)
    else:
        notfound.append(user)

print userattrs
예제 #2
0
# verify user args and shell option
logging.info("validating shell options...")
logging.debug(args.usernames)

# if not entering users manually...
if args.manual == False:
	# validate and correct user shell options if manual not selected
    	args.usernames = user_add.validateshell(args.usernames, args.defShell)
	logging.debug(args.usernames)

	attrs=[]
	
	# find user ldap entries
	for uname in args.usernames:
		uname = uname.split(':')
		sres = (ldap_tools.ldapsearch(uname[0],uname[1]))
		
		if sres != "NOUSER":
			attrs.append(sres)
		else:
			if args.manid == True:
				logging.critical("error, user not found and manid enabled...abort")
     				exit()
# if manual ids is on, set input ids
if args.manid == True:
	for n,user in enumerate(attrs):
		attrs[n][5] = man_uids[n]	
		attrs[n][6] = man_uids[n]	
	
	
# if the user would like to confim user attributes
# create parser
args = parser.parse_args()

logging.basicConfig(format='%(asctime)s :: %(message)s', level=logging.CRITICAL)
logging.info("START")
logging.debug(args)

dstring =""
if args.dry == True:
	dstring = "--dry-run selected, no changes will be made to idm regardless of confirmation!\n"

userattrs = []
# pull user attributes from AD with ldap query
for user in args.usernames:
	sres = ldap_tools.ldapsearch(user, 'bash')
	if sres != 'NOUSER':	
		userattrs.append(sres)
	else:
		print "error, user %s not found\n" %user

# The update list will be of tuples [<username>,"<attrs_to_update>"]
update_list = []

for user in userattrs:
	modstring = ""
	if args.uid == True:
		modstring = modstring + "--uid %s --gidnumber %s " % (user[5], user[6])
	
	update_list.append([user[0], modstring])