(self, line)
| 123 | raise Exception("Something wasnt right: %s" %str(self.client.result['description'])) |
| 124 | |
| 125 | def do_add_computer(self, line): |
| 126 | args = shlex.split(line) |
| 127 | |
| 128 | if not self.client.server.ssl and not self.client.tls_started: |
| 129 | print("Error adding a new computer with LDAP requires LDAPS.") |
| 130 | |
| 131 | if len(args) != 1 and len(args) != 2 and len(args) !=3: |
| 132 | raise Exception("Error expected a computer name, an optional password argument, and an optional nospns argument.") |
| 133 | |
| 134 | computer_name = args[0] |
| 135 | if not computer_name.endswith('$'): |
| 136 | computer_name += '$' |
| 137 | |
| 138 | print("Attempting to add a new computer with the name: %s" % computer_name) |
| 139 | |
| 140 | password = "" |
| 141 | if len(args) == 1 or args[1] == "nospns": |
| 142 | password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(15)) |
| 143 | else: |
| 144 | password = args[1] |
| 145 | |
| 146 | domain_dn = self.domain_dumper.root |
| 147 | domain = re.sub(',DC=', '.', domain_dn[domain_dn.find('DC='):], flags=re.I)[3:] |
| 148 | |
| 149 | print("Inferred Domain DN: %s" % domain_dn) |
| 150 | print("Inferred Domain Name: %s" % domain) |
| 151 | |
| 152 | computer_hostname = computer_name[:-1] # Remove $ sign |
| 153 | computer_dn = "CN=%s,CN=Computers,%s" % (computer_hostname, self.domain_dumper.root) |
| 154 | print("New Computer DN: %s" % computer_dn) |
| 155 | |
| 156 | if len(args) == 3: |
| 157 | if args[2] == "nospns": |
| 158 | spns = [ |
| 159 | 'HOST/%s.%s' % (computer_hostname, domain) |
| 160 | ] |
| 161 | else: |
| 162 | raise Exception("Invalid third argument: %s" %str(args[3])) |
| 163 | elif len(args) == 2: |
| 164 | if args[1] != "nospns": |
| 165 | spns = [ |
| 166 | 'HOST/%s' % computer_hostname, |
| 167 | 'HOST/%s.%s' % (computer_hostname, domain), |
| 168 | 'RestrictedKrbHost/%s' % computer_hostname, |
| 169 | 'RestrictedKrbHost/%s.%s' % (computer_hostname, domain), |
| 170 | ] |
| 171 | elif args[1] == "nospns": |
| 172 | spns = [ |
| 173 | 'HOST/%s.%s' % (computer_hostname, domain) |
| 174 | ] |
| 175 | elif len(args) == 1: |
| 176 | spns = [ |
| 177 | 'HOST/%s' % computer_hostname, |
| 178 | 'HOST/%s.%s' % (computer_hostname, domain), |
| 179 | 'RestrictedKrbHost/%s' % computer_hostname, |
| 180 | 'RestrictedKrbHost/%s.%s' % (computer_hostname, domain), |
| 181 | ] |
| 182 | else: |
nothing calls this directly
no outgoing calls
no test coverage detected