(self, line)
| 233 | raise Exception('The server returned an error: %s', self.client.result['message']) |
| 234 | |
| 235 | def do_add_user(self, line): |
| 236 | args = shlex.split(line) |
| 237 | |
| 238 | if not self.client.server.ssl and not self.client.tls_started: |
| 239 | print("Error adding a new user with LDAP requires LDAPS.") |
| 240 | |
| 241 | if len(args) == 0: |
| 242 | raise Exception("A username is required.") |
| 243 | |
| 244 | new_user = args[0] |
| 245 | if len(args) == 1: |
| 246 | parent_dn = 'CN=Users,%s' % self.domain_dumper.root |
| 247 | else: |
| 248 | parent_dn = args[1] |
| 249 | |
| 250 | new_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(15)) |
| 251 | |
| 252 | new_user_dn = 'CN=%s,%s' % (new_user, parent_dn) |
| 253 | ucd = { |
| 254 | 'objectCategory': 'CN=Person,CN=Schema,CN=Configuration,%s' % self.domain_dumper.root, |
| 255 | 'distinguishedName': new_user_dn, |
| 256 | 'cn': new_user, |
| 257 | 'sn': new_user, |
| 258 | 'givenName': new_user, |
| 259 | 'displayName': new_user, |
| 260 | 'name': new_user, |
| 261 | 'userAccountControl': 512, |
| 262 | 'accountExpires': '0', |
| 263 | 'sAMAccountName': new_user, |
| 264 | 'unicodePwd': '"{}"'.format(new_password).encode('utf-16-le') |
| 265 | } |
| 266 | |
| 267 | print('Attempting to create user in: %s', parent_dn) |
| 268 | res = self.client.add(new_user_dn, ['top', 'person', 'organizationalPerson', 'user'], ucd) |
| 269 | if not res: |
| 270 | if self.client.result['result'] == RESULT_UNWILLING_TO_PERFORM and not self.client.server.ssl: |
| 271 | raise Exception('Failed to add a new user. The server denied the operation. Try relaying to LDAP with TLS enabled (ldaps) or escalating an existing user.') |
| 272 | else: |
| 273 | raise Exception('Failed to add a new user: %s' % str(self.client.result['description'])) |
| 274 | else: |
| 275 | print('Adding new user with username: %s and password: %s result: OK' % (new_user, new_password)) |
| 276 | |
| 277 | def do_add_user_to_group(self, line): |
| 278 | user_name, group_name = shlex.split(line) |
nothing calls this directly
no outgoing calls
no test coverage detected