def _connect(): global _currentLdapConnection if not user.isInAD() and not (user.isRoot() or not computer.isInAD()): logging.warning("Cannot perform LDAP search: User is not in AD!") _currentLdapConnection = None return False if not _currentLdapConnection == None: return True try: sasl_auth = ldap.sasl.sasl({}, 'GSSAPI') _currentLdapConnection = ldap.initialize(serverUrl(), trace_level=0) # TODO: # conn.set_option(ldap.OPT_X_TLS_CACERTFILE, '/path/to/ca.pem') # conn.set_option(ldap.OPT_X_TLS_NEWCTX, 0) # conn.start_tls_s() _currentLdapConnection.set_option(ldap.OPT_REFERRALS, 0) _currentLdapConnection.protocol_version = ldap.VERSION3 _currentLdapConnection.sasl_interactive_bind_s("", sasl_auth) except Exception as e: _currentLdapConnection = None logging.error("Cloud not bind to ldap!") logging.exception(e) return False return True
def _getDefaultUsername(username=None): if username == None: if user.isRoot(): username = computer.hostname().upper() + "$" else: username = user.username() return username
def installPrinter(networkPath, name=None, username=None): if username == None: username = user.username() if user.isRoot(): return _installPrinter(username, networkPath, name) else: # This will call installPrinter() again with root privileges return _installPrinterWithoutRoot(networkPath, name) pass
def mountShare(networkPath, shareName=None, hiddenShare=False, username=None): networkPath = networkPath.replace("\\", "/") username = _getDefaultUsername(username) shareName = _getDefaultShareName(networkPath, shareName) if user.isRoot(): return _mountShare(username, networkPath, shareName, hiddenShare, True) else: mountpoint = _getShareMountpoint(networkPath, username, hiddenShare, shareName) # This will call _mountShare() directly with root privileges return _mountShareWithoutRoot(networkPath, shareName, hiddenShare), mountpoint
def installPrinter(networkPath, name=None, username=None): """ Installs a networked printer for a user :param networkPath: The network path of the printer :type networkPath: str :param name: The name for the printer, defaults to None :type name: str, optional :param username: The username of the user whom the is installed printer for. Defaults to the executing user :type username: str, optional :return: True on success, False otherwise :rtype: bool """ if username == None: username = user.username() if user.isRoot(): return _installPrinter(username, networkPath, name) else: # This will call installPrinter() again with root privileges return _installPrinterWithoutRoot(networkPath, name) pass