def _req_print_guid(self, guidList, attrs, delimiter=None): legacyDNList = [] for guid in guidList: legacyDNList.append(get_dn_from_guid(guid, minimize=True)) resp = nspi.hNspiResolveNamesW(self.__dce, self.__handler, pPropTags=attrs, paStr=legacyDNList) try: # Addressing to PropertyRowSet_r must be inside try / except, # as if the server returned a wrong result, it can be in # multiple of forms, and we cannot easily determine it # before parsing if resp['ppRows']['cRows'] <= 0: return 0 # Addressing to PropertyRowSet_r must be inside try / except, # as if the server returned a wrong result, it can be in # multiple of forms, and we cannot easily determine it # before parsing resp_rows = nspi.simplifyPropertyRowSet(resp['ppRows']) except Exception as e: resp.dumpRaw() logging.error(str(e)) raise Exception("NspiResolveNamesW returned wrong result") for row in resp_rows: self.print_row(row, delimiter) return resp['ppRows']['cRows']
def req_print_table_rows(self, table_MId=None, attrs=[], count=50, eTable=None, onlyCheck=False): printOnlyGUIDs = False useAsExplicitTable = False if self.anyExistingContainerID == -1: self.load_htable_containerid() if table_MId == None and eTable == None: raise Exception("Wrong arguments!") elif table_MId != None and eTable != None: raise Exception("Wrong arguments!") elif table_MId != None: # Let's call NspiUpdateStat # It's important when the given MId is taken from the hierarchy table, # especially in Multi-Tenant environments self.update_stat(table_MId) # Table end reached if self.stat['CurrentRec'] == nspi.MID_END_OF_TABLE: # Returning False to support onlyCheck return False else: # eTable != None useAsExplicitTable = True if attrs == self.PROPS_GUID: # GUIDS firstReqProps = self.PROPS_GUID printOnlyGUIDs = True elif attrs == self.PROPS_MINUMAL: # MINIMAL firstReqProps = self.PROPS_MINUMAL elif attrs == []: # FULL # Requesting a list of all the properties that the server knows if self.props == []: self.load_props() attrs = self.props # To avoid MAPI_E_NOT_ENOUGH_RESOURCES error we request MIds, # and then use them as an Explicit Table firstReqProps = [PR_INSTANCE_KEY] useAsExplicitTable = True else: # EXTENDED and custom # # To avoid MAPI_E_NOT_ENOUGH_RESOURCES error we request MIds, # and then use them as an Explicit Table firstReqProps = [PR_INSTANCE_KEY] useAsExplicitTable = True if onlyCheck: attrs = self.PROPS_GUID firstReqProps = self.PROPS_GUID useAsExplicitTable = True while True: if eTable == None: resp = nspi.hNspiQueryRows(self.__dce, self.__handler, pStat=self.stat, Count=count, pPropTags=firstReqProps) self.stat = resp['pStat'] try: # Addressing to PropertyRowSet_r must be inside try / except, # as if the server returned a wrong result, it can be in # multiple of forms, and we cannot easily determine it # before parsing resp_rows = nspi.simplifyPropertyRowSet(resp['ppRows']) except Exception as e: resp.dumpRaw() logging.error(str(e)) raise Exception("NspiQueryRows returned wrong result") if onlyCheck: if len(resp_rows) == 0: return False for row in resp_rows: # PropertyId = 0x8C6D (objectGUID) # PropertyType = 0x000A (error) if 0x8C6D000A not in row: return True return False if useAsExplicitTable: if eTable == None: eTableInt = [] for row in resp_rows: eTableInt.append(row[PR_INSTANCE_KEY]) else: eTableInt = eTable resp = nspi.hNspiQueryRows(self.__dce, self.__handler, ContainerID=self.anyExistingContainerID, Count=count, pPropTags=attrs, lpETable=eTableInt) try: # Addressing to PropertyRowSet_r must be inside try / except, # as if the server returned a wrong result, it can be in # multiple of forms, and we cannot easily determine it # before parsing resp_rows = nspi.simplifyPropertyRowSet(resp['ppRows']) except Exception as e: resp.dumpRaw() logging.error(str(e)) raise Exception("NspiQueryRows returned wrong result while processing explicit table") if onlyCheck: if len(resp_rows) == 0: return False for row in resp_rows: # PropertyId = 0x8C6D (objectGUID) # PropertyType = 0x000A (error) if 0x8C6D000A not in row: return True return False if printOnlyGUIDs: for row in resp_rows: if PR_EMS_AB_OBJECT_GUID in row: objectGuid = row[PR_EMS_AB_OBJECT_GUID] self.print(objectGuid) else: # Empty row (wrong MId) pass else: for row in resp_rows: self.print_row(row, DELIMITER) # When the caller specified eTable it's always one NspiQueryRows call if eTable != None: break # Table end reached # It also MUST be checked after NspiUpdateStat if self.stat['CurrentRec'] == nspi.MID_END_OF_TABLE: break # This should not happen if len(resp_rows) == 0: break
def load_htable(self): resp = nspi.hNspiGetSpecialTable(self.__dce, self.__handler) resp_simpl = nspi.simplifyPropertyRowSet(resp['ppRows']) self._parse_and_set_htable(resp_simpl)