def ScpCreate( service_binding_info, service_class_name, # Service class string to store in SCP. account_name=None, # Logon account that needs access to SCP. container_name=None, keywords=None, object_class="serviceConnectionPoint", dns_name_type="A", dn=None, dns_name=None, ): container_name = container_name or service_class_name if not dns_name: # Get the DNS name of the local computer dns_name = win32api.GetComputerNameEx( win32con.ComputerNameDnsFullyQualified) # Get the distinguished name of the computer object for the local computer if dn is None: dn = win32api.GetComputerObjectName(win32con.NameFullyQualifiedDN) # Compose the ADSpath and bind to the computer object for the local computer comp = adsi.ADsGetObject("LDAP://" + dn, adsi.IID_IDirectoryObject) # Publish the SCP as a child of the computer object keywords = keywords or [] # Fill in the attribute values to be stored in the SCP. attrs = [ ("cn", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, (container_name, )), ("objectClass", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, (object_class, )), ("keywords", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, keywords), ("serviceDnsName", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, (dns_name, )), ( "serviceDnsNameType", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, (dns_name_type, ), ), ( "serviceClassName", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, (service_class_name, ), ), ( "serviceBindingInformation", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, (service_binding_info, ), ), ] new = comp.CreateDSObject("cn=" + container_name, attrs) logger.info("New connection point is at %s", container_name) # Wrap in a usable IDispatch object. new = Dispatch(new) # And allow access to the SCP for the specified account name AllowAccessToScpProperties(account_name, new) return new
def getADDomain(): try: domain = win32api.GetComputerNameEx(win32con.ComputerNameDnsDomain) except Exception: Logger.exception("System::getADDomain") return False return domain
def renameComputer(newName): # Needs admin privileges to work if ctypes.windll.kernel32.SetComputerNameExW(DWORD(win32con.ComputerNamePhysicalDnsHostname), LPCWSTR(newName)) == 0: # @UndefinedVariable # win32api.FormatMessage -> returns error string # win32api.GetLastError -> returns error code # (just put this comment here to remember to log this when logger is available) error = getErrorMessage() computerName = win32api.GetComputerNameEx(win32con.ComputerNamePhysicalDnsHostname) raise Exception('Error renaming computer from {} to {}: {}'.format(computerName, newName, error))
def get_computer_name(): ''' Get the Windows computer name Returns: str: Returns the computer name if found. Otherwise returns ``False``. CLI Example: .. code-block:: bash salt 'minion-id' system.get_computer_name ''' name = win32api.GetComputerNameEx(win32con.ComputerNamePhysicalDnsHostname) return name if name else False
def get_computer_name(): """ Get the Windows computer name. Uses the win32api to get the current computer name. .. versionadded:: 3001 Returns: str: Returns the computer name if found. Otherwise returns ``False``. Example: .. code-block:: python import salt.utils.win_system salt.utils.win_system.get_computer_name() """ name = win32api.GetComputerNameEx(win32con.ComputerNamePhysicalDnsHostname) return name if name else False
async def _rest(self, uri, item=None, delete=False, **kwargs): # Both set to None for then GET root key = kwargs.pop('id', None) method = 'GET' if isinstance(item, dict): key = item.get('_id', key) if key is not None: uri += '/' + key if item is not None: method = 'PUT' elif item is not None: method = 'POST' if delete is True: method = 'DELETE' # If no id set but object is set, 'POST' to root response = await self.api(uri, item, method=method, **kwargs) log.debug('{}: {}'.format(method, response.url)) if response.status == 403: fqdn = getfqdn() hostname = fqdn.split('.')[0] dns_domain = win32api.GetComputerNameEx( win32con.ComputerNameDnsDomain) windows_domain = caldera_utils.getDomainNameFlat() token = await self._get_token(hostname, dns_domain, windows_domain, fqdn, self._rest) # renegotiate access token log.debug('renegotiated authentication token') self._cookies['AUTH'] = token response = await self.api(uri, item, method=method, **kwargs) elif response.status != 200: reason = "" try: reason = response.reason except AttributeError: log.warning("Got a response with no reason: {}".format( response.status)) raise RequestFailed(response.status, reason) return response
def get_host_name(): """Return host machine name. If name cannot be obtained return None. :return: A unicode string representing the host name. """ if has_win32api: try: return win32api.GetComputerNameEx(_WIN32_ComputerNameDnsHostname) except (NotImplementedError, win32api.error): # NotImplemented will happen on win9x... pass if has_ctypes: try: kernel32 = ctypes.windll.kernel32 except AttributeError: pass # Missing the module we need else: buf = create_buffer(MAX_COMPUTERNAME_LENGTH + 1) n = ctypes.c_int(MAX_COMPUTERNAME_LENGTH + 1) # Try GetComputerNameEx which gives a proper Unicode hostname GetComputerNameEx = getattr(kernel32, 'GetComputerNameEx' + suffix, None) if (GetComputerNameEx is not None and GetComputerNameEx( _WIN32_ComputerNameDnsHostname, buf, ctypes.byref(n))): return extract_buffer(buf) # Try GetComputerName in case GetComputerNameEx wasn't found # It returns the NETBIOS name, which isn't as good, but still ok. # The first GetComputerNameEx might have changed 'n', so reset it n = ctypes.c_int(MAX_COMPUTERNAME_LENGTH + 1) GetComputerName = getattr(kernel32, 'GetComputerName' + suffix, None) if (GetComputerName is not None and GetComputerName(buf, ctypes.byref(n))): return extract_buffer(buf) return get_environ_unicode('COMPUTERNAME')
def getComputerName(): return win32api.GetComputerNameEx(win32con.ComputerNamePhysicalDnsHostname)
def getADDomain(): try: domain = win32api.GetComputerNameEx(win32con.ComputerNameDnsDomain) except Exception, e: Logger.warn("System::getADDomain: exception '%s'" % (str(e))) return False
def getComputerNBName(): return win32api.GetComputerNameEx(COMPUTER_NAME_PHYSICAL_NETBIOS)