| 295 | raise Exception('Failed to add user to %s group: %s' % (group_name, str(self.client.result['description']))) |
| 296 | |
| 297 | def do_change_password(self, line): |
| 298 | args = shlex.split(line) |
| 299 | |
| 300 | if len(args) != 1 and len(args) != 2: |
| 301 | raise Exception("Error expected a username and an optional password argument. Instead %d arguments were provided" % len(args)) |
| 302 | |
| 303 | user_dn = self.get_dn(args[0]) |
| 304 | print("Got User DN: " + user_dn) |
| 305 | |
| 306 | password = "" |
| 307 | if len(args) == 1: |
| 308 | password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(15)) |
| 309 | else: |
| 310 | password = args[1] |
| 311 | |
| 312 | print("Attempting to set new password of: %s" % password) |
| 313 | success = self.client.extend.microsoft.modify_password(user_dn, password) |
| 314 | |
| 315 | if self.client.result['result'] == 0: |
| 316 | print('Password changed successfully!') |
| 317 | else: |
| 318 | if self.client.result['result'] == 50: |
| 319 | raise Exception('Could not modify object, the server reports insufficient rights: %s', self.client.result['message']) |
| 320 | elif self.client.result['result'] == 19: |
| 321 | raise Exception('Could not modify object, the server reports a constrained violation: %s', self.client.result['message']) |
| 322 | else: |
| 323 | raise Exception('The server returned an error: %s', self.client.result['message']) |
| 324 | |
| 325 | def do_clear_rbcd(self, computer_name): |
| 326 | |