Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3780 lines
132 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // Properties utility object implementation
  7. //
  8. //
  9. // Notes - there are two main methods in this module:
  10. // - CUtilProps::GetPropertyInfo, a helper function for IDBInfo::GetPropertyInfo
  11. // - CUtilProps::GetProperties, a helper function for IRowsetInfo::GetProperties
  12. //
  13. // Our property implementation is simplified considerably by the fact that we
  14. // only support reading\getting the properties, we do not support
  15. // writing\setting them. This makes sense because we are a simple provider,
  16. // and our rowset object always creates all the interfaces it exposes. In
  17. // other words, there are really no properties the consumer could set.
  18. //
  19. // The implementation is very simple - we keep a global table of the
  20. // properties we support in s_rgprop. We search this table sequentially.
  21. //
  22. // Note that a full-featured provider would probably need to use a more
  23. // sophisticated implementation. We keep the entire GUID for each property in
  24. // our struct, which would become a waste of space if we had a lot more
  25. // properties. Similarly, with large numbers of properties some sort of
  26. // hashing would be better than the sequential search used here.
  27. //
  28. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  29. #include "headers.h"
  30. #include "wmiver.h"
  31. #define __TXT(x) L ## x
  32. #define _TEXT_T(x) __TXT(x)
  33. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. //
  35. // Struct containing the properties we know about. The GUID and string fields are
  36. // initialized in the constructor, because C++ makes it awkward to do so at declaration
  37. // time. So, if you change this table, be sure to make parallel changes in CUtilProp::CUtilProp.
  38. //
  39. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  40. #define PRIVILEGE_NAMESIZE 255
  41. const GUID DBPROPSET_WMIOLEDB_DBINIT = {0xdd497a71,0x9628,0x11d3,{0x9d,0x5f,0x0,0xc0,0x4f,0x5f,0x11,0x64}};
  42. const GUID DBPROPSET_WMIOLEDB_ROWSET = {0x8d16c220,0x9bbb,0x11d3,{0x9d,0x65,0x0,0xc0,0x4f,0x5f,0x11,0x64}};
  43. const GUID DBPROPSET_WMIOLEDB_COLUMN = {0x3ed51791,0x9c76,0x11d3,{0x9d,0x66,0x0,0xc0,0x4f,0x5f,0x11,0x64}};
  44. const GUID DBPROPSET_WMIOLEDB_COMMAND = {0xda0ff63c,0xad10,0x11d3,{0xb3,0xcb,0x0,0x10,0x4b,0xcc,0x48,0xc4}};
  45. PROPSTRUCT s_rgprop[] =
  46. {
  47. /* 0*/ {DBPROP_INIT_DATASOURCE, FLAGS_DBINITRW, VT_BSTR, FALSE, 0, NULL, L"Data Source"},
  48. /* 1*/ {DBPROP_INIT_HWND, FLAGS_DBINITRW, VT_I4, FALSE, 0, NULL, L"Window Handle"},
  49. /* 2*/ {DBPROP_INIT_PROMPT, FLAGS_DBINITRW, VT_I2, FALSE, 4, NULL, L"Prompt"},
  50. /* 3*/ {DBPROP_INIT_PROTECTION_LEVEL, FLAGS_DBINITRW, VT_I4, FALSE, DB_PROT_LEVEL_CONNECT, NULL, L"Protection Level"},
  51. /* 4*/ {DBPROP_INIT_IMPERSONATION_LEVEL, FLAGS_DBINITRW, VT_I4, FALSE, DB_IMP_LEVEL_IMPERSONATE, NULL, L"Impersonation Level"},
  52. /* 5*/ {DBPROP_INIT_MODE, FLAGS_DBINITRW, VT_I4, TRUE, DB_MODE_READWRITE, NULL, L"Mode"},
  53. /* 6*/ {DBPROP_AUTH_USERID, FLAGS_DBINITRW, VT_BSTR, FALSE, 0, NULL, L"User ID"},
  54. /* 7*/ {DBPROP_AUTH_PASSWORD, FLAGS_DBINITRW, VT_BSTR, FALSE, 0, NULL, L"Password"},
  55. /* 8*/ {DBPROP_INIT_LCID, FLAGS_DBINITRW, VT_I4, FALSE, 0, NULL, L"Locale Identifier"},
  56. /* 9*/ {DBPROP_WMIOLEDB_QUALIFIERS , FLAGS_DBINITRW , VT_I4, FALSE , 0,NULL, L"Qualifiers"},
  57. /* 10*/ {DBPROP_WMIOLEDB_SYSTEMPROPERTIES , FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"System Properties"},
  58. /* 11*/ {DBPROP_WMIOLEDB_AUTHORITY , FLAGS_DBINITRW , VT_BSTR, FALSE , 0,NULL, L"Authority"},
  59. // security priveleges
  60. /* 12*/ {DBPROP_WMIOLEDB_PREV_CREATE_TOKEN, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Create Token Privilege"},
  61. /* 13*/ {DBPROP_WMIOLEDB_PREV_ASSIGNPRIMARYTOKEN, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Assign Primary Token Privilege"},
  62. /* 14*/ {DBPROP_WMIOLEDB_PREV_LOCK_MEMORY, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Lock Memory Privilege"},
  63. /* 15*/ {DBPROP_WMIOLEDB_PREV_INCREASE_QUOTA, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Increase Quota Privilege"},
  64. /* 16*/ {DBPROP_WMIOLEDB_PREV_MACHINE_ACCOUNT, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Machine Account Privilege"},
  65. /* 17*/ {DBPROP_WMIOLEDB_PREV_TCB, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Tcb Privilege"},
  66. /* 18*/ {DBPROP_WMIOLEDB_PREV_SECURITY, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Security Privilege"},
  67. /* 19*/ {DBPROP_WMIOLEDB_PREV_TAKE_OWNERSHIP, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Take Ownership Privilege"},
  68. /* 20*/ {DBPROP_WMIOLEDB_PREV_LOAD_DRIVER, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Load Driver Privilege"},
  69. /* 21*/ {DBPROP_WMIOLEDB_PREV_SYSTEM_PROFILE, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"System Profile Privilege"},
  70. /* 22*/ {DBPROP_WMIOLEDB_PREV_SYSTEMTIME, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Systemtime Privilege"},
  71. /* 23*/ {DBPROP_WMIOLEDB_PREV_PROF_SINGLE_PROCESS, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Profile SingleProcess Privilege"},
  72. /* 24*/ {DBPROP_WMIOLEDB_PREV_INC_BASE_PRIORITY, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Increase BasePriority Privilege"},
  73. /* 25*/ {DBPROP_WMIOLEDB_PREV_CREATE_PAGEFILE , FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Create Pagefile Privilege"},
  74. /* 26*/ {DBPROP_WMIOLEDB_PREV_CREATE_PERMANENT , FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Create Permanent Privilege"},
  75. /* 27*/ {DBPROP_WMIOLEDB_PREV_BACKUP, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Backup Privilege"},
  76. /* 28*/ {DBPROP_WMIOLEDB_PREV_RESTORE, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Restore Privilege"},
  77. /* 29*/ {DBPROP_WMIOLEDB_PREV_SHUTDOWN, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Shutdown Privilege"},
  78. /* 30*/ {DBPROP_WMIOLEDB_PREV_DEBUG, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Debug Privilege"},
  79. /* 31*/ {DBPROP_WMIOLEDB_PREV_AUDIT , FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Audit Privilege"},
  80. /* 32*/ {DBPROP_WMIOLEDB_PREV_SYSTEM_ENVIRONMENT , FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"System Environment Privilege"},
  81. /* 33*/ {DBPROP_WMIOLEDB_PREV_CHANGE_NOTIFY, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Change Notify Privilege"},
  82. /* 34*/ {DBPROP_WMIOLEDB_PREV_REMOTE_SHUTDOWN, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Remote Shutdown Privilege"},
  83. /* 35*/ {DBPROP_WMIOLEDB_PREV_UNDOCK, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Undock Privilege"},
  84. /* 36*/ {DBPROP_WMIOLEDB_PREV_SYNC_AGENT, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"SyncAgent Privilege"},
  85. /* 37*/ {DBPROP_WMIOLEDB_PREV_ENABLE_DELEGATION, FLAGS_DBINITRW , VT_BOOL, FALSE , 0,NULL, L"Enable Delegation Privilege"},
  86. // Session properties should come here
  87. // Data Source properties
  88. /* 38*/ {DBPROP_ACTIVESESSIONS, FLAGS_DATASRCINF, VT_I4, FALSE, 1, NULL, L"Active Sessions"},
  89. /* 39*/ {DBPROP_PERSISTENTIDTYPE, FLAGS_DATASRCINF, VT_I4, FALSE, DBPROPVAL_PT_GUID_PROPID, NULL, L"Persistent ID Type"},
  90. /* 40*/ {DBPROP_PROVIDERFILENAME, FLAGS_DATASRCINF, VT_BSTR, FALSE, 0, L"WMIOLEDB.DLL",L"Provider Name"},
  91. /* 41*/ {DBPROP_PROVIDERFRIENDLYNAME, FLAGS_DATASRCINF, VT_BSTR, FALSE, 0, L"Microsoft WMIOLE DB Provider",L"Provider Friendly Name"},
  92. /* 42*/ {DBPROP_PROVIDEROLEDBVER, FLAGS_DATASRCINF, VT_BSTR, FALSE, 0, L"02.00", L"OLE DB Version"},
  93. /* 43*/ {DBPROP_PROVIDERVER, FLAGS_DATASRCINF, VT_BSTR, FALSE, 0, _TEXT_T(VER_PRODUCTVERSION_STR), L"Provider Version"},
  94. /* 44*/ {DBPROP_GENERATEURL, FLAGS_DATASRCINF, VT_I4, FALSE, DBPROPVAL_GU_NOTSUPPORTED, NULL, L"URL Generation"},
  95. /* 45*/ {DBPROP_ALTERCOLUMN, FLAGS_DATASRCINF, VT_I4, FALSE, DBCOLUMNDESCFLAGS_PROPERTIES, NULL, L"Alter Column Support"},
  96. /* 45*/ {DBPROP_MULTIPLERESULTS, FLAGS_DATASRCINF, VT_I4, FALSE, 0, NULL, L"Multiple Results"},
  97. /* 45*/ {DBPROP_OLEOBJECTS, FLAGS_DATASRCINF, VT_I4, FALSE, DBPROPVAL_OO_ROWOBJECT, NULL, L"OLE Object Support"},
  98. // Command properties should come here
  99. ///* 75*/ {DBPROP_WMIOLEDB_ISMETHOD, FLAGS_ROWSETRW, VT_BOOL, FALSE, 0, NULL, L"Method"},
  100. ///* 75*/ {DBPROP_WMIOLEDB_QUERYLANGUAGE, FLAGS_ROWSETRW, VT_BSTR, FALSE, 0, NULL, L"Query Language"},
  101. /* 46*/ {DBPROP_IAccessor, FLAGS_ROWSETRO, VT_BOOL, TRUE, 0, NULL, L"IAccessor"},
  102. /* 47*/ {DBPROP_IColumnsInfo, FLAGS_ROWSETRO, VT_BOOL, TRUE, 0, NULL, L"IColumnsInfo"},
  103. /* 48*/ {DBPROP_IConvertType, FLAGS_ROWSETRO, VT_BOOL, TRUE, 0, NULL, L"IConvertType"},
  104. /* 49*/ {DBPROP_IRowset, FLAGS_ROWSETRO, VT_BOOL, TRUE, 0, NULL, L"IRowset"},
  105. /* 50*/ {DBPROP_IRowsetChange, FLAGS_ROWSETRW, VT_BOOL, TRUE, 0, NULL, L"IRowsetChange"},
  106. /* 51*/ {DBPROP_IRowsetInfo, FLAGS_ROWSETRO, VT_BOOL, TRUE, 0, NULL, L"IRowsetInfo"},
  107. /* 52*/ {DBPROP_IRowsetIdentity, FLAGS_ROWSETRO, VT_BOOL, TRUE, 0, NULL, L"IRowsetIdentity"},
  108. /* 53*/ {DBPROP_IRowsetLocate, FLAGS_ROWSETRW, VT_BOOL, FALSE, 0, NULL, L"IRowsetLocate"},
  109. /* 54*/ {DBPROP_CANHOLDROWS, FLAGS_ROWSETRW, VT_BOOL, TRUE, 0, NULL, L"Hold Rows"},
  110. /* 55*/ {DBPROP_LITERALIDENTITY, FLAGS_ROWSETRW, VT_BOOL, TRUE, 0, NULL, L"Literal Row Identity"},
  111. /* 56*/ {DBPROP_UPDATABILITY, FLAGS_ROWSETRW, VT_I4, TRUE, 0, NULL, L"Updatability"},
  112. /* 57*/ {DBPROP_OWNUPDATEDELETE, FLAGS_ROWSETRW, VT_BOOL, FALSE, 0, NULL, L"Own Changes Visible"},
  113. ///**/ {DBPROP_IRowsetUpdate, FLAGS_ROWSETRO, VT_BOOL, FALSE, 0, NULL, L"IRowsetUpdate"},
  114. /* 58*/ {DBPROP_ISequentialStream, FLAGS_ROWSETRO, VT_BOOL, FALSE, 0, NULL, L"ISequentialStream"},
  115. /* 59*/ {DBPROP_OTHERUPDATEDELETE, FLAGS_ROWSETRW, VT_BOOL, FALSE, 0, NULL, L"Others' Changes Visible"},
  116. /* 60*/ {DBPROP_CANFETCHBACKWARDS, FLAGS_ROWSETRW, VT_BOOL, FALSE, 0, NULL, L"Fetch Backwards"},
  117. /* 61*/ {DBPROP_CANSCROLLBACKWARDS, FLAGS_ROWSETRW, VT_BOOL, FALSE, 0, NULL, L"Scroll Backwards"},
  118. /* 62*/ {DBPROP_BOOKMARKS, FLAGS_ROWSETRW, VT_BOOL, TRUE, 0, NULL, L"Use Bookmarks"},
  119. /* 63*/ {DBPROP_BOOKMARKTYPE, FLAGS_ROWSETRO, VT_I4, TRUE, DBPROPVAL_BMK_NUMERIC, NULL, L"Bookmark Type"},
  120. /* 64*/ {DBPROP_IRow, FLAGS_ROWSETRW, VT_BOOL, FALSE, 0, NULL, L"IRow"},
  121. /* 65*/ {DBPROP_IGetRow, FLAGS_ROWSETRW, VT_BOOL, TRUE, 0, NULL, L"IGetRow"},
  122. /* 66*/ {DBPROP_IRowsetRefresh, FLAGS_ROWSETRW, VT_BOOL, TRUE, 0, NULL, L"IRowsetRefresh"},
  123. /* 67*/ {DBPROP_IChapteredRowset, FLAGS_ROWSETRW, VT_BOOL, TRUE, 0, NULL, L"IChapteredRowset"},
  124. /* 68*/ {DBPROP_REMOVEDELETED, FLAGS_ROWSETRO, VT_BOOL, FALSE, 0, NULL, L"Remove Deleted Rows"},
  125. /* 69*/ {DBPROP_OTHERINSERT, FLAGS_ROWSETRW, VT_BOOL, FALSE, 0, NULL, L"Others' Inserts Visible"},
  126. /* 70*/ {DBPROP_MAXOPENROWS, FLAGS_ROWSETRW, VT_I4, TRUE, 1024, NULL, L"Maximum Open Rows"},
  127. // WMIOLEDB_ROWSET properties
  128. /* 73*/ {DBPROP_WMIOLEDB_FETCHDEEP, FLAGS_ROWSETRW, VT_BOOL, FALSE, 0, NULL, L"Get Child Instances"},
  129. /* 74*/ {DBPROP_WMIOLEDB_OBJECTTYPE, FLAGS_ROWSETRW, VT_I4, TRUE, DBPROPVAL_SCOPEOBJ, NULL, L"Type of Object"},
  130. /* 75*/ {DBPROP_WMIOLEDB_ISMETHOD, FLAGS_ROWSETRW, VT_BOOL, FALSE, 0, NULL, L"Method"},
  131. /* 75*/ {DBPROP_WMIOLEDB_QUERYLANGUAGE, FLAGS_ROWSETRW, VT_BSTR, FALSE, 0, NULL, L"Query Language"},
  132. // ADSI Search Preferences
  133. /* 76*/ {DBPROP_WMIOLEDB_DS_DEREFALIAS, FLAGS_ROWSETRW, VT_I4, FALSE, 0, NULL, L"Deref Aliases"},
  134. /* 77*/ {DBPROP_WMIOLEDB_DS_SIZELIMIT, FLAGS_ROWSETRW, VT_I4, TRUE, 0, NULL, L"Size Limit"},
  135. /* 78*/ {DBPROP_WMIOLEDB_DS_SEARCHSCOPE, FLAGS_ROWSETRW, VT_I4, FALSE, 0, NULL, L"SearchScope"},
  136. /* 79*/ {DBPROP_WMIOLEDB_DS_TIMEOUT, FLAGS_ROWSETRW, VT_I4, TRUE, 0, NULL, L"Timeout"},
  137. /* 80*/ {DBPROP_WMIOLEDB_DS_PAGESIZE, FLAGS_ROWSETRW, VT_I4, TRUE, 0, NULL, L"Page Size"},
  138. /* 81*/ {DBPROP_WMIOLEDB_DS_TIMELIMIT, FLAGS_ROWSETRW, VT_I4, TRUE, 0, NULL, L"Time Limit"},
  139. /* 82*/ {DBPROP_WMIOLEDB_DS_CHASEREF, FLAGS_ROWSETRW, VT_I4, TRUE, 0, NULL, L"Chase Referals"},
  140. /* 83*/ {DBPROP_WMIOLEDB_DS_CACHERESULTS, FLAGS_ROWSETRW, VT_BOOL,TRUE, 0, NULL, L"Cache Results"},
  141. /* 84*/ {DBPROP_WMIOLEDB_DS_ASYNCH, FLAGS_ROWSETRW, VT_BOOL,FALSE, 0, NULL, L"Search Asynchronous"},
  142. /* 85*/ {DBPROP_WMIOLEDB_DS_ATTRIBONLY, FLAGS_ROWSETRW, VT_BOOL,FALSE, 0, NULL, L"Attributes Only"},
  143. /* 86*/ {DBPROP_WMIOLEDB_DS_PAGEDTIMELIMIT, FLAGS_ROWSETRW, VT_I4, FALSE, 0, NULL, L"Page size limit"},
  144. /* 87*/ {DBPROP_WMIOLEDB_DS_TOMBSTONE, FLAGS_ROWSETRW, VT_BOOL,FALSE, 0, NULL, L"TombStone"},
  145. /* 88*/ {DBPROP_WMIOLEDB_DS_FILTER, FLAGS_ROWSETRW, VT_BSTR,FALSE, 0, NULL, L"Filter"},
  146. /* 89*/ {DBPROP_WMIOLEDB_DS_ATTRIBUTES, FLAGS_ROWSETRW, VT_BSTR,FALSE, 0, NULL, L"Attributes"},
  147. // Column Properties
  148. /* 90*/ {DBPROP_COL_NULLABLE, FLAGS_COLUMNSRW, VT_BOOL, TRUE, 0, NULL, L"Nullable"},
  149. /* 91*/ {DBPROP_COL_UNIQUE, FLAGS_COLUMNSRW, VT_BOOL, TRUE, 0, NULL, L"Unique"},
  150. /* 92*/ {DBPROP_COL_PRIMARYKEY, FLAGS_COLUMNSRW, VT_BOOL, TRUE, 0, NULL, L"Primary Key"},
  151. // WMIOLEDB_COLUMN Properties
  152. /* 93*/ {DBPROP_WMIOLEDB_QUALIFIERFLAVOR, FLAGS_COLUMNSRW, VT_I4, TRUE, DBPROPVAL_FLAVOR_PROPOGAGTE_TO_INSTANCE, NULL, L"Qualifier Flavor"},
  153. };
  154. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  155. //
  156. // Constructor for this class
  157. //
  158. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  159. CUtilProp::CUtilProp (void)
  160. {
  161. /* m_prgproperties = NULL;
  162. m_cProperties = NUMBER_OF_SUPPORTED_PROPERTIES;
  163. m_prgproperties = (PROPSTRUCT *)g_pIMalloc->Alloc(sizeof(PROPSTRUCT) * m_cProperties);
  164. memcpy(m_prgproperties, &s_rgprop, sizeof(PROPSTRUCT) * m_cProperties );
  165. m_nPropStartIndex = 0;
  166. */
  167. m_propType = BINDERPROP;
  168. m_prgproperties = NULL;
  169. m_cProperties = 0;
  170. m_nPropStartIndex = 0;
  171. }
  172. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  173. //
  174. // Constructor for this class
  175. //
  176. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  177. CUtilProp::CUtilProp ( PROPERTYTYPE propType )
  178. {
  179. /*
  180. m_propType = propType;
  181. m_prgproperties = NULL;
  182. m_cProperties = 0;
  183. m_nPropStartIndex = 0;
  184. switch(propType)
  185. {
  186. case DATASOURCEPROP :
  187. m_cProperties = NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES + \
  188. NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES + \
  189. NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  190. m_nPropStartIndex = 0;
  191. break;
  192. case SESSIONPROP :
  193. m_cProperties = NUMBER_OF_SUPPORTED_SESSION_PROPERTIES;
  194. m_nPropStartIndex = START_OF_SUPPORTED_SESSION_PROPERTIES;
  195. break;
  196. // for command follow through to include even the rowset properties
  197. case COMMANDPROP :
  198. m_cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  199. m_nPropStartIndex = START_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  200. case ROWSETPROP :
  201. m_cProperties += NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES + NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  202. // if start index is no set by COMMANDPROP
  203. if(m_nPropStartIndex == 0)
  204. {
  205. m_nPropStartIndex = START_OF_SUPPORTED_ROWSET_PROPERTIES;
  206. }
  207. break;
  208. case BINDERPROP:
  209. m_cProperties = NUMBER_OF_SUPPORTED_PROPERTIES;
  210. m_nPropStartIndex = 0;
  211. break;
  212. case COLUMNPROP:
  213. m_cProperties = NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES + NUMBER_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  214. m_nPropStartIndex = START_OF_SUPPORTED_COLUMN_PROPERTIES;
  215. break;
  216. };
  217. if(m_cProperties > 0)
  218. {
  219. // m_prgproperties = (PROPSTRUCT *)g_pIMalloc->Alloc(sizeof(PROPSTRUCT) * m_cProperties);
  220. m_prgproperties = new PROPSTRUCT[m_cProperties];
  221. memcpy(m_prgproperties, &s_rgprop[m_nPropStartIndex], sizeof(PROPSTRUCT) * m_cProperties );
  222. SetDefaultValueForStringProperties(m_prgproperties,m_cProperties);
  223. }
  224. if( propType == DATASOURCEPROP || propType == BINDERPROP)
  225. {
  226. ULONG lIndex = 0;
  227. // Get the default LCID
  228. if(GetPropIndex(DBPROP_INIT_LCID,&lIndex))
  229. {
  230. m_prgproperties[lIndex].longVal = (SLONG)GetSystemDefaultLCID();
  231. }
  232. CPreviligeToken pvgToken;
  233. DBPROPIDSET rgPropertyIDSets[1];
  234. ULONG cPropertySets;
  235. DBPROPSET* prgPropertySets;
  236. HRESULT hr = S_OK;
  237. rgPropertyIDSets[0].guidPropertySet = DBPROPSET_WMIOLEDB_DBINIT;
  238. rgPropertyIDSets[0].rgPropertyIDs = NULL;
  239. rgPropertyIDSets[0].cPropertyIDs = 0;
  240. // NTRaid: 136443
  241. // 07/05/00
  242. hr = pvgToken.FInit();
  243. if(SUCCEEDED(hr) && SUCCEEDED(hr = GetProperties(PROPSET_DSO,1,rgPropertyIDSets,&cPropertySets,&prgPropertySets)))
  244. {
  245. pvgToken.SetDBPROPForPrivileges(prgPropertySets->cProperties ,prgPropertySets[0].rgProperties);
  246. hr = SetProperties(PROPSET_DSO,1,prgPropertySets);
  247. //==========================================================================
  248. // Free memory we allocated to get the namespace property above
  249. //==========================================================================
  250. m_PropMemMgr.FreeDBPROPSET( cPropertySets, prgPropertySets);
  251. }
  252. }
  253. */
  254. }
  255. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  256. //
  257. // Destructor for this class
  258. //
  259. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  260. CUtilProp:: ~CUtilProp (void )
  261. {
  262. SAFE_DELETE_ARRAY(m_prgproperties);
  263. }
  264. HRESULT CUtilProp:: FInit(PROPERTYTYPE propType)
  265. {
  266. HRESULT hr = S_OK;
  267. m_propType = propType;
  268. switch(propType)
  269. {
  270. case DATASOURCEPROP :
  271. m_cProperties = NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES + \
  272. NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES + \
  273. NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  274. m_nPropStartIndex = 0;
  275. break;
  276. case SESSIONPROP :
  277. m_cProperties = NUMBER_OF_SUPPORTED_SESSION_PROPERTIES;
  278. m_nPropStartIndex = START_OF_SUPPORTED_SESSION_PROPERTIES;
  279. break;
  280. // for command follow through to include even the rowset properties
  281. case COMMANDPROP :
  282. m_cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  283. m_nPropStartIndex = START_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  284. case ROWSETPROP :
  285. m_cProperties += NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES + NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  286. // if start index is no set by COMMANDPROP
  287. if(m_nPropStartIndex == 0)
  288. {
  289. m_nPropStartIndex = START_OF_SUPPORTED_ROWSET_PROPERTIES;
  290. }
  291. break;
  292. case BINDERPROP:
  293. m_cProperties = NUMBER_OF_SUPPORTED_PROPERTIES;
  294. m_nPropStartIndex = 0;
  295. break;
  296. case COLUMNPROP:
  297. m_cProperties = NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES + NUMBER_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  298. m_nPropStartIndex = START_OF_SUPPORTED_COLUMN_PROPERTIES;
  299. break;
  300. };
  301. if(m_cProperties > 0)
  302. {
  303. // m_prgproperties = (PROPSTRUCT *)g_pIMalloc->Alloc(sizeof(PROPSTRUCT) * m_cProperties);
  304. m_prgproperties = new PROPSTRUCT[m_cProperties];
  305. if(m_prgproperties)
  306. {
  307. memcpy(m_prgproperties, &s_rgprop[m_nPropStartIndex], sizeof(PROPSTRUCT) * m_cProperties );
  308. SetDefaultValueForStringProperties(m_prgproperties,m_cProperties);
  309. }
  310. else
  311. {
  312. hr = E_OUTOFMEMORY;
  313. }
  314. }
  315. if (SUCCEEDED(hr) &&( propType == DATASOURCEPROP || propType == BINDERPROP))
  316. {
  317. ULONG lIndex = 0;
  318. // Get the default LCID
  319. if(GetPropIndex(DBPROP_INIT_LCID,&lIndex))
  320. {
  321. m_prgproperties[lIndex].longVal = (SLONG)GetSystemDefaultLCID();
  322. }
  323. CPreviligeToken pvgToken;
  324. DBPROPIDSET rgPropertyIDSets[1];
  325. ULONG cPropertySets;
  326. DBPROPSET* prgPropertySets;
  327. HRESULT hr = S_OK;
  328. rgPropertyIDSets[0].guidPropertySet = DBPROPSET_WMIOLEDB_DBINIT;
  329. rgPropertyIDSets[0].rgPropertyIDs = NULL;
  330. rgPropertyIDSets[0].cPropertyIDs = 0;
  331. // NTRaid: 136443
  332. // 07/05/00
  333. hr = pvgToken.FInit();
  334. if(SUCCEEDED(hr) && SUCCEEDED(hr = GetProperties(PROPSET_DSO,1,rgPropertyIDSets,&cPropertySets,&prgPropertySets)))
  335. {
  336. pvgToken.SetDBPROPForPrivileges(prgPropertySets->cProperties ,prgPropertySets[0].rgProperties);
  337. hr = SetProperties(PROPSET_DSO,1,prgPropertySets);
  338. //==========================================================================
  339. // Free memory we allocated to get the namespace property above
  340. //==========================================================================
  341. m_PropMemMgr.FreeDBPROPSET( cPropertySets, prgPropertySets);
  342. }
  343. }
  344. return hr;
  345. }
  346. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  347. //
  348. // Returns index of the given property in the property set
  349. //
  350. // BOOL
  351. // TRUE found match, copied it to pulIndex out-param
  352. // FALSE no match. In this case, pulIndex has no meaning
  353. //
  354. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  355. BOOL CUtilProp::GetPropIndex ( DBPROPID dwPropertyID, //IN PROPID of desired property
  356. ULONG* pulIndex) //OUT index of desired property if return was TRUE
  357. {
  358. ULONG cNumberOfProperties;
  359. BOOL fRc = FALSE;
  360. assert( pulIndex );
  361. for ( cNumberOfProperties = 0; cNumberOfProperties < m_cProperties; cNumberOfProperties++) {
  362. if (dwPropertyID == m_prgproperties[cNumberOfProperties].dwPropertyID ) {
  363. //==============================================================
  364. // found a match
  365. //==============================================================
  366. *pulIndex = cNumberOfProperties;
  367. fRc = TRUE;
  368. break;
  369. }
  370. }
  371. return fRc;
  372. }
  373. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  374. //
  375. // Returns index of the given property in our global table of properties
  376. //
  377. // BOOL
  378. // TRUE found match, copied it to pulIndex out-param
  379. // FALSE no match. In this case, pulIndex has no meaning
  380. //
  381. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  382. BOOL CUtilProp::GetPropIndexFromAllSupportedProps ( DBPROPID dwPropertyID, //IN PROPID of desired property
  383. ULONG* pulIndex) //OUT index of desired property if return was TRUE
  384. {
  385. ULONG cNumberOfProperties;
  386. BOOL fRc = FALSE;
  387. assert( pulIndex );
  388. for ( cNumberOfProperties = 0; cNumberOfProperties < NUMBER_OF_SUPPORTED_PROPERTIES; cNumberOfProperties++) {
  389. if (dwPropertyID == s_rgprop[cNumberOfProperties].dwPropertyID ) {
  390. //==============================================================
  391. // found a match
  392. //==============================================================
  393. *pulIndex = cNumberOfProperties;
  394. fRc = TRUE;
  395. break;
  396. }
  397. }
  398. return fRc;
  399. }
  400. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  401. //
  402. // Helper for GetPropertyInfo. Loads field of DBPROPINFO structure.
  403. //
  404. // BOOL
  405. // TRUE Method succeeded
  406. // FALSE Method failed (couldn't allocate memory)
  407. //
  408. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  409. BOOL CUtilProp::LoadDBPROPINFO ( PROPSTRUCT* pPropStruct, DBPROPINFO* pPropInfo )
  410. {
  411. assert( pPropStruct );
  412. assert( pPropInfo );
  413. //=======================================================================
  414. // init the variant
  415. //=======================================================================
  416. VariantInit( &pPropInfo->vValues );
  417. //=======================================================================
  418. // set the easy fields..
  419. //=======================================================================
  420. pPropInfo->dwPropertyID = pPropStruct->dwPropertyID;
  421. pPropInfo->dwFlags = pPropStruct->dwFlags;
  422. pPropInfo->vtType = pPropStruct->vtType;
  423. //=======================================================================
  424. // fill in the description
  425. //=======================================================================
  426. if ( pPropInfo->pwszDescription ){
  427. wcscpy(pPropInfo->pwszDescription, pPropStruct->pwstrDescBuffer);
  428. }
  429. //=======================================================================
  430. // all went well
  431. //=======================================================================
  432. return TRUE;
  433. }
  434. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  435. //
  436. // Helper for GetProperties. Loads field of DBPROP structure.
  437. //
  438. // BOOL
  439. // TRUE Method succeeded
  440. // FALSE Method failed (couldn't allocate memory)
  441. //
  442. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  443. BOOL CUtilProp::LoadDBPROP ( PROPSTRUCT* pPropStruct, DBPROP* pPropSupport )
  444. {
  445. assert( pPropStruct );
  446. assert( pPropSupport );
  447. //========================================================================
  448. // init the variant
  449. //========================================================================
  450. VariantInit( &pPropSupport->vValue );
  451. //========================================================================
  452. // set the easy fields..
  453. //========================================================================
  454. pPropSupport->dwPropertyID = pPropStruct->dwPropertyID;
  455. pPropSupport->colid = DB_NULLID;
  456. pPropSupport->dwStatus = DBPROPSTATUS_OK;
  457. //========================================================================
  458. // set pPropSupport->vValue based on Variant type
  459. //========================================================================
  460. switch (pPropStruct->vtType){
  461. case VT_BOOL:
  462. V_VT( &pPropSupport->vValue ) = VT_BOOL;
  463. if( pPropStruct->boolVal )
  464. V_BOOL( &pPropSupport->vValue ) = VARIANT_TRUE;
  465. else
  466. V_BOOL( &pPropSupport->vValue ) = VARIANT_FALSE;
  467. break;
  468. case VT_I2:
  469. V_VT( &pPropSupport->vValue ) = VT_I2;
  470. V_I2( &pPropSupport->vValue ) = (SHORT)pPropStruct->longVal;
  471. break;
  472. case VT_I4:
  473. V_VT( &pPropSupport->vValue ) = VT_I4;
  474. V_I4( &pPropSupport->vValue ) = pPropStruct->longVal;
  475. break;
  476. case VT_BSTR:
  477. if( pPropStruct->pwstrVal ){
  478. V_VT( &pPropSupport->vValue ) = VT_BSTR;
  479. V_BSTR( &pPropSupport->vValue ) = Wmioledb_SysAllocString( pPropStruct->pwstrVal );
  480. }
  481. /* else
  482. VariantClear( &pPropSupport->vValue );
  483. */ break;
  484. case VT_UI4:
  485. V_VT( &pPropSupport->vValue ) = VT_I4;
  486. V_UI4( &pPropSupport->vValue ) = pPropStruct->longVal;
  487. break;
  488. default:
  489. assert( !"LoadDBPROP unknown variant type!\n\r" );
  490. break;
  491. }
  492. // all went well
  493. return TRUE;
  494. }
  495. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  496. //
  497. // Initialize the buffers and check for E_INVALIDARG cases
  498. //
  499. // NOTE: This routine is used by RowsetInfo and IDBProperties
  500. //
  501. // HRESULT indicating the status of the method
  502. // S_OK Properties gathered
  503. // E_INVALIDARG Invalid parameter values
  504. //
  505. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  506. HRESULT CUtilProp::GetPropertiesArgChk( DWORD dwBitMask, //IN Mask for object
  507. const ULONG cPropertySets, //IN Number of property Sets
  508. const DBPROPIDSET rgPropertySets[], //IN Property Classes and Ids
  509. ULONG* pcProperties, //OUT Count of structs returned
  510. DBPROPSET** prgProperties, //OUT Array of Properties
  511. BOOL bDSOInitialized )
  512. {
  513. HRESULT hr = S_OK;
  514. //================================================================
  515. // Initialize values
  516. //================================================================
  517. if( pcProperties ){
  518. *pcProperties = 0;
  519. }
  520. if( prgProperties ){
  521. *prgProperties = NULL;
  522. }
  523. //================================================================
  524. // Check Arguments
  525. //================================================================
  526. if (((cPropertySets > 0) && !rgPropertySets) ||
  527. !pcProperties ||
  528. !prgProperties )
  529. {
  530. hr = E_INVALIDARG ;
  531. }
  532. else{
  533. //=========================================================================
  534. // New argument check for > 1 cPropertyIDs and NULL pointer
  535. // for array of property ids.
  536. //=========================================================================
  537. for(ULONG ul=0; ul<cPropertySets && hr == S_OK; ul++){
  538. if(( rgPropertySets[ul].guidPropertySet == DBPROPSET_PROPERTIESINERROR &&
  539. (rgPropertySets[ul].cPropertyIDs != 0 || rgPropertySets[0].rgPropertyIDs != NULL ||
  540. cPropertySets > 1)) && (dwBitMask == DATASOURCEPROP || dwBitMask == COMMANDPROP))
  541. {
  542. hr = E_INVALIDARG;
  543. break;
  544. }
  545. else
  546. if( rgPropertySets[ul].cPropertyIDs && !(rgPropertySets[ul].rgPropertyIDs) )
  547. {
  548. hr = E_INVALIDARG;
  549. }
  550. else
  551. {
  552. // Check if all the propertysetID's are correct for this object
  553. hr = IsValidPropertySet(bDSOInitialized,rgPropertySets[ul].guidPropertySet);
  554. }
  555. if(FAILED(hr))
  556. {
  557. hr = E_INVALIDARG;
  558. break;
  559. }
  560. else
  561. hr = S_OK;
  562. }
  563. }
  564. return hr;
  565. }
  566. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  567. //
  568. // Validate that the variant contains legal values for it's particalur type and for the particular PROPID in this
  569. // propset.
  570. //
  571. // HRESULT indicating status
  572. //
  573. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  574. HRESULT CUtilProp::IsValidValue(DBPROP* pDBProp )
  575. {
  576. HRESULT hr = S_OK;
  577. ULONG lIndex = 0;
  578. //===========================================================================
  579. // Check BOOLEAN values
  580. //===========================================================================
  581. if( (pDBProp->vValue.vt == VT_BOOL) && !((V_BOOL(&(pDBProp->vValue)) == VARIANT_TRUE) ||
  582. (V_BOOL(&(pDBProp->vValue)) == VARIANT_FALSE)) ){
  583. hr = S_FALSE;
  584. }
  585. else if( pDBProp->vValue.vt != VT_EMPTY && pDBProp->vValue.vt != VT_NULL){
  586. if(GetPropIndex(pDBProp->dwPropertyID,&lIndex) == FALSE)
  587. hr = FALSE;
  588. else
  589. if(pDBProp->vValue.vt != m_prgproperties[lIndex].vtType)
  590. hr = S_FALSE;
  591. else
  592. {
  593. switch( pDBProp->dwPropertyID ) {
  594. case DBPROP_INIT_DATASOURCE:
  595. case DBPROP_AUTH_USERID:
  596. case DBPROP_AUTH_PASSWORD:
  597. case DBPROP_WMIOLEDB_AUTHORITY:
  598. case DBPROP_WMIOLEDB_QUERYLANGUAGE:
  599. if( pDBProp->vValue.vt != VT_BSTR ){
  600. hr = S_FALSE;
  601. }
  602. break;
  603. case DBPROP_INIT_HWND:
  604. if( pDBProp->vValue.vt != VT_I4 ){
  605. hr = S_FALSE;
  606. }
  607. break;
  608. case DBPROP_INIT_PROMPT:
  609. //===============================================================
  610. // These are the only values we support (from spec).
  611. //===============================================================
  612. if ( (pDBProp->vValue.vt == VT_I2) &&
  613. !(V_I2(&pDBProp->vValue) == DBPROMPT_PROMPT ||
  614. V_I2(&pDBProp->vValue) == DBPROMPT_COMPLETE ||
  615. V_I2(&pDBProp->vValue) == DBPROMPT_COMPLETEREQUIRED ||
  616. V_I2(&pDBProp->vValue) == DBPROMPT_NOPROMPT)){
  617. hr = S_FALSE;
  618. }
  619. break;
  620. case DBPROP_INIT_PROTECTION_LEVEL:
  621. if (!( V_I4(&pDBProp->vValue) == DB_PROT_LEVEL_NONE ||
  622. V_I4(&pDBProp->vValue) == DB_PROT_LEVEL_CONNECT ||
  623. V_I4(&pDBProp->vValue) == DB_PROT_LEVEL_CALL ||
  624. V_I4(&pDBProp->vValue) == DB_PROT_LEVEL_PKT ||
  625. V_I4(&pDBProp->vValue) == DB_PROT_LEVEL_PKT ||
  626. V_I4(&pDBProp->vValue) == DB_PROT_LEVEL_PKT_PRIVACY))
  627. {
  628. hr = S_FALSE;
  629. }
  630. break;
  631. case DBPROP_INIT_IMPERSONATION_LEVEL:
  632. if (!( V_I4(&pDBProp->vValue) == DB_IMP_LEVEL_ANONYMOUS ||
  633. V_I4(&pDBProp->vValue) == DB_IMP_LEVEL_IDENTIFY ||
  634. V_I4(&pDBProp->vValue) == DB_IMP_LEVEL_IMPERSONATE ||
  635. V_I4(&pDBProp->vValue) == DB_IMP_LEVEL_DELEGATE )) {
  636. hr = S_FALSE;
  637. }
  638. break;
  639. case DBPROP_INIT_MODE:
  640. switch(V_I4(&pDBProp->vValue))
  641. {
  642. case DB_MODE_READ:
  643. case DB_MODE_WRITE:
  644. case DB_MODE_READWRITE:
  645. case DB_MODE_SHARE_DENY_READ:
  646. case DB_MODE_SHARE_EXCLUSIVE:
  647. case DB_MODE_SHARE_DENY_NONE:
  648. case DB_MODE_SHARE_EXCLUSIVE|DB_MODE_SHARE_DENY_NONE:
  649. case DB_MODE_READ|DB_MODE_WRITE|DB_MODE_READWRITE|DB_MODE_SHARE_DENY_READ|DB_MODE_SHARE_DENY_WRITE|DB_MODE_SHARE_EXCLUSIVE|DB_MODE_SHARE_DENY_NONE:
  650. hr = S_OK;
  651. break;
  652. default:
  653. hr = S_FALSE;
  654. };
  655. break;
  656. case DBPROP_WMIOLEDB_QUALIFIERS:
  657. if (!( V_I4(&pDBProp->vValue) == DBPROP_WM_CLASSQUALIFIERS ||
  658. V_I4(&pDBProp->vValue) == DBPROP_WM_PROPERTYQUALIFIERS ||
  659. V_I4(&pDBProp->vValue) == 0 ||
  660. V_I4(&pDBProp->vValue) == (DBPROP_WM_PROPERTYQUALIFIERS | DBPROP_WM_CLASSQUALIFIERS) ))
  661. {
  662. hr = S_FALSE;
  663. }
  664. break;
  665. case DBPROP_UPDATABILITY:
  666. if (!( V_I4(&pDBProp->vValue) <= (DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_DELETE | DBPROPVAL_UP_INSERT) &&
  667. V_I4(&pDBProp->vValue) >= 0))
  668. {
  669. hr = S_FALSE;
  670. }
  671. break;
  672. case DBPROP_MAXOPENROWS:
  673. if(V_I4(&pDBProp->vValue) > MAXOPENROWS &&
  674. V_I4(&pDBProp->vValue) <= 0)
  675. {
  676. hr = S_FALSE;
  677. }
  678. break;
  679. case DBPROP_WMIOLEDB_OBJECTTYPE:
  680. if(!( (V_I4(&pDBProp->vValue) == DBPROPVAL_SCOPEOBJ) ||
  681. (V_I4(&pDBProp->vValue) == DBPROPVAL_CONTAINEROBJ) ||
  682. (V_I4(&pDBProp->vValue) == DBPROPVAL_NOOBJ) ) )
  683. {
  684. hr = S_FALSE;
  685. }
  686. break;
  687. }
  688. }
  689. }
  690. return hr;
  691. }
  692. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  693. HRESULT CUtilProp::CheckPropertyIDSets( BOOL & fIsNotSpecialGUID, BOOL & fIsSpecialGUID,
  694. ULONG cPropIDSets, const DBPROPIDSET rgPropIDSets[] ) //IN Array of property sets
  695. {
  696. HRESULT hr = S_OK;
  697. fIsNotSpecialGUID = FALSE;
  698. fIsSpecialGUID = FALSE;
  699. for(ULONG ul=0; ul<cPropIDSets; ul++){
  700. if( rgPropIDSets[ul].cPropertyIDs && !(rgPropIDSets[ul].rgPropertyIDs) ){
  701. hr = E_INVALIDARG ;
  702. break;
  703. }
  704. if (DBPROPSET_ROWSETALL == rgPropIDSets[ul].guidPropertySet ||
  705. DBPROPSET_DATASOURCEALL == rgPropIDSets[ul].guidPropertySet ||
  706. DBPROPSET_DATASOURCEINFOALL == rgPropIDSets[ul].guidPropertySet ||
  707. DBPROPSET_SESSIONALL == rgPropIDSets[ul].guidPropertySet ||
  708. DBPROPSET_COLUMNALL == rgPropIDSets[ul].guidPropertySet ||
  709. DBPROPSET_DBINITALL == rgPropIDSets[ul].guidPropertySet ||
  710. DBPROPSET_CONSTRAINTALL == rgPropIDSets[ul].guidPropertySet ||
  711. DBPROPSET_INDEXALL == rgPropIDSets[ul].guidPropertySet ||
  712. DBPROPSET_SESSIONALL == rgPropIDSets[ul].guidPropertySet ||
  713. DBPROPSET_VIEWALL == rgPropIDSets[ul].guidPropertySet ||
  714. DBPROPSET_TABLEALL == rgPropIDSets[ul].guidPropertySet ||
  715. DBPROPSET_TRUSTEEALL == rgPropIDSets[ul].guidPropertySet )
  716. {
  717. fIsSpecialGUID = TRUE;
  718. }
  719. else{
  720. fIsNotSpecialGUID = TRUE;
  721. }
  722. if(fIsSpecialGUID && fIsNotSpecialGUID){
  723. hr = E_INVALIDARG ;
  724. break;
  725. }
  726. }
  727. if(fIsSpecialGUID && fIsNotSpecialGUID)
  728. hr = E_INVALIDARG ;
  729. return hr;
  730. }
  731. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  732. //
  733. // Returns information about rowset and data source properties supported by the provider
  734. //
  735. // HRESULT
  736. // S_OK The method succeeded
  737. // E_INVALIDARG pcPropertyIDSets or prgPropertyInfo was NULL
  738. // E_OUTOFMEMORY Out of memory
  739. //
  740. // NTRaid : 142133 - Testing this , found that getting data source property from ADO was resulting in a crash
  741. // 07/12/00
  742. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  743. STDMETHODIMP CUtilProp::GetPropertyInfo( BOOL fDSOInitialized, //IN if Initialized
  744. ULONG cPropIDSets, //IN # properties
  745. const DBPROPIDSET rgPropIDSets[], //IN Array of property sets
  746. ULONG* pcPropInfoSets, //OUT # DBPROPSET structures
  747. DBPROPINFOSET** prgPropInfoSets,//OUT DBPROPSET structures property information returned
  748. WCHAR** ppDescBuffer //OUT Property descriptions
  749. )
  750. {
  751. BOOL fRet= TRUE;
  752. BOOL fPropsinError, fPropsSucceed, fIsSpecialGUID, fIsNotSpecialGUID;
  753. ULONG cProps = 0;
  754. ULONG cCount = 0;
  755. ULONG ulPropSets = 0;
  756. ULONG cTotalPropSets = 0;
  757. ULONG ulPropSetIndex = 0;
  758. ULONG cPropSetsInSpecialGUID = 0;
  759. WCHAR* pDescBuffer = NULL;
  760. WCHAR* pDescBufferTemp = NULL;
  761. DBPROPINFO* pPropInfo;
  762. DBPROPINFOSET* pPropInfoSet;
  763. HRESULT hr = S_OK;
  764. ULONG ulPropertyInfoCount = 0;
  765. //=======================================================================
  766. // init out params and local stuff
  767. //=======================================================================
  768. if (pcPropInfoSets)
  769. *pcPropInfoSets = 0;
  770. if (prgPropInfoSets)
  771. *prgPropInfoSets = NULL;
  772. if (ppDescBuffer)
  773. *ppDescBuffer = NULL;
  774. fPropsinError = fPropsSucceed = fIsSpecialGUID = fIsNotSpecialGUID = FALSE;
  775. cProps = cCount = ulPropSets = ulPropSetIndex = cTotalPropSets = cPropSetsInSpecialGUID = 0;
  776. //=======================================================================
  777. // Check Arguments, on failure post HRESULT to error queue
  778. //=======================================================================
  779. if( ((cPropIDSets > 0) && !rgPropIDSets) || !pcPropInfoSets || !prgPropInfoSets ){
  780. return E_INVALIDARG ;
  781. }
  782. //=======================================================================
  783. // If the consumer does not restrict the property sets by specify an
  784. // array of property sets and a cPropertySets greater than 0, then we
  785. // need to make sure we have some to return
  786. //=======================================================================
  787. if ( (cPropIDSets == 0) ){
  788. if( fDSOInitialized )
  789. cProps = NUMBER_OF_SUPPORTED_PROPERTY_SETS;
  790. else
  791. cProps = 2;
  792. cTotalPropSets = cProps;
  793. }
  794. else
  795. {
  796. //=======================================================================
  797. // New argument check for > 1 cPropIDs and NULL pointer for
  798. // array of property ids.
  799. //=======================================================================
  800. if( S_OK != ( hr = CheckPropertyIDSets(fIsNotSpecialGUID,fIsSpecialGUID,cPropIDSets,rgPropIDSets)) ){
  801. return hr;
  802. }
  803. if( fIsSpecialGUID == TRUE)
  804. {
  805. cTotalPropSets = GetNumberOfPropertySets(fDSOInitialized,rgPropIDSets,cPropIDSets);
  806. // NTRaid : 142133
  807. // 07/12/00
  808. cProps = cPropIDSets;
  809. }
  810. else
  811. //=======================================================================
  812. // save the count of PropertyIDSets
  813. //=======================================================================
  814. cTotalPropSets = cProps = cPropIDSets;
  815. }
  816. // con.properties
  817. // 07/06/00
  818. if(cTotalPropSets)
  819. {
  820. //=======================================================================
  821. // use task memory allocater to alloc a DBPROPINFOSET struct
  822. //=======================================================================
  823. if( S_OK != (hr = m_PropMemMgr.AllocDBPROPINFOSET(pPropInfoSet,cTotalPropSets))){
  824. return hr;
  825. }
  826. memset(pPropInfoSet,0,cTotalPropSets * sizeof(DBPROPINFOSET));
  827. // Fill the property sets info to be fetched and get the number of properties that will be returned
  828. if(fIsSpecialGUID == TRUE || cPropIDSets == 0)
  829. {
  830. FillPropertySets(fDSOInitialized,rgPropIDSets,cPropIDSets ,pPropInfoSet,ulPropertyInfoCount);
  831. }
  832. else
  833. {
  834. ulPropertyInfoCount = GetNumberofPropInfoToBeReturned(fDSOInitialized,cPropIDSets,rgPropIDSets);
  835. }
  836. //=======================================================================
  837. // Alloc memory for ppDescBuffer
  838. //=======================================================================
  839. if( S_OK != (hr = m_PropMemMgr.AllocDESCRIPTBuffer(pDescBuffer, ppDescBuffer,ulPropertyInfoCount))){
  840. m_PropMemMgr.FreeDBPROPINFOSET(pPropInfoSet,cTotalPropSets);
  841. return hr;
  842. }
  843. pDescBufferTemp = pDescBuffer;
  844. //=======================================================================
  845. // For each supported Property Set
  846. //=======================================================================
  847. for (ulPropSets=0,ulPropSetIndex = 0; ulPropSets < cTotalPropSets; ulPropSets++ )
  848. {
  849. BOOL fGetAllProps = FALSE;
  850. // if the propinfo is not filled manually then get it from the input parameters
  851. if(fIsSpecialGUID == FALSE && cPropIDSets != 0)
  852. {
  853. pPropInfoSet[ulPropSetIndex].guidPropertySet = rgPropIDSets[ulPropSets].guidPropertySet;
  854. pPropInfoSet[ulPropSetIndex].cPropertyInfos = rgPropIDSets[ulPropSets].cPropertyIDs;
  855. }
  856. if (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_DBINIT &&
  857. pPropInfoSet[ulPropSetIndex].cPropertyInfos == 0 )
  858. {
  859. fGetAllProps = TRUE;
  860. pPropInfoSet[ulPropSetIndex].cPropertyInfos = NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES;
  861. }
  862. else
  863. if (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_WMIOLEDB_DBINIT &&
  864. pPropInfoSet[ulPropSetIndex].cPropertyInfos == 0 )
  865. {
  866. fGetAllProps = TRUE;
  867. pPropInfoSet[ulPropSetIndex].cPropertyInfos = NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  868. }
  869. else
  870. if( fDSOInitialized )
  871. {
  872. if (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_DATASOURCEINFO &&
  873. pPropInfoSet[ulPropSetIndex].cPropertyInfos == 0 )
  874. {
  875. fGetAllProps = TRUE;
  876. pPropInfoSet[ulPropSetIndex].cPropertyInfos = NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES;
  877. }
  878. else
  879. if (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_ROWSET &&
  880. pPropInfoSet[ulPropSetIndex].cPropertyInfos == 0 )
  881. {
  882. fGetAllProps = TRUE;
  883. pPropInfoSet[ulPropSetIndex].cPropertyInfos = NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  884. }
  885. else
  886. if (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_WMIOLEDB_ROWSET &&
  887. pPropInfoSet[ulPropSetIndex].cPropertyInfos == 0 )
  888. {
  889. fGetAllProps = TRUE;
  890. pPropInfoSet[ulPropSetIndex].cPropertyInfos = NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  891. }
  892. else
  893. if (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_COLUMN &&
  894. pPropInfoSet[ulPropSetIndex].cPropertyInfos == 0 )
  895. {
  896. fGetAllProps = TRUE;
  897. pPropInfoSet[ulPropSetIndex].cPropertyInfos = NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES;
  898. }
  899. else
  900. if (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_WMIOLEDB_COLUMN &&
  901. pPropInfoSet[ulPropSetIndex].cPropertyInfos == 0 )
  902. {
  903. fGetAllProps = TRUE;
  904. pPropInfoSet[ulPropSetIndex].cPropertyInfos = NUMBER_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  905. }
  906. /* if (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_WMIOLEDB_COMMAND &&
  907. pPropInfoSet[ulPropSetIndex].cPropertyInfos == 0 )
  908. {
  909. fGetAllProps = TRUE;
  910. pPropInfoSet[ulPropSetIndex].cPropertyInfos = NUMBER_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  911. }
  912. */
  913. // else if (rgPropIDSets[ulPropSets].cPropertyIDs == 0)
  914. else if (pPropInfoSet[ulPropSetIndex].cPropertyInfos == 0)
  915. fPropsinError = TRUE;
  916. }
  917. // else if (rgPropIDSets[ulPropSets].cPropertyIDs == 0)
  918. else if (pPropInfoSet[ulPropSetIndex].cPropertyInfos == 0)
  919. {
  920. //===============================================================
  921. // Since we do not support it should return a error with 0 & NULL
  922. //===============================================================
  923. fPropsinError = TRUE;
  924. }
  925. if (pPropInfoSet[ulPropSetIndex].cPropertyInfos){
  926. //===============================================================
  927. // use task memory allocater to alloc array of DBPROPINFO structs
  928. //===============================================================
  929. hr = m_PropMemMgr.AllocDBPROPINFO(pPropInfo,pPropInfoSet,ulPropSetIndex);
  930. if (!pPropInfo) {
  931. m_PropMemMgr.FreeDBPROPINFOSET(pPropInfoSet,cTotalPropSets);
  932. pDescBuffer = pDescBufferTemp;
  933. m_PropMemMgr.FreeDESCRIPTBuffer(pDescBuffer,ppDescBuffer);
  934. return E_OUTOFMEMORY ;
  935. }
  936. pPropInfoSet[ulPropSetIndex].rgPropertyInfos = &pPropInfo[0];
  937. memset( pPropInfo, 0,
  938. (pPropInfoSet[ulPropSetIndex].cPropertyInfos * sizeof( DBPROPINFO )));
  939. }
  940. if(!IsPropertySetSupported(pPropInfoSet[ulPropSetIndex].guidPropertySet))
  941. {
  942. for (cCount=0; cCount < pPropInfoSet[ulPropSetIndex].cPropertyInfos; cCount++)
  943. {
  944. pPropInfo[cCount].dwPropertyID = rgPropIDSets[ulPropSets].rgPropertyIDs[cCount];
  945. pPropInfo[cCount].dwFlags = DBPROPFLAGS_NOTSUPPORTED;
  946. fPropsinError = TRUE;
  947. pPropInfo[cCount].pwszDescription = NULL;
  948. }
  949. }
  950. else
  951. {
  952. //===============================================================
  953. // for each prop in our table..
  954. //===============================================================
  955. for (cCount=0; cCount < pPropInfoSet[ulPropSetIndex].cPropertyInfos; cCount++){
  956. //===========================================================
  957. // init the Variant right up front that way we can
  958. // VariantClear with no worried (if we need to)
  959. //===========================================================
  960. VariantInit( &pPropInfo[cCount].vValues );
  961. //===========================================================
  962. // set the description pointer
  963. //===========================================================
  964. pPropInfo[cCount].pwszDescription = pDescBuffer;
  965. //===========================================================
  966. // Check supported property sets
  967. //===========================================================
  968. if ( (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_DBINIT) && (fGetAllProps) ){
  969. //=======================================================
  970. // load up their DBPROPINFO from our table
  971. //=======================================================
  972. fPropsSucceed = TRUE;
  973. fRet = LoadDBPROPINFO( &s_rgprop[START_OF_SUPPORTED_DBINIT_PROPERTIES + cCount], &pPropInfo[cCount] );
  974. }
  975. else
  976. if ( (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_WMIOLEDB_DBINIT) && (fGetAllProps) ){
  977. //=======================================================
  978. // load up their DBPROPINFO from our table
  979. //=======================================================
  980. fPropsSucceed = TRUE;
  981. fRet = LoadDBPROPINFO( &s_rgprop[START_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES + cCount], &pPropInfo[cCount] );
  982. }
  983. else if ( (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_DATASOURCEINFO) && fGetAllProps && fDSOInitialized){
  984. //=======================================================
  985. // load up their DBPROPINFO from our table
  986. //=======================================================
  987. fPropsSucceed = TRUE;
  988. fRet = LoadDBPROPINFO( &s_rgprop[START_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES + cCount], &pPropInfo[cCount] );
  989. }
  990. else if ( (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_ROWSET) && fGetAllProps && fDSOInitialized){
  991. //=======================================================
  992. // load up their DBPROPINFO from our table
  993. //=======================================================
  994. fPropsSucceed = TRUE;
  995. fRet = LoadDBPROPINFO( &s_rgprop[START_OF_SUPPORTED_ROWSET_PROPERTIES + cCount],&pPropInfo[cCount] );
  996. }
  997. else if ( (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_WMIOLEDB_ROWSET) && fGetAllProps && fDSOInitialized){
  998. //=======================================================
  999. // load up their DBPROPINFO from our table
  1000. //=======================================================
  1001. fPropsSucceed = TRUE;
  1002. fRet = LoadDBPROPINFO( &s_rgprop[START_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES + cCount],&pPropInfo[cCount] );
  1003. }
  1004. else if ( (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_COLUMN) && fGetAllProps && fDSOInitialized){
  1005. //=======================================================
  1006. // load up their DBPROPINFO from our table
  1007. //=======================================================
  1008. fPropsSucceed = TRUE;
  1009. fRet = LoadDBPROPINFO( &s_rgprop[START_OF_SUPPORTED_COLUMN_PROPERTIES + cCount],&pPropInfo[cCount] );
  1010. }
  1011. else if ( (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_WMIOLEDB_COLUMN) && fGetAllProps && fDSOInitialized){
  1012. //=======================================================
  1013. // load up their DBPROPINFO from our table
  1014. //=======================================================
  1015. fPropsSucceed = TRUE;
  1016. fRet = LoadDBPROPINFO( &s_rgprop[START_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES + cCount],&pPropInfo[cCount] );
  1017. }
  1018. /* else if ( (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_WMIOLEDB_COMMAND) && fGetAllProps && fDSOInitialized){
  1019. //=======================================================
  1020. // load up their DBPROPINFO from our table
  1021. //=======================================================
  1022. fPropsSucceed = TRUE;
  1023. fRet = LoadDBPROPINFO( &s_rgprop[START_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES + cCount],&pPropInfo[cCount] );
  1024. }
  1025. */ else{
  1026. ULONG ulIndex;
  1027. pPropInfo[cCount].dwPropertyID = rgPropIDSets[ulPropSets].rgPropertyIDs[cCount];
  1028. pPropInfo[cCount].dwFlags = DBPROPFLAGS_NOTSUPPORTED;
  1029. if ( (GetPropIndexFromAllSupportedProps(rgPropIDSets[ulPropSets].rgPropertyIDs[cCount], &ulIndex)) &&
  1030. (fDSOInitialized || (pPropInfoSet[ulPropSetIndex].guidPropertySet == DBPROPSET_DBINIT)) ){
  1031. fPropsSucceed = TRUE;
  1032. fRet = LoadDBPROPINFO( &s_rgprop[ulIndex], &pPropInfo[cCount] );
  1033. }
  1034. else{
  1035. fPropsinError = TRUE;
  1036. pPropInfo[cCount].pwszDescription = NULL;
  1037. }
  1038. }
  1039. if (!fRet){
  1040. m_PropMemMgr.FreeDBPROPINFOSET(pPropInfoSet,cTotalPropSets);
  1041. if ( ppDescBuffer ){
  1042. *ppDescBuffer = NULL;
  1043. }
  1044. g_pIMalloc->Free( pDescBufferTemp );
  1045. return E_FAIL ;
  1046. }
  1047. //===========================================================
  1048. // move the description pointer to the next
  1049. //===========================================================
  1050. if ( pPropInfo[cCount].pwszDescription ){
  1051. pDescBuffer += (wcslen(pPropInfo[cCount].pwszDescription) + sizeof(CHAR));
  1052. }
  1053. }
  1054. }
  1055. //===============================================================
  1056. // Set local back to FALSE
  1057. //===============================================================
  1058. fGetAllProps = FALSE;
  1059. // cPropSetsInSpecialGUID--;
  1060. ulPropSetIndex++;
  1061. }
  1062. }
  1063. else
  1064. if(fIsSpecialGUID && ulPropSetIndex == 0)
  1065. {
  1066. hr = S_OK;
  1067. }
  1068. else
  1069. {
  1070. hr = DB_E_ERRORSOCCURRED;
  1071. }
  1072. if(ulPropSetIndex)
  1073. {
  1074. //===================================================================
  1075. // set count of properties and property information
  1076. //===================================================================
  1077. *pcPropInfoSets = ulPropSetIndex;
  1078. *prgPropInfoSets = pPropInfoSet;
  1079. }
  1080. if(SUCCEEDED(hr))
  1081. {
  1082. if ( !fPropsSucceed && fPropsinError ){
  1083. if ( ppDescBuffer ){
  1084. *ppDescBuffer = NULL;
  1085. }
  1086. g_pIMalloc->Free( pDescBufferTemp );
  1087. hr = DB_E_ERRORSOCCURRED ;
  1088. }
  1089. else if ( fPropsSucceed && fPropsinError )
  1090. hr = DB_S_ERRORSOCCURRED ;
  1091. else
  1092. hr = S_OK ;
  1093. }
  1094. return hr;
  1095. }
  1096. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  1097. //
  1098. // Returns current settings of all properties supported by the DSO/rowset
  1099. //
  1100. // HRESULT
  1101. // S_OK The method succeeded
  1102. // E_INVALIDARG pcProperties or prgPropertyInfo was NULL
  1103. // E_OUTOFMEMORY Out of memory
  1104. //
  1105. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  1106. STDMETHODIMP CUtilProp::GetProperties( DWORD dwBitMask, //IN Mask if Initialized
  1107. ULONG cPropertyIDSets, //IN # of restiction property IDs
  1108. const DBPROPIDSET rgPropertyIDSets[], //IN restriction guids
  1109. ULONG* pcPropertySets, //OUT count of properties returned
  1110. DBPROPSET** prgPropertySets //OUT property information returned
  1111. )
  1112. {
  1113. BOOL fRet = TRUE;
  1114. BOOL fPropsinError = FALSE;
  1115. BOOL fPropsSucceed = FALSE;
  1116. ULONG cProps = 0;
  1117. ULONG cCount = 0;
  1118. ULONG ulPropertySets= 0;
  1119. DBPROP* pProp;
  1120. DBPROPSET* pPropSet;
  1121. BOOL bDSOInitialized = FALSE;
  1122. ULONG ulIndex = 0;
  1123. HRESULT hr = S_OK;
  1124. //======================================================================
  1125. // save the count of PropertyIDSets
  1126. //======================================================================
  1127. cProps = cPropertyIDSets;
  1128. //======================================================================
  1129. // If the consumer does not restrict the property sets by specify an
  1130. // array of property sets and a cPropertySets greater than 0, then we
  1131. // need to make sure we have some to return
  1132. //======================================================================
  1133. if ( (dwBitMask & PROPSET_DSOINIT) == PROPSET_DSOINIT )
  1134. bDSOInitialized = TRUE;
  1135. if( cPropertyIDSets == 0 ){
  1136. //=================================================================
  1137. // only allow the DBINIT and DATASOURCE if Initialized
  1138. //=================================================================
  1139. cProps = GetNumberOfPropertySets(bDSOInitialized,dwBitMask);
  1140. }
  1141. //=====================================================================
  1142. // use task memory allocater to alloc a DBPROPSET struct
  1143. //=====================================================================
  1144. pPropSet = (DBPROPSET*) g_pIMalloc->Alloc(cProps * sizeof( DBPROPSET ));
  1145. if ( !pPropSet )
  1146. return E_OUTOFMEMORY ;
  1147. memset( pPropSet, 0, (cProps * sizeof( DBPROPSET )));
  1148. if(cPropertyIDSets == 0)
  1149. {
  1150. FillPropStruct(bDSOInitialized,dwBitMask,pPropSet);
  1151. }
  1152. if(pcPropertySets)
  1153. {
  1154. *pcPropertySets = 0;
  1155. }
  1156. if(prgPropertySets)
  1157. {
  1158. *prgPropertySets = NULL;
  1159. }
  1160. //=====================================================================
  1161. // For each supported Property Set
  1162. //=====================================================================
  1163. for (ulPropertySets=0; ulPropertySets < cProps; ulPropertySets++){
  1164. BOOL fGetAllProps = FALSE;
  1165. //=====================================================================
  1166. // If no restrictions return all properties from the three supported
  1167. // property sets
  1168. //=====================================================================
  1169. if ( cPropertyIDSets == 0 ){
  1170. fGetAllProps = TRUE;
  1171. /* //=============================================================
  1172. // only do this once
  1173. //=============================================================
  1174. if ( ulPropertySets == 0 ){
  1175. if( !(dwBitMask & PROPSET_SESSION) ){
  1176. if ( !(dwBitMask & PROPSET_ROWSET) ){
  1177. pPropSet[0].guidPropertySet = DBPROPSET_DBINIT;
  1178. pPropSet[0].cProperties = NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES;
  1179. if( dwBitMask & PROPSET_INIT ){
  1180. pPropSet[1].guidPropertySet = DBPROPSET_DATASOURCEINFO;
  1181. pPropSet[1].cProperties = NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES;
  1182. }
  1183. }
  1184. else{
  1185. pPropSet[0].guidPropertySet = DBPROPSET_ROWSET;
  1186. pPropSet[0].cProperties = NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  1187. }
  1188. }
  1189. }
  1190. */ }
  1191. else
  1192. {
  1193. pPropSet[ulPropertySets].guidPropertySet = rgPropertyIDSets[ulPropertySets].guidPropertySet;
  1194. // if propertyset is supported by provider , but not available for the current OLEDB object ,
  1195. // then throw error
  1196. // if the requested number of propertysets is more than one then , the other properties should be
  1197. // fetched and DB_S_ERRORSOCCURRED should be thrown
  1198. if((S_OK != (hr = IsValidPropertySet(bDSOInitialized,pPropSet[ulPropertySets].guidPropertySet))) &&
  1199. IsPropertySetSupported(pPropSet[ulPropertySets].guidPropertySet) &&
  1200. rgPropertyIDSets[ulPropertySets].cPropertyIDs == 0)
  1201. {
  1202. if(cProps > 1)
  1203. {
  1204. fPropsinError = TRUE;
  1205. continue;
  1206. }
  1207. else
  1208. {
  1209. *pcPropertySets = 1;
  1210. *prgPropertySets = pPropSet;
  1211. return DB_E_ERRORSOCCURRED;
  1212. }
  1213. }
  1214. pPropSet[ulPropertySets].cProperties = rgPropertyIDSets[ulPropertySets].cPropertyIDs;
  1215. if( rgPropertyIDSets[ulPropertySets].cPropertyIDs == 0 &&
  1216. rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_PROPERTIESINERROR )
  1217. {
  1218. fPropsSucceed = TRUE;
  1219. continue;
  1220. }
  1221. if( rgPropertyIDSets[ulPropertySets].cPropertyIDs == 0 ){
  1222. fGetAllProps = TRUE;
  1223. if( rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_DBINIT ){
  1224. pPropSet[ulPropertySets].cProperties = NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES;
  1225. }
  1226. else
  1227. if( rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_DBINIT ){
  1228. pPropSet[ulPropertySets].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  1229. }
  1230. else if( (rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_DATASOURCEINFO) &&
  1231. ((dwBitMask & PROPSET_DSOINIT) == PROPSET_DSOINIT) ){
  1232. pPropSet[ulPropertySets].cProperties = NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES;
  1233. }
  1234. else if( (rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_ROWSET) &&
  1235. (dwBitMask & PROPSET_ROWSET)){
  1236. pPropSet[ulPropertySets].cProperties = NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  1237. }
  1238. else if( (rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_ROWSET) &&
  1239. (dwBitMask & PROPSET_ROWSET)){
  1240. pPropSet[ulPropertySets].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  1241. }
  1242. else if( (rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_COLUMN) &&
  1243. (dwBitMask & PROPSET_COLUMN)){
  1244. pPropSet[ulPropertySets].cProperties = NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES;
  1245. }
  1246. else if( (rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_COLUMN) &&
  1247. (dwBitMask & PROPSET_COLUMN)){
  1248. pPropSet[ulPropertySets].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  1249. }
  1250. /* else if( (rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_COMMAND) &&
  1251. (dwBitMask & PROPSET_COMMAND)){
  1252. pPropSet[ulPropertySets].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  1253. }
  1254. */ else{
  1255. fGetAllProps = FALSE;
  1256. fPropsinError = TRUE;
  1257. }
  1258. }
  1259. }
  1260. if( pPropSet[ulPropertySets].cProperties ){
  1261. //=============================================================
  1262. // use task memory allocater to alloc array of DBPROP structs
  1263. //=============================================================
  1264. pProp = (DBPROP*) g_pIMalloc->Alloc(sizeof( DBPROP ) * pPropSet[ulPropertySets].cProperties);
  1265. if (!pProp){
  1266. for(ULONG ul=0; ul<ulPropertySets; ul++){
  1267. for(ULONG ul2=0; ul2<pPropSet[ul].cProperties; ul2++)
  1268. VariantClear( &pPropSet[ul].rgProperties[ul2].vValue );
  1269. g_pIMalloc->Free( pPropSet[ul].rgProperties );
  1270. }
  1271. g_pIMalloc->Free( pPropSet );
  1272. return E_OUTOFMEMORY ;
  1273. }
  1274. pPropSet[ulPropertySets].rgProperties = &pProp[0];
  1275. memset( pProp, 0, (pPropSet[ulPropertySets].cProperties * sizeof( DBPROP )));
  1276. }
  1277. //=================================================================
  1278. // for each prop in our table..
  1279. //=================================================================
  1280. for (cCount=0; cCount < pPropSet[ulPropertySets].cProperties; cCount++){
  1281. //=============================================================
  1282. // init the Variant right up front
  1283. // that way we can VariantClear with no worried (if we need to)
  1284. //=============================================================
  1285. VariantInit( &pProp[cCount].vValue );
  1286. //=============================================================
  1287. // Check supported property sets
  1288. //=============================================================
  1289. if ( pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_DBINIT && fGetAllProps ) {
  1290. fPropsSucceed = TRUE;
  1291. //=========================================================
  1292. // load up their DBPROP from our table
  1293. //=========================================================
  1294. pProp[cCount].dwPropertyID = s_rgprop[START_OF_SUPPORTED_DBINIT_PROPERTIES + cCount].dwPropertyID;
  1295. // fRet = LoadDBPROP( &s_rgprop[START_OF_SUPPORTED_DBINIT_PROPERTIES + cCount],&pProp[cCount] );
  1296. }
  1297. else
  1298. if ( pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_DBINIT && fGetAllProps ) {
  1299. fPropsSucceed = TRUE;
  1300. //=========================================================
  1301. // load up their DBPROP from our table
  1302. //=========================================================
  1303. pProp[cCount].dwPropertyID = s_rgprop[START_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES + cCount].dwPropertyID;
  1304. // fRet = LoadDBPROP( &s_rgprop[START_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES + cCount],&pProp[cCount] );
  1305. }
  1306. else if ( pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_DATASOURCEINFO && fGetAllProps ){
  1307. fPropsSucceed = TRUE;
  1308. //=========================================================
  1309. // load up their DBPROPINFO from our table
  1310. //=========================================================
  1311. pProp[cCount].dwPropertyID = s_rgprop[START_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES + cCount].dwPropertyID;
  1312. // fRet = LoadDBPROP( &s_rgprop[START_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES + cCount],&pProp[cCount] );
  1313. }
  1314. else if ( pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_ROWSET && fGetAllProps ){
  1315. fPropsSucceed = TRUE;
  1316. //=========================================================
  1317. // load up their DBPROPINFO from our table
  1318. //=========================================================
  1319. pProp[cCount].dwPropertyID = s_rgprop[START_OF_SUPPORTED_ROWSET_PROPERTIES + cCount].dwPropertyID;
  1320. // fRet = LoadDBPROP( &s_rgprop[START_OF_SUPPORTED_ROWSET_PROPERTIES + cCount], &pProp[cCount] );
  1321. }
  1322. else if ( pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_ROWSET && fGetAllProps ){
  1323. fPropsSucceed = TRUE;
  1324. //=========================================================
  1325. // load up their DBPROPINFO from our table
  1326. //=========================================================
  1327. pProp[cCount].dwPropertyID = s_rgprop[START_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES + cCount].dwPropertyID;
  1328. // fRet = LoadDBPROP( &s_rgprop[START_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES + cCount], &pProp[cCount] );
  1329. }
  1330. else if ( pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_COLUMN && fGetAllProps ){
  1331. fPropsSucceed = TRUE;
  1332. //=========================================================
  1333. // load up their DBPROPINFO from our table
  1334. //=========================================================
  1335. pProp[cCount].dwPropertyID = s_rgprop[START_OF_SUPPORTED_COLUMN_PROPERTIES + cCount].dwPropertyID;
  1336. // fRet = LoadDBPROP( &s_rgprop[START_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES + cCount], &pProp[cCount] );
  1337. }
  1338. else if ( pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_COLUMN && fGetAllProps ){
  1339. fPropsSucceed = TRUE;
  1340. //=========================================================
  1341. // load up their DBPROPINFO from our table
  1342. //=========================================================
  1343. pProp[cCount].dwPropertyID = s_rgprop[START_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES + cCount].dwPropertyID;
  1344. // fRet = LoadDBPROP( &s_rgprop[START_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES + cCount], &pProp[cCount] );
  1345. }
  1346. /* else if ( pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_COMMAND && fGetAllProps ){
  1347. fPropsSucceed = TRUE;
  1348. //=========================================================
  1349. // load up their DBPROPINFO from our table
  1350. //=========================================================
  1351. pProp[cCount].dwPropertyID = s_rgprop[START_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES + cCount].dwPropertyID;
  1352. // fRet = LoadDBPROP( &s_rgprop[START_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES + cCount], &pProp[cCount] );
  1353. }
  1354. */ else
  1355. {
  1356. pProp[cCount].dwPropertyID = rgPropertyIDSets[ulPropertySets].rgPropertyIDs[cCount];
  1357. pProp[cCount].dwStatus = DBPROPSTATUS_NOTSUPPORTED;
  1358. }
  1359. if(GetPropIndex(pProp[cCount].dwPropertyID, &ulIndex))
  1360. {
  1361. fPropsSucceed = FALSE;
  1362. switch(dwBitMask)
  1363. {
  1364. case PROPSET_DSO:
  1365. case PROPSET_DSOINIT:
  1366. if(pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_DBINIT ||
  1367. pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_DBINIT ||
  1368. ((pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_DATASOURCE ||
  1369. pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_DATASOURCEINFO) &&
  1370. bDSOInitialized == TRUE)){
  1371. fPropsSucceed = TRUE;
  1372. }
  1373. break;
  1374. case PROPSET_INIT:
  1375. if(pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_DBINIT ||
  1376. pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_DBINIT) {
  1377. fPropsSucceed = TRUE;
  1378. }
  1379. break;
  1380. case PROPSET_SESSION:
  1381. if(pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_SESSION){
  1382. fPropsSucceed = TRUE;
  1383. }
  1384. break;
  1385. case PROPSET_COMMAND:
  1386. if(pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_ROWSET ||
  1387. pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_ROWSET) {
  1388. // || pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_COMMAND){
  1389. fPropsSucceed = TRUE;
  1390. }
  1391. break;
  1392. case PROPSET_ROWSET:
  1393. if(pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_ROWSET ||
  1394. pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_ROWSET){
  1395. fPropsSucceed = TRUE;
  1396. }
  1397. break;
  1398. case PROPSET_COLUMN:
  1399. if(pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_COLUMN ||
  1400. pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_COLUMN){
  1401. fPropsSucceed = TRUE;
  1402. }
  1403. break;
  1404. default:
  1405. fPropsSucceed = FALSE;
  1406. };
  1407. if(fPropsSucceed == TRUE)
  1408. {
  1409. fRet = LoadDBPROP( &m_prgproperties[ulIndex], &pProp[cCount] );
  1410. }
  1411. else
  1412. fPropsinError = TRUE;
  1413. }
  1414. else
  1415. {
  1416. pProp[cCount].dwPropertyID = rgPropertyIDSets[ulPropertySets].rgPropertyIDs[cCount];
  1417. pProp[cCount].dwStatus = DBPROPSTATUS_NOTSUPPORTED;
  1418. fPropsinError = TRUE;
  1419. }
  1420. /* if( (GetPropIndex(pProp[cCount].dwPropertyID, &ulIndex)) &&
  1421. ((((dwBitMask & PROPSET_DSO) || (dwBitMask & PROPSET_INIT)) &&
  1422. (pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_DBINIT)) ||
  1423. (((dwBitMask & PROPSET_DSO) || (dwBitMask & PROPSET_INIT))&&
  1424. (pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_DBINIT)) ||
  1425. (((dwBitMask & PROPSET_DSOINIT) == PROPSET_DSOINIT) &&
  1426. ((pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_DATASOURCE) ||
  1427. (pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_DATASOURCEINFO))) ||
  1428. ((dwBitMask & PROPSET_SESSION) &&
  1429. (pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_SESSION)) ||
  1430. ((dwBitMask & PROPSET_ROWSET) &&
  1431. ((pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_ROWSET) ||
  1432. (pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_ROWSET))) ||
  1433. ((dwBitMask & PROPSET_COLUMN) &&
  1434. ((pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_COLUMN) ||
  1435. (pPropSet[ulPropertySets].guidPropertySet == DBPROPSET_WMIOLEDB_COLUMN))) ) ){
  1436. fPropsSucceed = TRUE;
  1437. fRet = LoadDBPROP( &m_prgproperties[ulIndex], &pProp[cCount] );
  1438. }
  1439. else
  1440. fPropsinError = TRUE;
  1441. */
  1442. if (!fRet){
  1443. ULONG ulFor;
  1444. //=========================================================
  1445. // something went wrong
  1446. // clear all variants used so far..
  1447. //=========================================================
  1448. for (ulFor = 0; ulFor < cCount; ulFor++){
  1449. VariantClear( &pProp[ulFor].vValue );
  1450. }
  1451. //=========================================================
  1452. // .. delete the pPropInfo array, return failure
  1453. //=========================================================
  1454. g_pIMalloc->Free( pProp );
  1455. g_pIMalloc->Free( pPropSet );
  1456. return E_FAIL ;
  1457. }
  1458. }
  1459. //=================================================================
  1460. // Set local back to FALSE
  1461. //=================================================================
  1462. fGetAllProps = FALSE;
  1463. }
  1464. //=====================================================================
  1465. // set count of properties and property information
  1466. //=====================================================================
  1467. if(cProps > 0)
  1468. {
  1469. *pcPropertySets = cProps;
  1470. *prgPropertySets = pPropSet;
  1471. }
  1472. if ( (!fPropsSucceed && cPropertyIDSets) || (!fPropsSucceed && fPropsinError) )
  1473. {
  1474. /* g_pIMalloc->Free( pProp );
  1475. g_pIMalloc->Free( pPropSet );
  1476. *pcPropertySets = 0;
  1477. *prgPropertySets = NULL;
  1478. */ return DB_E_ERRORSOCCURRED ;
  1479. }
  1480. else if ( fPropsSucceed && fPropsinError )
  1481. return DB_S_ERRORSOCCURRED ;
  1482. else
  1483. return S_OK ;
  1484. }
  1485. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1486. //
  1487. // Initialize the buffers and check for E_INVALIDARG cases
  1488. //
  1489. // HRESULT indicating the status of the method
  1490. // S_OK Properties gathered
  1491. // E_INVALIDARG Invalid parameter values
  1492. //
  1493. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1494. HRESULT CUtilProp::SetPropertiesArgChk( const ULONG cPropertySets, //IN Count of structs returned
  1495. const DBPROPSET rgPropertySets[],//IN Array of Properties Sets
  1496. BOOL bDSOInitialized)
  1497. {
  1498. HRESULT hr = S_OK;
  1499. //================================================================
  1500. // Argument Checking
  1501. //================================================================
  1502. if ((cPropertySets > 0) && !rgPropertySets)
  1503. return E_INVALIDARG ;
  1504. //================================================================
  1505. // New argument check for > 1 cPropertyIDs and NULL pointer for
  1506. // array of property ids.
  1507. //================================================================
  1508. for(ULONG ul=0; ul<cPropertySets && hr == S_OK; ul++){
  1509. // Setting a error property set is not allowed
  1510. if(rgPropertySets[ul].guidPropertySet == DBPROPSET_PROPERTIESINERROR )
  1511. {
  1512. hr = E_INVALIDARG;
  1513. }
  1514. else
  1515. if( rgPropertySets[ul].cProperties && !(rgPropertySets[ul].rgProperties) )
  1516. {
  1517. hr = E_INVALIDARG ;
  1518. break;
  1519. }
  1520. else
  1521. {
  1522. // Check if all the propertysetID is correct for this object
  1523. hr = IsValidPropertySet(bDSOInitialized,rgPropertySets[ul].guidPropertySet);
  1524. }
  1525. if(FAILED(hr))
  1526. break;
  1527. else
  1528. hr = S_OK;
  1529. }
  1530. return hr ;
  1531. }
  1532. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1533. //
  1534. // Set current settings of properties supported by the DSO/rowset
  1535. //
  1536. // HRESULT
  1537. // S_OK The method succeeded
  1538. // E_INVALIDARG pcProperties or prgPropertyInfo was NULL
  1539. // E_OUTOFMEMORY Out of memory
  1540. //
  1541. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1542. STDMETHODIMP CUtilProp::SetProperties ( const DWORD dwBitMask, //IN Type of PropSet
  1543. const ULONG cPropertyIDSets, //IN # of DBPROPSET
  1544. DBPROPSET rgPropertyIDSets[] //IN Array of property sets
  1545. )
  1546. {
  1547. ULONG ulPropertySets = 0;
  1548. ULONG cCount = 0;
  1549. BOOL fSetAllProps = TRUE;
  1550. BOOL fOnePropSet = FALSE;
  1551. BOOL fWarn = FALSE;
  1552. ULONG cNoOfProps = 0;
  1553. BOOL fFail = FALSE;
  1554. HRESULT hr = S_OK;
  1555. //====================================================================
  1556. // For each supported Property Set
  1557. //====================================================================
  1558. for (ulPropertySets=0; ulPropertySets < cPropertyIDSets; ulPropertySets++){
  1559. ULONG ulIndex = 0;
  1560. //================================================================
  1561. // for each prop in the propset
  1562. //================================================================
  1563. for (cCount=0; cCount < rgPropertyIDSets[ulPropertySets].cProperties; cCount++) {
  1564. cNoOfProps++;
  1565. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_OK;
  1566. //============================================================
  1567. // only allow the DBINIT and DATASOURCE
  1568. //============================================================
  1569. if ( (dwBitMask & PROPSET_DSO) && ((rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_DBINIT) &&
  1570. (dwBitMask & PROPSET_INIT)) ){
  1571. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_NOTSETTABLE;
  1572. fSetAllProps = FALSE;
  1573. }
  1574. else if ( ((dwBitMask & PROPSET_DSO) &&
  1575. (rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_DATASOURCE &&
  1576. rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_DATASOURCEINFO &&
  1577. rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_WMIOLEDB_DBINIT &&
  1578. rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_DBINIT)) ||
  1579. ((rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_DATASOURCE ||
  1580. rgPropertyIDSets[ulPropertySets].guidPropertySet == DBPROPSET_DATASOURCEINFO) &&
  1581. !(dwBitMask & PROPSET_INIT)) ){
  1582. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_NOTSUPPORTED;
  1583. fSetAllProps = FALSE;
  1584. if(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwOptions == DBPROPOPTIONS_OPTIONAL)
  1585. fWarn = TRUE;
  1586. }
  1587. //============================================================
  1588. // only allow the SESSION
  1589. //============================================================
  1590. else if ( (dwBitMask & PROPSET_SESSION) && (rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_SESSION) ){
  1591. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_NOTSUPPORTED;
  1592. fSetAllProps = FALSE;
  1593. if(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwOptions == DBPROPOPTIONS_OPTIONAL)
  1594. fWarn = TRUE;
  1595. }
  1596. //============================================================
  1597. // only allow the ROWSET
  1598. //============================================================
  1599. else if ( (dwBitMask & PROPSET_ROWSET) && (rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_ROWSET) &&
  1600. (rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_WMIOLEDB_ROWSET) ){
  1601. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_NOTSUPPORTED;
  1602. fSetAllProps = FALSE;
  1603. if(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwOptions == DBPROPOPTIONS_OPTIONAL)
  1604. fWarn = TRUE;
  1605. }
  1606. //============================================================
  1607. // only allow the COLUMN
  1608. //============================================================
  1609. else if ( (dwBitMask & PROPSET_COLUMN) && (rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_COLUMN) &&
  1610. (rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_WMIOLEDB_COLUMN) ){
  1611. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_NOTSUPPORTED;
  1612. fSetAllProps = FALSE;
  1613. if(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwOptions == DBPROPOPTIONS_OPTIONAL)
  1614. fWarn = TRUE;
  1615. }
  1616. else if ( (dwBitMask & PROPSET_COMMAND) && (rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_ROWSET) &&
  1617. (rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_WMIOLEDB_ROWSET) ) {
  1618. // && (rgPropertyIDSets[ulPropertySets].guidPropertySet != DBPROPSET_WMIOLEDB_COMMAND)){
  1619. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_NOTSUPPORTED;
  1620. fSetAllProps = FALSE;
  1621. if(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwOptions == DBPROPOPTIONS_OPTIONAL)
  1622. fWarn = TRUE;
  1623. }
  1624. else{
  1625. //========================================================
  1626. // get the index in the array
  1627. //========================================================
  1628. if ( GetPropIndex(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwPropertyID, &ulIndex) ){
  1629. //====================================================
  1630. // arg checking for the prop
  1631. //====================================================
  1632. if ( (DBPROPOPTIONS_OPTIONAL != rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwOptions) &&
  1633. (DBPROPOPTIONS_REQUIRED != rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwOptions) ){
  1634. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_BADOPTION;
  1635. fSetAllProps = FALSE;
  1636. }
  1637. else if ( !(m_prgproperties[ulIndex].dwFlags & DBPROPFLAGS_WRITE) &&
  1638. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.vt == m_prgproperties[ulIndex].vtType){
  1639. // Check if it is been tried to set to default value
  1640. if (((rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.vt == VT_BOOL) &&
  1641. ((rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.boolVal == VARIANT_TRUE) != m_prgproperties[ulIndex].boolVal)) ||
  1642. ((rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.vt == VT_I4) &&
  1643. (rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.lVal != m_prgproperties[ulIndex].longVal)) ||
  1644. ((rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.vt == VT_BSTR) &&
  1645. (wcscmp(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.bstrVal,m_prgproperties[ulIndex].pwstrVal))) )
  1646. {
  1647. fSetAllProps = FALSE;
  1648. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_NOTSETTABLE;
  1649. if(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwOptions == DBPROPOPTIONS_OPTIONAL)
  1650. fWarn = TRUE;
  1651. }
  1652. else
  1653. fOnePropSet = TRUE;
  1654. }
  1655. else if ( ((m_prgproperties[ulIndex].vtType != rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.vt) &&
  1656. (VT_EMPTY != rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.vt)) ||
  1657. (IsValidValue(&rgPropertyIDSets[ulPropertySets].rgProperties[cCount]) == S_FALSE)) {
  1658. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_BADVALUE;
  1659. fSetAllProps = FALSE;
  1660. if(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwOptions == DBPROPOPTIONS_OPTIONAL)
  1661. fWarn = TRUE;
  1662. }
  1663. else
  1664. {
  1665. fOnePropSet = TRUE;
  1666. if( rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.vt == VT_EMPTY )
  1667. {
  1668. memcpy( &m_prgproperties[ulIndex], &s_rgprop[m_nPropStartIndex + ulIndex], sizeof(PROPSTRUCT));
  1669. }
  1670. else
  1671. {
  1672. // switch on the propid
  1673. switch( m_prgproperties[ulIndex].dwPropertyID )
  1674. {
  1675. case DBPROP_INIT_DATASOURCE:
  1676. case DBPROP_AUTH_USERID:
  1677. case DBPROP_AUTH_PASSWORD:
  1678. case DBPROP_WMIOLEDB_DS_FILTER:
  1679. case DBPROP_WMIOLEDB_DS_ATTRIBUTES:
  1680. case DBPROP_WMIOLEDB_AUTHORITY:
  1681. case DBPROP_WMIOLEDB_QUERYLANGUAGE:
  1682. SAFE_DELETE_ARRAY(m_prgproperties[ulIndex].pwstrVal);
  1683. m_prgproperties[ulIndex].pwstrVal = new WCHAR [ SysStringLen(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.bstrVal) +1];
  1684. if(m_prgproperties[ulIndex].pwstrVal)
  1685. {
  1686. wcscpy(m_prgproperties[ulIndex].pwstrVal , rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue.bstrVal);
  1687. }
  1688. else
  1689. {
  1690. hr = E_OUTOFMEMORY;
  1691. fFail = TRUE;
  1692. }
  1693. break;
  1694. case DBPROP_INIT_HWND:
  1695. case DBPROP_INIT_MODE:
  1696. case DBPROP_UPDATABILITY:
  1697. case DBPROP_WMIOLEDB_QUALIFIERS:
  1698. case DBPROP_WMIOLEDB_QUALIFIERFLAVOR:
  1699. case DBPROP_INIT_PROTECTION_LEVEL:
  1700. case DBPROP_INIT_IMPERSONATION_LEVEL:
  1701. case DBPROP_WMIOLEDB_OBJECTTYPE:
  1702. case DBPROP_INIT_LCID:
  1703. case DBPROP_WMIOLEDB_DS_DEREFALIAS:
  1704. case DBPROP_WMIOLEDB_DS_SIZELIMIT:
  1705. case DBPROP_WMIOLEDB_DS_PAGEDTIMELIMIT:
  1706. case DBPROP_WMIOLEDB_DS_SEARCHSCOPE:
  1707. case DBPROP_WMIOLEDB_DS_TIMEOUT:
  1708. case DBPROP_WMIOLEDB_DS_PAGESIZE:
  1709. case DBPROP_WMIOLEDB_DS_TIMELIMIT:
  1710. case DBPROP_WMIOLEDB_DS_CHASEREF:
  1711. m_prgproperties[ulIndex].longVal = V_I4(&rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue);
  1712. break;
  1713. case DBPROP_IRowsetChange:
  1714. case DBPROP_CANHOLDROWS:
  1715. case DBPROP_LITERALIDENTITY:
  1716. case DBPROP_OWNUPDATEDELETE:
  1717. case DBPROP_OTHERUPDATEDELETE:
  1718. case DBPROP_CANFETCHBACKWARDS:
  1719. case DBPROP_CANSCROLLBACKWARDS:
  1720. case DBPROP_BOOKMARKS:
  1721. case DBPROP_WMIOLEDB_FETCHDEEP:
  1722. case DBPROP_IRow:
  1723. case DBPROP_COL_NULLABLE:
  1724. case DBPROP_COL_UNIQUE:
  1725. case DBPROP_COL_PRIMARYKEY:
  1726. case DBPROP_IRowsetLocate:
  1727. case DBPROP_WMIOLEDB_SYSTEMPROPERTIES:
  1728. case DBPROP_IGetRow:
  1729. case DBPROP_IRowsetRefresh:
  1730. case DBPROP_IChapteredRowset:
  1731. // case DBPROP_OTHERINSERT:
  1732. case DBPROP_REMOVEDELETED:
  1733. case DBPROP_WMIOLEDB_PREV_CREATE_TOKEN :
  1734. case DBPROP_WMIOLEDB_PREV_ASSIGNPRIMARYTOKEN :
  1735. case DBPROP_WMIOLEDB_PREV_LOCK_MEMORY :
  1736. case DBPROP_WMIOLEDB_PREV_INCREASE_QUOTA :
  1737. case DBPROP_WMIOLEDB_PREV_MACHINE_ACCOUNT :
  1738. case DBPROP_WMIOLEDB_PREV_TCB :
  1739. case DBPROP_WMIOLEDB_PREV_SECURITY :
  1740. case DBPROP_WMIOLEDB_PREV_TAKE_OWNERSHIP :
  1741. case DBPROP_WMIOLEDB_PREV_LOAD_DRIVER :
  1742. case DBPROP_WMIOLEDB_PREV_SYSTEM_PROFILE :
  1743. case DBPROP_WMIOLEDB_PREV_SYSTEMTIME :
  1744. case DBPROP_WMIOLEDB_PREV_PROF_SINGLE_PROCESS :
  1745. case DBPROP_WMIOLEDB_PREV_INC_BASE_PRIORITY :
  1746. case DBPROP_WMIOLEDB_PREV_CREATE_PAGEFILE :
  1747. case DBPROP_WMIOLEDB_PREV_CREATE_PERMANENT :
  1748. case DBPROP_WMIOLEDB_PREV_BACKUP :
  1749. case DBPROP_WMIOLEDB_PREV_RESTORE :
  1750. case DBPROP_WMIOLEDB_PREV_SHUTDOWN :
  1751. case DBPROP_WMIOLEDB_PREV_DEBUG :
  1752. case DBPROP_WMIOLEDB_PREV_AUDIT :
  1753. case DBPROP_WMIOLEDB_PREV_SYSTEM_ENVIRONMENT :
  1754. case DBPROP_WMIOLEDB_PREV_CHANGE_NOTIFY :
  1755. case DBPROP_WMIOLEDB_PREV_REMOTE_SHUTDOWN :
  1756. case DBPROP_WMIOLEDB_PREV_UNDOCK :
  1757. case DBPROP_WMIOLEDB_PREV_SYNC_AGENT :
  1758. case DBPROP_WMIOLEDB_PREV_ENABLE_DELEGATION :
  1759. case DBPROP_WMIOLEDB_DS_ASYNCH:
  1760. case DBPROP_WMIOLEDB_DS_CACHERESULTS:
  1761. case DBPROP_WMIOLEDB_DS_ATTRIBONLY:
  1762. case DBPROP_WMIOLEDB_DS_TOMBSTONE:
  1763. case DBPROP_WMIOLEDB_ISMETHOD:
  1764. m_prgproperties[ulIndex].boolVal = V_BOOL(&rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue);
  1765. break;
  1766. case DBPROP_INIT_PROMPT:
  1767. m_prgproperties[ulIndex].longVal = V_I2(&rgPropertyIDSets[ulPropertySets].rgProperties[cCount].vValue);
  1768. }
  1769. }
  1770. }
  1771. }
  1772. else
  1773. {
  1774. rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwStatus = DBPROPSTATUS_NOTSUPPORTED;
  1775. fSetAllProps = FALSE;
  1776. if(rgPropertyIDSets[ulPropertySets].rgProperties[cCount].dwOptions == DBPROPOPTIONS_OPTIONAL)
  1777. fWarn = TRUE;
  1778. else
  1779. {
  1780. fFail = TRUE;
  1781. }
  1782. }
  1783. }
  1784. }
  1785. }
  1786. if(fFail)
  1787. {
  1788. hr = hr == S_OK ? DB_E_ERRORSOCCURRED: hr;
  1789. return hr;
  1790. }
  1791. // Figure out the retcode
  1792. if ( fSetAllProps )
  1793. return S_OK ;
  1794. else if (fOnePropSet && !fSetAllProps)
  1795. return DB_S_ERRORSOCCURRED ;
  1796. else if((fSetAllProps == FALSE && fOnePropSet == FALSE &&
  1797. fWarn == TRUE && cNoOfProps == 1) &&
  1798. (m_propType == ROWSETPROP || m_propType == BINDERPROP))
  1799. return DB_S_ERRORSOCCURRED ;
  1800. else
  1801. return DB_E_ERRORSOCCURRED ;
  1802. }
  1803. /////////////////////////////////////////////////////////////////////////////////////////
  1804. // Gets the number of propertysets to be returned when a special GUID is passed
  1805. /////////////////////////////////////////////////////////////////////////////////////////
  1806. ULONG CUtilProp::GetNumberOfPropertySets(BOOL fDSOInitialized,const DBPROPIDSET rgPropIDSets[],ULONG cPropIDSets)
  1807. {
  1808. ULONG cPropSets = 0;
  1809. for( ULONG ulIndex = 0 ; ulIndex < cPropIDSets ; ulIndex++)
  1810. {
  1811. if( DBPROPSET_DBINITALL == rgPropIDSets[ulIndex].guidPropertySet)
  1812. {
  1813. cPropSets += 2;
  1814. }
  1815. else
  1816. if(fDSOInitialized)
  1817. {
  1818. if(DBPROPSET_ROWSETALL == rgPropIDSets[ulIndex].guidPropertySet )
  1819. {
  1820. cPropSets += 2;
  1821. }
  1822. else
  1823. if( DBPROPSET_DATASOURCEALL == rgPropIDSets[ulIndex].guidPropertySet)
  1824. {
  1825. cPropSets += 0; // as of now there are no datasource info properties
  1826. }
  1827. else
  1828. if( DBPROPSET_DATASOURCEINFOALL == rgPropIDSets[ulIndex].guidPropertySet)
  1829. {
  1830. cPropSets += 1;
  1831. }
  1832. else
  1833. if( DBPROPSET_SESSIONALL == rgPropIDSets[ulIndex].guidPropertySet )
  1834. {
  1835. cPropSets += 0; // session properties is yet to be added
  1836. }
  1837. else
  1838. if(DBPROPSET_COLUMNALL == rgPropIDSets[ulIndex].guidPropertySet)
  1839. {
  1840. cPropSets += 2; // Columns and WMioledb_columns propertysets
  1841. }
  1842. }
  1843. }
  1844. return cPropSets;
  1845. }
  1846. /////////////////////////////////////////////////////////////////////////////////////////
  1847. // Fills the propertysets informations to be returned when a special GUID is passed for GetPropertyInfo
  1848. /////////////////////////////////////////////////////////////////////////////////////////
  1849. void CUtilProp::FillPropertySets(BOOL fDSOInitialized,
  1850. const DBPROPIDSET rgPropIDSets[],
  1851. ULONG cPropIDSets,
  1852. DBPROPINFOSET* pPropInfoSet,
  1853. ULONG &cProperties)
  1854. {
  1855. cProperties = 0;
  1856. ULONG ulIndex = 0;
  1857. ULONG ulPropSetIndex = 0;
  1858. if(cPropIDSets == 0)
  1859. {
  1860. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_DBINIT;
  1861. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1862. cProperties += NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES;
  1863. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_WMIOLEDB_DBINIT;
  1864. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1865. cProperties += NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  1866. if(fDSOInitialized)
  1867. {
  1868. /* pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_WMIOLEDB_COMMAND;
  1869. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1870. cProperties += NUMBER_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  1871. */
  1872. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_ROWSET;
  1873. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1874. cProperties += NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  1875. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_WMIOLEDB_ROWSET;
  1876. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1877. cProperties += NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  1878. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_DATASOURCEINFO;
  1879. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1880. cProperties += NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES;
  1881. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_COLUMN;
  1882. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1883. cProperties += NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES;
  1884. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_WMIOLEDB_COLUMN;
  1885. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1886. cProperties += NUMBER_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  1887. }
  1888. }
  1889. else
  1890. for( ; ulIndex < cPropIDSets ;ulIndex++)
  1891. {
  1892. if( fDSOInitialized == FALSE &&
  1893. DBPROPSET_DBINITALL != rgPropIDSets[ulIndex].guidPropertySet)
  1894. {
  1895. pPropInfoSet[ulPropSetIndex].guidPropertySet = rgPropIDSets[ulIndex].guidPropertySet;
  1896. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1897. cProperties += 0;
  1898. }
  1899. else
  1900. if(DBPROPSET_ROWSETALL == rgPropIDSets[ulIndex].guidPropertySet )
  1901. {
  1902. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_ROWSET;
  1903. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1904. cProperties += NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  1905. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_WMIOLEDB_ROWSET;
  1906. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1907. cProperties += NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  1908. }
  1909. else
  1910. if( DBPROPSET_DATASOURCEINFOALL == rgPropIDSets[ulIndex].guidPropertySet )
  1911. {
  1912. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_DATASOURCEINFO;
  1913. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1914. cProperties += NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES;
  1915. }
  1916. else
  1917. if( DBPROPSET_DBINITALL == rgPropIDSets[ulIndex].guidPropertySet)
  1918. {
  1919. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_DBINIT;
  1920. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1921. cProperties += NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES;
  1922. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_WMIOLEDB_DBINIT;
  1923. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1924. cProperties += NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  1925. }
  1926. else
  1927. if(DBPROPSET_COLUMNALL == rgPropIDSets[ulIndex].guidPropertySet)
  1928. {
  1929. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_COLUMN;
  1930. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1931. cProperties += NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES;
  1932. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_WMIOLEDB_COLUMN;
  1933. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1934. cProperties += NUMBER_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  1935. }
  1936. // NTRaid : 142133
  1937. // 07/12/00
  1938. // since we don't support any of the property in the following Special GUIL
  1939. // this is been commented
  1940. /* else
  1941. if(DBPROPSET_DATASOURCEALL == rgPropIDSets[ulIndex].guidPropertySet )
  1942. {
  1943. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_DATASOURCEALL;
  1944. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1945. cProperties += 0;
  1946. }
  1947. else
  1948. if(DBPROPSET_CONSTRAINTALL == rgPropIDSets[ulIndex].guidPropertySet )
  1949. {
  1950. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_CONSTRAINTALL;
  1951. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1952. cProperties += 0;
  1953. }
  1954. else
  1955. if(DBPROPSET_INDEXALL == rgPropIDSets[ulIndex].guidPropertySet)
  1956. {
  1957. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_INDEXALL;
  1958. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1959. cProperties += 0;
  1960. }
  1961. else
  1962. if(DBPROPSET_SESSIONALL == rgPropIDSets[ulIndex].guidPropertySet)
  1963. {
  1964. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_SESSIONALL;
  1965. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1966. cProperties += 0;
  1967. }
  1968. else
  1969. if(DBPROPSET_TABLEALL == rgPropIDSets[ulIndex].guidPropertySet)
  1970. {
  1971. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_TABLEALL;
  1972. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1973. cProperties += 0;
  1974. }
  1975. else
  1976. if(DBPROPSET_TRUSTEEALL == rgPropIDSets[ulIndex].guidPropertySet)
  1977. {
  1978. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_TRUSTEEALL;
  1979. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1980. cProperties += 0;
  1981. }
  1982. else
  1983. if(DBPROPSET_VIEWALL == rgPropIDSets[ulIndex].guidPropertySet && fDSOInitialized == TRUE)
  1984. {
  1985. pPropInfoSet[ulPropSetIndex].guidPropertySet = DBPROPSET_VIEWALL;
  1986. pPropInfoSet[ulPropSetIndex++].cPropertyInfos = 0;
  1987. cProperties += 0;
  1988. }
  1989. */ }
  1990. }
  1991. /////////////////////////////////////////////////////////////////////////////////////////
  1992. // Gets the number of propertysets to be returned for a particular type of property object
  1993. // if 0 is passed for the number of property set to be retrieved
  1994. /////////////////////////////////////////////////////////////////////////////////////////
  1995. ULONG CUtilProp::GetNumberOfPropertySets(BOOL fDSOInitialized,DWORD dwBitMask)
  1996. {
  1997. ULONG cPropSets = 0;
  1998. switch(m_propType)
  1999. {
  2000. case DATASOURCEPROP :
  2001. if(fDSOInitialized == TRUE)
  2002. cPropSets = 3; // DBINIT & WMIOLEDB_DBINIT && DATASOURCEINFO
  2003. else
  2004. cPropSets = 2; // DBINIT & WMIOLEDB_DBINIT
  2005. break;
  2006. case SESSIONPROP :
  2007. cPropSets = 0; // number of sesssion propertysets
  2008. break;
  2009. case COMMANDPROP :
  2010. cPropSets = 3; // WMIOLEDB_COMMAND & ROWSET & WMIOLEDB_ROWSET
  2011. break;
  2012. case ROWSETPROP :
  2013. cPropSets = 2; // ROWSET & WMIOLEDB_ROWSET
  2014. break;
  2015. case BINDERPROP:
  2016. switch(dwBitMask)
  2017. {
  2018. case PROPSET_INIT:
  2019. cPropSets = 2;
  2020. break;
  2021. case PROPSET_DSO:
  2022. case PROPSET_DSOINIT:
  2023. if(fDSOInitialized == TRUE)
  2024. cPropSets = 3;
  2025. else
  2026. cPropSets = 2;
  2027. break;
  2028. case PROPSET_SESSION:
  2029. cPropSets = 0;
  2030. break;
  2031. case PROPSET_COMMAND:
  2032. cPropSets = 3;
  2033. break;
  2034. case PROPSET_ROWSET:
  2035. cPropSets = 2;
  2036. break;
  2037. case PROPSET_COLUMN:
  2038. cPropSets = 2;
  2039. break;
  2040. default:
  2041. cPropSets = NUMBER_OF_SUPPORTED_PROPERTY_SETS; // all propertysets supported
  2042. }
  2043. break;
  2044. case COLUMNPROP:
  2045. cPropSets = 2; // COLUMNS & WMIOLEDB_COLUMN
  2046. break;
  2047. };
  2048. return cPropSets;
  2049. }
  2050. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2051. // Reset all the properties to default properties
  2052. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2053. HRESULT CUtilProp::ResetProperties()
  2054. {
  2055. ULONG nPropStartIndex = 0;
  2056. switch(m_propType)
  2057. {
  2058. case DATASOURCEPROP :
  2059. nPropStartIndex = 0;
  2060. break;
  2061. case SESSIONPROP :
  2062. nPropStartIndex = START_OF_SUPPORTED_SESSION_PROPERTIES;
  2063. break;
  2064. case COMMANDPROP :
  2065. nPropStartIndex = NUMBER_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  2066. break;
  2067. case ROWSETPROP :
  2068. nPropStartIndex = START_OF_SUPPORTED_ROWSET_PROPERTIES;
  2069. break;
  2070. case BINDERPROP:
  2071. nPropStartIndex = 0;
  2072. break;
  2073. };
  2074. if(m_cProperties > 0)
  2075. {
  2076. memcpy(m_prgproperties, &s_rgprop[nPropStartIndex], sizeof(PROPSTRUCT) * m_cProperties );
  2077. }
  2078. return S_OK;
  2079. }
  2080. /////////////////////////////////////////////////////////////////////////////////////////
  2081. // Fills the different PropertIDsets when the number of propertysets
  2082. // requested for GetProperties is 0
  2083. /////////////////////////////////////////////////////////////////////////////////////////
  2084. HRESULT CUtilProp::FillPropStruct(BOOL fDSOInitialized,DWORD dwBitMask,DBPROPSET* pPropSet)
  2085. {
  2086. HRESULT hr = S_OK;
  2087. ULONG lIndex = 0;
  2088. if(pPropSet == NULL)
  2089. {
  2090. hr = E_FAIL;
  2091. }
  2092. else
  2093. switch(m_propType)
  2094. {
  2095. case DATASOURCEPROP :
  2096. pPropSet[lIndex].guidPropertySet = DBPROPSET_DBINIT;
  2097. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES;
  2098. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_DBINIT;
  2099. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  2100. if(fDSOInitialized == TRUE)
  2101. {
  2102. pPropSet[lIndex].guidPropertySet = DBPROPSET_DATASOURCEINFO;
  2103. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES;
  2104. }
  2105. break;
  2106. case SESSIONPROP :
  2107. break;
  2108. case COMMANDPROP :
  2109. /* pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_COMMAND;
  2110. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  2111. */
  2112. pPropSet[lIndex].guidPropertySet = DBPROPSET_ROWSET;
  2113. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  2114. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_ROWSET;
  2115. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  2116. break;
  2117. case ROWSETPROP :
  2118. pPropSet[lIndex].guidPropertySet = DBPROPSET_ROWSET;
  2119. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  2120. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_ROWSET;
  2121. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  2122. break;
  2123. case BINDERPROP:
  2124. switch(dwBitMask)
  2125. {
  2126. case PROPSET_INIT:
  2127. pPropSet[lIndex].guidPropertySet = DBPROPSET_DBINIT;
  2128. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES;
  2129. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_DBINIT;
  2130. pPropSet[lIndex].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  2131. break;
  2132. case PROPSET_DSO:
  2133. case PROPSET_DSOINIT:
  2134. pPropSet[lIndex].guidPropertySet = DBPROPSET_DBINIT;
  2135. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES;
  2136. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_DBINIT;
  2137. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  2138. if(fDSOInitialized == TRUE)
  2139. {
  2140. pPropSet[lIndex].guidPropertySet = DBPROPSET_DATASOURCEINFO;
  2141. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES;
  2142. }
  2143. break;
  2144. case PROPSET_SESSION:
  2145. break;
  2146. case PROPSET_COMMAND:
  2147. /* pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_COMMAND;
  2148. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  2149. */
  2150. pPropSet[lIndex].guidPropertySet = DBPROPSET_ROWSET;
  2151. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  2152. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_ROWSET;
  2153. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  2154. break;
  2155. case PROPSET_ROWSET:
  2156. pPropSet[lIndex].guidPropertySet = DBPROPSET_ROWSET;
  2157. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  2158. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_ROWSET;
  2159. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  2160. break;
  2161. case PROPSET_COLUMN:
  2162. pPropSet[lIndex].guidPropertySet = DBPROPSET_COLUMN;
  2163. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES;
  2164. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_COLUMN;
  2165. pPropSet[lIndex++].cProperties = START_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  2166. break;
  2167. default:
  2168. pPropSet[lIndex].guidPropertySet = DBPROPSET_DBINIT;
  2169. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES;
  2170. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_DBINIT;
  2171. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  2172. pPropSet[lIndex].guidPropertySet = DBPROPSET_DATASOURCEINFO;
  2173. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES;
  2174. /* pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_COMMAND;
  2175. pPropSet[lIndex++].cProperties = START_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  2176. */
  2177. pPropSet[lIndex].guidPropertySet = DBPROPSET_ROWSET;
  2178. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  2179. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_ROWSET;
  2180. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  2181. pPropSet[lIndex].guidPropertySet = DBPROPSET_COLUMN;
  2182. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES;
  2183. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_COLUMN;
  2184. pPropSet[lIndex++].cProperties = START_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  2185. };
  2186. break;
  2187. case COLUMNPROP:
  2188. pPropSet[lIndex].guidPropertySet = DBPROPSET_COLUMN;
  2189. pPropSet[lIndex++].cProperties = NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES;
  2190. pPropSet[lIndex].guidPropertySet = DBPROPSET_WMIOLEDB_COLUMN;
  2191. pPropSet[lIndex++].cProperties = START_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  2192. };
  2193. return hr;
  2194. }
  2195. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2196. // Checks if the PropertysetIDs are proper
  2197. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2198. HRESULT CUtilProp::IsValidPropertySet(BOOL fDSOInitialized,const GUID guidPropset)
  2199. {
  2200. HRESULT hr = S_OK;
  2201. /*
  2202. if(guidPropset == DBPROPSET_PROPERTIESINERROR &&
  2203. (m_propType == DATASOURCEPROP || m_propType == COMMANDPROP))
  2204. return hr;
  2205. else
  2206. return DB_S_ERRORSOCCURRED;
  2207. */
  2208. switch(m_propType)
  2209. {
  2210. case DATASOURCEPROP :
  2211. if(!( guidPropset == DBPROPSET_DBINIT ||
  2212. (guidPropset == DBPROPSET_DATASOURCEINFO && fDSOInitialized == TRUE) ||
  2213. guidPropset == DBPROPSET_WMIOLEDB_DBINIT ||
  2214. guidPropset == DBPROPSET_PROPERTIESINERROR))
  2215. {
  2216. hr = DB_S_ERRORSOCCURRED;
  2217. }
  2218. break;
  2219. case SESSIONPROP :
  2220. if(!( guidPropset == DBPROPSET_SESSION))
  2221. {
  2222. hr = DB_S_ERRORSOCCURRED;
  2223. }
  2224. break;
  2225. case COMMANDPROP :
  2226. if(!( guidPropset == DBPROPSET_ROWSET ||
  2227. guidPropset == DBPROPSET_WMIOLEDB_ROWSET ||
  2228. // guidPropset == DBPROPSET_WMIOLEDB_COMMAND ||
  2229. guidPropset == DBPROPSET_PROPERTIESINERROR))
  2230. {
  2231. hr = DB_S_ERRORSOCCURRED;
  2232. }
  2233. case ROWSETPROP :
  2234. if(!( guidPropset == DBPROPSET_ROWSET ||
  2235. guidPropset == DBPROPSET_WMIOLEDB_ROWSET))
  2236. {
  2237. hr = DB_S_ERRORSOCCURRED;
  2238. }
  2239. break;
  2240. case BINDERPROP :
  2241. hr = S_OK;
  2242. break;
  2243. case COLUMNPROP :
  2244. if(!( guidPropset == DBPROPSET_COLUMN ||
  2245. guidPropset == DBPROPSET_WMIOLEDB_COLUMN))
  2246. {
  2247. hr = DB_S_ERRORSOCCURRED;
  2248. }
  2249. break;
  2250. };
  2251. return hr;
  2252. }
  2253. BOOL CUtilProp::IsPropertySetSupported(const GUID guidPropset)
  2254. {
  2255. BOOL bRet = FALSE;
  2256. if(guidPropset == DBPROPSET_PROPERTIESINERROR ||
  2257. guidPropset == DBPROPSET_DBINIT ||
  2258. guidPropset == DBPROPSET_DATASOURCEINFO ||
  2259. guidPropset == DBPROPSET_WMIOLEDB_DBINIT ||
  2260. guidPropset == DBPROPSET_SESSION ||
  2261. guidPropset == DBPROPSET_ROWSET ||
  2262. guidPropset == DBPROPSET_WMIOLEDB_ROWSET ||
  2263. guidPropset == DBPROPSET_COLUMN ||
  2264. guidPropset == DBPROPSET_WMIOLEDB_COLUMN )
  2265. // || guidPropset == DBPROPSET_WMIOLEDB_COMMAND )
  2266. {
  2267. bRet = TRUE;
  2268. };
  2269. return bRet;
  2270. }
  2271. ULONG CUtilProp::GetNumberofPropInfoToBeReturned(BOOL bDSOInitialized,
  2272. ULONG cPropertyIDSets,
  2273. const DBPROPIDSET rgPropertyIDSets[])
  2274. {
  2275. int nProps = 0;
  2276. if(cPropertyIDSets == 0)
  2277. {
  2278. nProps = NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES +
  2279. NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES;
  2280. if(bDSOInitialized)
  2281. {
  2282. nProps = nProps + NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES +
  2283. NUMBER_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES +
  2284. NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES +
  2285. NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES +
  2286. NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES +
  2287. NUMBER_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  2288. }
  2289. }
  2290. else
  2291. for( ULONG ulPropSets = 0; ulPropSets < cPropertyIDSets;ulPropSets++)
  2292. {
  2293. if (rgPropertyIDSets[ulPropSets].guidPropertySet == DBPROPSET_DBINIT)
  2294. {
  2295. if(rgPropertyIDSets[ulPropSets].cPropertyIDs == 0 )
  2296. {
  2297. nProps += NUMBER_OF_SUPPORTED_DBINIT_PROPERTIES ;
  2298. }
  2299. else
  2300. {
  2301. nProps += rgPropertyIDSets[ulPropSets].cPropertyIDs;
  2302. }
  2303. }
  2304. else
  2305. if (rgPropertyIDSets[ulPropSets].guidPropertySet == DBPROPSET_WMIOLEDB_DBINIT)
  2306. {
  2307. if(rgPropertyIDSets[ulPropSets].cPropertyIDs == 0 )
  2308. {
  2309. nProps += NUMBER_OF_SUPPORTED_WMIOLEDB_DBINIT_PROPERTIES ;
  2310. }
  2311. else
  2312. {
  2313. nProps += rgPropertyIDSets[ulPropSets].cPropertyIDs;
  2314. }
  2315. }
  2316. else
  2317. if( bDSOInitialized )
  2318. {
  2319. if(rgPropertyIDSets[ulPropSets].guidPropertySet == DBPROPSET_DATASOURCEINFO)
  2320. {
  2321. if(rgPropertyIDSets[ulPropSets].cPropertyIDs == 0 )
  2322. {
  2323. nProps += NUMBER_OF_SUPPORTED_DATASOURCEINFO_PROPERTIES;
  2324. }
  2325. else
  2326. {
  2327. nProps += rgPropertyIDSets[ulPropSets].cPropertyIDs;
  2328. }
  2329. }
  2330. else
  2331. if(rgPropertyIDSets[ulPropSets].guidPropertySet == DBPROPSET_WMIOLEDB_COMMAND)
  2332. {
  2333. if(rgPropertyIDSets[ulPropSets].cPropertyIDs == 0 )
  2334. {
  2335. nProps += NUMBER_OF_SUPPORTED_WMIOLEDB_COMMAND_PROPERTIES;
  2336. }
  2337. else
  2338. {
  2339. nProps += rgPropertyIDSets[ulPropSets].cPropertyIDs;
  2340. }
  2341. }
  2342. else
  2343. if(rgPropertyIDSets[ulPropSets].guidPropertySet == DBPROPSET_ROWSET)
  2344. {
  2345. if(rgPropertyIDSets[ulPropSets].cPropertyIDs == 0 )
  2346. {
  2347. nProps += NUMBER_OF_SUPPORTED_ROWSET_PROPERTIES;
  2348. }
  2349. else
  2350. {
  2351. nProps += rgPropertyIDSets[ulPropSets].cPropertyIDs;
  2352. }
  2353. }
  2354. else
  2355. if(rgPropertyIDSets[ulPropSets].guidPropertySet == DBPROPSET_WMIOLEDB_ROWSET)
  2356. {
  2357. if(rgPropertyIDSets[ulPropSets].cPropertyIDs == 0 )
  2358. {
  2359. nProps += NUMBER_OF_SUPPORTED_WMIOLEDB_ROWSET_PROPERTIES;
  2360. }
  2361. else
  2362. {
  2363. nProps += rgPropertyIDSets[ulPropSets].cPropertyIDs;
  2364. }
  2365. }
  2366. else
  2367. if(rgPropertyIDSets[ulPropSets].guidPropertySet == DBPROPSET_COLUMN)
  2368. {
  2369. if(rgPropertyIDSets[ulPropSets].cPropertyIDs == 0 )
  2370. {
  2371. nProps += NUMBER_OF_SUPPORTED_COLUMN_PROPERTIES;
  2372. }
  2373. else
  2374. {
  2375. nProps += rgPropertyIDSets[ulPropSets].cPropertyIDs;
  2376. }
  2377. }
  2378. else
  2379. if(rgPropertyIDSets[ulPropSets].guidPropertySet == DBPROPSET_WMIOLEDB_COLUMN)
  2380. {
  2381. if(rgPropertyIDSets[ulPropSets].cPropertyIDs == 0 )
  2382. {
  2383. nProps += NUMBER_OF_SUPPORTED_WMIOLEDB_COLUMN_PROPERTIES;
  2384. }
  2385. else
  2386. {
  2387. nProps += rgPropertyIDSets[ulPropSets].cPropertyIDs;
  2388. }
  2389. }
  2390. }
  2391. }
  2392. return nProps;
  2393. }
  2394. HRESULT CUtilProp::GetConnectionInitProperties(DBPROPSET** pprgPropertySets)
  2395. {
  2396. DBPROPIDSET rgPropertyIDSets[1];
  2397. ULONG cPropertySets;
  2398. DBPROPID rgPropId[NUMBER_OF_CONNECTIONINIT_PROP];
  2399. rgPropId[0] = DBPROP_INIT_DATASOURCE;
  2400. rgPropId[1] = DBPROP_INIT_PROTECTION_LEVEL;
  2401. rgPropId[2] = DBPROP_INIT_IMPERSONATION_LEVEL;
  2402. rgPropId[3] = DBPROP_AUTH_USERID;
  2403. rgPropId[4] = DBPROP_AUTH_PASSWORD;
  2404. rgPropId[5] = DBPROP_INIT_LCID;
  2405. rgPropId[6] = DBPROP_WMIOLEDB_AUTHORITY;
  2406. rgPropertyIDSets[0].guidPropertySet = DBPROPSET_DBINIT;
  2407. rgPropertyIDSets[0].rgPropertyIDs = rgPropId;
  2408. rgPropertyIDSets[0].cPropertyIDs = 7;
  2409. return GetProperties( PROPSET_DSO,1, rgPropertyIDSets,&cPropertySets,pprgPropertySets );
  2410. }
  2411. HRESULT CUtilProp::SetDefaultValueForStringProperties(PROPSTRUCT * prgPropeties,ULONG cProperties)
  2412. {
  2413. HRESULT hr = S_OK;
  2414. for(ULONG lProperties = 0; lProperties < cProperties ; lProperties++)
  2415. {
  2416. switch(prgPropeties[lProperties].dwPropertyID)
  2417. {
  2418. case DBPROP_INIT_DATASOURCE:
  2419. case DBPROP_AUTH_USERID:
  2420. case DBPROP_AUTH_PASSWORD:
  2421. case DBPROP_WMIOLEDB_DS_FILTER:
  2422. case DBPROP_WMIOLEDB_DS_ATTRIBUTES:
  2423. case DBPROP_WMIOLEDB_AUTHORITY:
  2424. prgPropeties[lProperties].pwstrVal = NULL;
  2425. break;
  2426. case DBPROP_WMIOLEDB_QUERYLANGUAGE:
  2427. prgPropeties[lProperties].pwstrVal = new WCHAR[wcslen(DEFAULTQUERYLANG) + 1];
  2428. if(prgPropeties[lProperties].pwstrVal)
  2429. {
  2430. wcscpy(prgPropeties[lProperties].pwstrVal,DEFAULTQUERYLANG);
  2431. }
  2432. else
  2433. {
  2434. hr = E_OUTOFMEMORY;
  2435. }
  2436. break;
  2437. }
  2438. }
  2439. return hr;
  2440. }
  2441. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2442. //
  2443. //
  2444. // This class manages the memory allocations of all the property structs
  2445. //
  2446. //
  2447. //
  2448. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2449. HRESULT CPropertyMemoryMgr::AllocDBPROPINFOSET(DBPROPINFOSET *& pPropInfoSet, const ULONG cProps)
  2450. {
  2451. HRESULT hr = S_OK;
  2452. pPropInfoSet = (DBPROPINFOSET*) g_pIMalloc->Alloc(cProps * sizeof( DBPROPINFOSET ));
  2453. if ( !pPropInfoSet ){
  2454. hr = E_OUTOFMEMORY ;
  2455. }
  2456. else{
  2457. memset( pPropInfoSet, 0, (cProps * sizeof( DBPROPINFOSET )));
  2458. }
  2459. return hr;
  2460. }
  2461. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2462. HRESULT CPropertyMemoryMgr::AllocDESCRIPTBuffer(WCHAR *& pDescBuffer, WCHAR** ppDescBuffer, ULONG cProperties)
  2463. {
  2464. HRESULT hr = S_OK;
  2465. if ( ppDescBuffer ){
  2466. pDescBuffer = (WCHAR*)g_pIMalloc->Alloc(cProperties * CCH_GETPROPERTYINFO_DESCRIP_BUFFER_SIZE * sizeof(WCHAR) );
  2467. if( pDescBuffer ){
  2468. memset(pDescBuffer, 0, (cProperties * CCH_GETPROPERTYINFO_DESCRIP_BUFFER_SIZE * sizeof(WCHAR)));
  2469. *ppDescBuffer = pDescBuffer;
  2470. }
  2471. else{
  2472. hr = E_OUTOFMEMORY ;
  2473. }
  2474. }
  2475. return hr;
  2476. }
  2477. //=====================================================================================================
  2478. HRESULT CPropertyMemoryMgr::AllocDBPROPINFO(DBPROPINFO *& pPropInfo, DBPROPINFOSET * pPropInfoSet, ULONG ulPropSets)
  2479. {
  2480. HRESULT hr = S_OK;
  2481. pPropInfo = (DBPROPINFO*) g_pIMalloc->Alloc(sizeof( DBPROPINFO ) * pPropInfoSet[ulPropSets].cPropertyInfos);
  2482. if( pPropInfo ){
  2483. }
  2484. else{
  2485. hr = E_OUTOFMEMORY;
  2486. }
  2487. return hr;
  2488. }
  2489. //=====================================================================================================
  2490. HRESULT CPropertyMemoryMgr::AllocateDBPROP(DBPROP*& ppProp, const ULONG cProperties)
  2491. {
  2492. HRESULT hr = E_INVALIDARG;
  2493. if ( NULL != ppProp && NULL == ppProp && cProperties > 0 ) {
  2494. ppProp = (DBPROP*)g_pIMalloc->Alloc(cProperties * sizeof DBPROP);
  2495. // *ppProp = new DBPROP[cProperties];
  2496. if ( NULL == ppProp ){
  2497. hr = E_OUTOFMEMORY;
  2498. }
  2499. else {
  2500. memset(ppProp, 0, sizeof DBPROP);
  2501. hr = S_OK;
  2502. }
  2503. }
  2504. return hr;
  2505. }
  2506. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2507. HRESULT CPropertyMemoryMgr::AllocDBPROPSET(DBPROPSET*& ppPropSet, const ULONG cPropSets)
  2508. {
  2509. HRESULT hr = E_INVALIDARG;
  2510. if ( NULL != ppPropSet && NULL == ppPropSet && cPropSets > 0 ) {
  2511. ppPropSet = (DBPROPSET*)g_pIMalloc->Alloc(cPropSets * sizeof DBPROPSET);
  2512. if ( NULL == ppPropSet ){
  2513. hr = E_OUTOFMEMORY;
  2514. }
  2515. else {
  2516. memset(ppPropSet, 0, cPropSets * sizeof DBPROPSET);
  2517. hr = S_OK;
  2518. }
  2519. }
  2520. return hr;
  2521. }
  2522. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2523. HRESULT CPropertyMemoryMgr::AllocDBCOLUMNDESC(DBCOLUMNDESC*& ppCOLUMNDESC, const ULONG cColumnDescs)
  2524. {
  2525. HRESULT hr = E_INVALIDARG;
  2526. if ( NULL != ppCOLUMNDESC && NULL == ppCOLUMNDESC && cColumnDescs > 0 ) {
  2527. ppCOLUMNDESC = (DBCOLUMNDESC*)g_pIMalloc->Alloc(cColumnDescs * sizeof DBCOLUMNDESC);
  2528. if ( NULL == ppCOLUMNDESC ){
  2529. hr = E_OUTOFMEMORY;
  2530. }
  2531. else {
  2532. memset(ppCOLUMNDESC, 0, cColumnDescs * sizeof DBCOLUMNDESC);
  2533. hr = S_OK;
  2534. }
  2535. }
  2536. return hr;
  2537. }
  2538. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2539. void CPropertyMemoryMgr::FreeDBPROPINFOSET(DBPROPINFOSET *& pPropInfoSet, const ULONG cProps)
  2540. {
  2541. if (pPropInfoSet){
  2542. for(ULONG i = 0 ; i < cProps ; i++)
  2543. {
  2544. if(pPropInfoSet[i].rgPropertyInfos)
  2545. {
  2546. FreeDBPROPINFO(pPropInfoSet[i].rgPropertyInfos , pPropInfoSet[i].cPropertyInfos);
  2547. }
  2548. }
  2549. g_pIMalloc->Free(pPropInfoSet);
  2550. pPropInfoSet = NULL;
  2551. }
  2552. }
  2553. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2554. void CPropertyMemoryMgr::FreeDBPROPINFO(DBPROPINFO *& pPropInfo, const ULONG cProps)
  2555. {
  2556. if(pPropInfo)
  2557. {
  2558. for(ULONG i = 0 ; i < cProps; i++)
  2559. {
  2560. VariantClear(&pPropInfo[i].vValues);
  2561. }
  2562. g_pIMalloc->Free(pPropInfo);
  2563. }
  2564. }
  2565. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2566. void CPropertyMemoryMgr::FreeDESCRIPTBuffer(WCHAR *& pDescBuffer, WCHAR** ppDescBuffer)
  2567. {
  2568. if ( ppDescBuffer ) {
  2569. *ppDescBuffer = NULL;
  2570. }
  2571. if( pDescBuffer ){
  2572. g_pIMalloc->Free(pDescBuffer);
  2573. pDescBuffer = NULL;
  2574. }
  2575. }
  2576. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2577. void CPropertyMemoryMgr::FreeDBCOLUMNDESC(DBCOLUMNDESC rgColumnDescs[], LONG cColumns)
  2578. {
  2579. if ( rgColumnDescs ){
  2580. for ( LONG i = 0; i < cColumns; i++ ) {
  2581. //free pointers
  2582. SysFreeString((BSTR)(rgColumnDescs[i].pwszTypeName));
  2583. if ( rgColumnDescs[i].pTypeInfo ) {
  2584. rgColumnDescs[i].pTypeInfo->Release();
  2585. rgColumnDescs[i].pTypeInfo = NULL;
  2586. }
  2587. //free sub structs
  2588. FreeDBPROPSET(rgColumnDescs[i].cPropertySets,rgColumnDescs[i].rgPropertySets);
  2589. rgColumnDescs[i].rgPropertySets = NULL;
  2590. }
  2591. g_pIMalloc->Free(rgColumnDescs);
  2592. }
  2593. }
  2594. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2595. HRESULT CPropertyMemoryMgr::CopyDBPROPSET(DBPROPSET*& pDestination, DBPROPSET*& pSource)
  2596. {
  2597. if ( NULL == pSource ||
  2598. NULL == pDestination ||
  2599. NULL != pDestination->rgProperties )
  2600. return E_INVALIDARG;
  2601. memcpy(pDestination, pSource, sizeof DBPROPSET);
  2602. memset(pSource->rgProperties, 0, sizeof DBPROPSET);
  2603. return S_OK;
  2604. }
  2605. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2606. HRESULT CPropertyMemoryMgr::CopyDBCOLUMNDESC(DBCOLUMNDESC*& pDestination, DBCOLUMNDESC*& pSource)
  2607. {
  2608. if ( NULL == pSource ||
  2609. NULL == pDestination ||
  2610. NULL != pDestination->rgPropertySets ) //must not contain data
  2611. return E_INVALIDARG;
  2612. memcpy(pDestination, pSource, sizeof DBCOLUMNDESC);
  2613. memset(pSource->rgPropertySets, 0, sizeof DBCOLUMNDESC);
  2614. return S_OK;
  2615. }
  2616. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2617. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2618. // CPriveligeToken class implementation
  2619. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2620. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2621. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2622. // Constructor
  2623. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2624. CPreviligeToken::CPreviligeToken()
  2625. {
  2626. m_nMemAllocated = 0;
  2627. m_pPrevTokenPrev = NULL;
  2628. }
  2629. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2630. // Destructor
  2631. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2632. CPreviligeToken::~CPreviligeToken()
  2633. {
  2634. SAFE_DELETE_ARRAY(m_pPrevTokenPrev);
  2635. }
  2636. // NTRaid: 136443
  2637. // 07/05/00
  2638. HRESULT CPreviligeToken::FInit()
  2639. {
  2640. HRESULT hr = S_OK;
  2641. m_nMemAllocated = sizeof(TOKEN_PRIVILEGES) + NUMBEROF_PRIVELAGES * sizeof(LUID_AND_ATTRIBUTES);
  2642. m_pPrevTokenPrev = (TOKEN_PRIVILEGES *)new BYTE [m_nMemAllocated];
  2643. if(m_pPrevTokenPrev)
  2644. {
  2645. memset(m_pPrevTokenPrev,0,m_nMemAllocated);
  2646. GetCurrentPrivelegeToken();
  2647. }
  2648. else
  2649. {
  2650. hr = E_OUTOFMEMORY;
  2651. }
  2652. return hr;
  2653. }
  2654. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2655. // Function to adjust the privileges
  2656. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2657. BOOL CPreviligeToken::AdjustTokenPrivileges(ULONG cProps , DBPROP rgProp[])
  2658. {
  2659. BOOL bRet = FALSE;
  2660. HANDLE hToken = NULL;
  2661. /* DWORD dwError;
  2662. ConvertDBPropToPriveleges(cProps,rgProp);
  2663. dwError = GetLastError();
  2664. // if(bRet = OpenThreadToken(GetCurrentThread(),TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES,FALSE,&hToken))
  2665. if(OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES,&hToken))
  2666. */
  2667. OpenToken(hToken);
  2668. if(hToken != NULL)
  2669. {
  2670. bRet = ::AdjustTokenPrivileges(hToken,
  2671. FALSE,
  2672. m_pPrevTokenPrev,
  2673. 0,
  2674. NULL,
  2675. NULL);
  2676. CloseHandle(hToken);
  2677. }
  2678. return bRet;
  2679. }
  2680. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2681. // Function to Set the DBPROP structure accoriding to the current privileges
  2682. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2683. void CPreviligeToken::SetDBPROPForPrivileges(ULONG cProps , DBPROP * rgProp)
  2684. {
  2685. ULONG_PTR lPropValTemp = 1;
  2686. ULONG lSize = PRIVILEGE_NAMESIZE;
  2687. LONG lIndex = -1;
  2688. TCHAR strName[PRIVILEGE_NAMESIZE];
  2689. memset(strName,0,PRIVILEGE_NAMESIZE * sizeof(TCHAR));
  2690. for(ULONG_PTR i = 0 ; i < m_pPrevTokenPrev->PrivilegeCount ; i++)
  2691. {
  2692. lIndex = -1;
  2693. LookupPrivilegeName(NULL,&((m_pPrevTokenPrev->Privileges[i]).Luid) ,&strName[0],&lSize);
  2694. if(!_tcscmp(strName,SE_CREATE_TOKEN_NAME))
  2695. {
  2696. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_CREATE_TOKEN,&lIndex);
  2697. }
  2698. else if(!_tcscmp(strName,SE_ASSIGNPRIMARYTOKEN_NAME))
  2699. {
  2700. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_ASSIGNPRIMARYTOKEN,&lIndex);
  2701. }
  2702. else if(!_tcscmp(strName,SE_LOCK_MEMORY_NAME))
  2703. {
  2704. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_LOCK_MEMORY,&lIndex);
  2705. }
  2706. else if(!_tcscmp(strName,SE_INCREASE_QUOTA_NAME))
  2707. {
  2708. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_INCREASE_QUOTA,&lIndex);
  2709. }
  2710. else if(!_tcscmp(strName,SE_MACHINE_ACCOUNT_NAME))
  2711. {
  2712. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_MACHINE_ACCOUNT,&lIndex);
  2713. }
  2714. else if(!_tcscmp(strName,SE_TCB_NAME))
  2715. {
  2716. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_TCB,&lIndex);
  2717. }
  2718. else if(!_tcscmp(strName,SE_SECURITY_NAME))
  2719. {
  2720. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_SECURITY,&lIndex);
  2721. }
  2722. else if(!_tcscmp(strName,SE_TAKE_OWNERSHIP_NAME))
  2723. {
  2724. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_TAKE_OWNERSHIP,&lIndex);
  2725. }
  2726. else if(!_tcscmp(strName,SE_LOAD_DRIVER_NAME))
  2727. {
  2728. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_LOAD_DRIVER,&lIndex);
  2729. }
  2730. else if(!_tcscmp(strName,SE_SYSTEM_PROFILE_NAME))
  2731. {
  2732. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_SYSTEM_PROFILE,&lIndex);
  2733. }
  2734. else if(!_tcscmp(strName,SE_SYSTEMTIME_NAME))
  2735. {
  2736. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_SYSTEMTIME,&lIndex);
  2737. }
  2738. else if(!_tcscmp(strName,SE_PROF_SINGLE_PROCESS_NAME))
  2739. {
  2740. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_PROF_SINGLE_PROCESS,&lIndex);
  2741. }
  2742. else if(!_tcscmp(strName,SE_INC_BASE_PRIORITY_NAME))
  2743. {
  2744. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_INC_BASE_PRIORITY,&lIndex);
  2745. }
  2746. else if(!_tcscmp(strName,SE_CREATE_PAGEFILE_NAME))
  2747. {
  2748. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_CREATE_PAGEFILE,&lIndex);
  2749. }
  2750. else if(!_tcscmp(strName,SE_CREATE_PERMANENT_NAME))
  2751. {
  2752. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_CREATE_PERMANENT,&lIndex);
  2753. }
  2754. else if(!_tcscmp(strName,SE_BACKUP_NAME))
  2755. {
  2756. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_BACKUP,&lIndex);
  2757. }
  2758. else if(!_tcscmp(strName,SE_RESTORE_NAME))
  2759. {
  2760. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_RESTORE,&lIndex);
  2761. }
  2762. else if(!_tcscmp(strName,SE_SHUTDOWN_NAME))
  2763. {
  2764. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_SHUTDOWN,&lIndex);
  2765. }
  2766. else if(!_tcscmp(strName,SE_DEBUG_NAME))
  2767. {
  2768. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_DEBUG,&lIndex);
  2769. }
  2770. else if(!_tcscmp(strName,SE_AUDIT_NAME))
  2771. {
  2772. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_AUDIT,&lIndex);
  2773. }
  2774. else if(!_tcscmp(strName,SE_SYSTEM_ENVIRONMENT_NAME))
  2775. {
  2776. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_SYSTEM_ENVIRONMENT,&lIndex);
  2777. }
  2778. else if(!_tcscmp(strName,SE_CHANGE_NOTIFY_NAME))
  2779. {
  2780. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_CHANGE_NOTIFY,&lIndex);
  2781. }
  2782. else if(!_tcscmp(strName,SE_REMOTE_SHUTDOWN_NAME))
  2783. {
  2784. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_REMOTE_SHUTDOWN,&lIndex);
  2785. }
  2786. else if(!_tcscmp(strName,SE_UNDOCK_NAME))
  2787. {
  2788. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_UNDOCK,&lIndex);
  2789. }
  2790. else if(!_tcscmp(strName,SE_SYNC_AGENT_NAME))
  2791. {
  2792. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_SYNC_AGENT,&lIndex);
  2793. }
  2794. else if(!_tcscmp(strName,SE_ENABLE_DELEGATION_NAME))
  2795. {
  2796. GetPropIndex(cProps,rgProp,DBPROP_WMIOLEDB_PREV_ENABLE_DELEGATION,&lIndex);
  2797. }
  2798. if(lIndex >= 0)
  2799. {
  2800. if(m_pPrevTokenPrev->Privileges[i].Attributes == SE_PRIVILEGE_ENABLED)
  2801. {
  2802. rgProp[lIndex].vValue.boolVal = VARIANT_TRUE;
  2803. }
  2804. else
  2805. {
  2806. rgProp[lIndex].vValue.boolVal = VARIANT_FALSE;
  2807. }
  2808. }
  2809. memset(strName,0,PRIVILEGE_NAMESIZE * sizeof(TCHAR));
  2810. } // for loop
  2811. }
  2812. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2813. // Function to get priveleges from the DBPROP structure
  2814. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2815. void CPreviligeToken::ConvertDBPropToPriveleges(ULONG cProps , DBPROP rgProp[])
  2816. {
  2817. LUID luid;
  2818. ULONG_PTR lPropValTemp = 1;
  2819. TCHAR * pName = NULL;
  2820. BOOL bPrivelege = TRUE;
  2821. m_pPrevTokenPrev->PrivilegeCount = 0;
  2822. for(ULONG i = 0 ; i < cProps && lPropValTemp != 0 ; i++)
  2823. {
  2824. bPrivelege = TRUE;
  2825. switch(rgProp[i].dwPropertyID)
  2826. {
  2827. case DBPROP_WMIOLEDB_PREV_CREATE_TOKEN :
  2828. pName = SE_CREATE_TOKEN_NAME;
  2829. break;
  2830. case DBPROP_WMIOLEDB_PREV_ASSIGNPRIMARYTOKEN:
  2831. pName = SE_ASSIGNPRIMARYTOKEN_NAME;
  2832. break;
  2833. case DBPROP_WMIOLEDB_PREV_LOCK_MEMORY :
  2834. pName = SE_LOCK_MEMORY_NAME;
  2835. break;
  2836. case DBPROP_WMIOLEDB_PREV_INCREASE_QUOTA:
  2837. pName = SE_INCREASE_QUOTA_NAME;
  2838. break;
  2839. case DBPROP_WMIOLEDB_PREV_MACHINE_ACCOUNT :
  2840. pName = SE_MACHINE_ACCOUNT_NAME;
  2841. break;
  2842. case DBPROP_WMIOLEDB_PREV_TCB :
  2843. pName = SE_TCB_NAME;
  2844. break;
  2845. case DBPROP_WMIOLEDB_PREV_SECURITY :
  2846. pName = SE_SECURITY_NAME;
  2847. break;
  2848. case DBPROP_WMIOLEDB_PREV_TAKE_OWNERSHIP:
  2849. pName = SE_TAKE_OWNERSHIP_NAME;
  2850. break;
  2851. case DBPROP_WMIOLEDB_PREV_LOAD_DRIVER:
  2852. pName = SE_LOAD_DRIVER_NAME;
  2853. break;
  2854. case DBPROP_WMIOLEDB_PREV_SYSTEM_PROFILE :
  2855. pName = SE_SYSTEM_PROFILE_NAME;
  2856. break;
  2857. case DBPROP_WMIOLEDB_PREV_SYSTEMTIME:
  2858. pName = SE_SYSTEMTIME_NAME;
  2859. break;
  2860. case DBPROP_WMIOLEDB_PREV_PROF_SINGLE_PROCESS:
  2861. pName = SE_PROF_SINGLE_PROCESS_NAME;
  2862. break;
  2863. case DBPROP_WMIOLEDB_PREV_INC_BASE_PRIORITY:
  2864. pName = SE_INC_BASE_PRIORITY_NAME;
  2865. break;
  2866. case DBPROP_WMIOLEDB_PREV_CREATE_PAGEFILE :
  2867. pName = SE_CREATE_PAGEFILE_NAME;
  2868. break;
  2869. case DBPROP_WMIOLEDB_PREV_CREATE_PERMANENT:
  2870. pName = SE_CREATE_PERMANENT_NAME;
  2871. break;
  2872. case DBPROP_WMIOLEDB_PREV_BACKUP:
  2873. pName = SE_BACKUP_NAME;
  2874. break;
  2875. case DBPROP_WMIOLEDB_PREV_RESTORE:
  2876. pName = SE_RESTORE_NAME;
  2877. break;
  2878. case DBPROP_WMIOLEDB_PREV_SHUTDOWN:
  2879. pName = SE_SHUTDOWN_NAME;
  2880. break;
  2881. case DBPROP_WMIOLEDB_PREV_DEBUG:
  2882. pName = SE_DEBUG_NAME;
  2883. break;
  2884. case DBPROP_WMIOLEDB_PREV_AUDIT:
  2885. pName = SE_AUDIT_NAME;
  2886. break;
  2887. case DBPROP_WMIOLEDB_PREV_SYSTEM_ENVIRONMENT:
  2888. pName = SE_SYSTEM_ENVIRONMENT_NAME;
  2889. break;
  2890. case DBPROP_WMIOLEDB_PREV_CHANGE_NOTIFY :
  2891. pName = SE_CHANGE_NOTIFY_NAME;
  2892. break;
  2893. case DBPROP_WMIOLEDB_PREV_REMOTE_SHUTDOWN :
  2894. pName = SE_REMOTE_SHUTDOWN_NAME;
  2895. break;
  2896. case DBPROP_WMIOLEDB_PREV_UNDOCK:
  2897. pName = SE_UNDOCK_NAME;
  2898. break;
  2899. case DBPROP_WMIOLEDB_PREV_SYNC_AGENT:
  2900. pName = SE_SYNC_AGENT_NAME;
  2901. break;
  2902. case DBPROP_WMIOLEDB_PREV_ENABLE_DELEGATION:
  2903. pName = SE_ENABLE_DELEGATION_NAME;
  2904. break;
  2905. default:
  2906. bPrivelege = FALSE;
  2907. }
  2908. if(bPrivelege)
  2909. {
  2910. LookupPrivilegeValue(NULL,pName,&luid);
  2911. m_pPrevTokenPrev->Privileges[m_pPrevTokenPrev->PrivilegeCount].Luid = luid;
  2912. //=============================================================================================
  2913. // Any setting other than SE_PRIVILEGE_ENABLED is interpreted by AdjustTokenPrivileges
  2914. // as a DISABLE request for the privelege
  2915. //=============================================================================================
  2916. m_pPrevTokenPrev->Privileges[m_pPrevTokenPrev->PrivilegeCount].Attributes = (rgProp[i].vValue.boolVal == VARIANT_TRUE)
  2917. ? SE_PRIVILEGE_ENABLED : SE_PRIVILEGE_ENABLED_BY_DEFAULT;
  2918. m_pPrevTokenPrev->PrivilegeCount++;
  2919. pName = NULL;
  2920. }
  2921. }
  2922. }
  2923. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2924. // Funciton to get the current privelege token
  2925. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2926. void CPreviligeToken::GetCurrentPrivelegeToken()
  2927. {
  2928. HANDLE hToken = NULL;
  2929. HANDLE hThread = NULL;
  2930. BOOL bRet = FALSE;
  2931. /*
  2932. hThread = GetCurrentProcess();
  2933. dwError = GetLastError();
  2934. hThread = GetCurrentThread();
  2935. if(OpenThreadToken(hThread,TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES,TRUE,&hToken))
  2936. // if(OpenProcessToken(hThread,TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,&hToken))
  2937. */
  2938. OpenToken(hToken);
  2939. if(hToken != NULL)
  2940. {
  2941. DWORD dwLen = m_nMemAllocated;
  2942. bRet = GetTokenInformation(hToken,
  2943. TokenPrivileges,
  2944. m_pPrevTokenPrev,
  2945. dwLen,
  2946. &dwLen);
  2947. CloseHandle(hToken);
  2948. }
  2949. // CloseHandle(hThread);
  2950. // dwError = GetLastError();
  2951. }
  2952. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2953. // Function to adjust the privileges
  2954. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2955. BOOL CPreviligeToken::AdjustTokenPrivileges(ULONG ulProperty)
  2956. {
  2957. BOOL bRet = FALSE;
  2958. HANDLE hToken = NULL;
  2959. DWORD dwError = 0;
  2960. ConvertDBPropToPriveleges(ulProperty);
  2961. /*
  2962. dwError = GetLastError();
  2963. // if(bRet = OpenThreadToken(GetCurrentThread(),TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES,FALSE,&hToken))
  2964. if(OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES,&hToken))
  2965. */
  2966. OpenToken(hToken);
  2967. if(hToken != NULL)
  2968. {
  2969. bRet = ::AdjustTokenPrivileges(hToken,
  2970. FALSE,
  2971. m_pPrevTokenPrev,
  2972. 0,
  2973. NULL,
  2974. NULL);
  2975. CloseHandle(hToken);
  2976. }
  2977. dwError = GetLastError();
  2978. return bRet;
  2979. }
  2980. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2981. // Function to Set the DBPROP structure accoriding to the current privileges
  2982. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2983. void CPreviligeToken::SetDBPROPForPrivileges(ULONG &ulProperty)
  2984. {
  2985. ULONG_PTR lPropValTemp = 1;
  2986. ULONG lSize = PRIVILEGE_NAMESIZE;
  2987. LONG lIndex = -1;
  2988. ULONG ulCurPrivilege = 0;
  2989. TCHAR strName[PRIVILEGE_NAMESIZE];
  2990. memset(strName,0,PRIVILEGE_NAMESIZE * sizeof(TCHAR));
  2991. ulProperty = 0;
  2992. for(ULONG_PTR i = 0 ; i < NUMBER_OF_PREVILAGE_PROPERTIES ; i++)
  2993. {
  2994. ulCurPrivilege = 0;
  2995. LookupPrivilegeName(NULL,&((m_pPrevTokenPrev->Privileges[i]).Luid) ,&strName[0],&lSize);
  2996. if(!_tcscmp(strName,SE_CREATE_TOKEN_NAME))
  2997. {
  2998. ulCurPrivilege = DBPROPVAL_CREATE_TOKEN;
  2999. }
  3000. else if(!_tcscmp(strName,SE_ASSIGNPRIMARYTOKEN_NAME))
  3001. {
  3002. ulCurPrivilege = DBPROPVAL_ASSIGNPRIMARYTOKEN;
  3003. }
  3004. else if(!_tcscmp(strName,SE_LOCK_MEMORY_NAME))
  3005. {
  3006. ulCurPrivilege = DBPROPVAL_LOCK_MEMORY;
  3007. }
  3008. else if(!_tcscmp(strName,SE_INCREASE_QUOTA_NAME))
  3009. {
  3010. ulCurPrivilege = DBPROPVAL_INCREASE_QUOTA;
  3011. }
  3012. else if(!_tcscmp(strName,SE_MACHINE_ACCOUNT_NAME))
  3013. {
  3014. ulCurPrivilege = DBPROPVAL_MACHINE_ACCOUNT;
  3015. }
  3016. else if(!_tcscmp(strName,SE_TCB_NAME))
  3017. {
  3018. ulCurPrivilege = DBPROPVAL_TCB;
  3019. }
  3020. else if(!_tcscmp(strName,SE_SECURITY_NAME))
  3021. {
  3022. ulCurPrivilege = DBPROPVAL_SECURITY;
  3023. }
  3024. else if(!_tcscmp(strName,SE_TAKE_OWNERSHIP_NAME))
  3025. {
  3026. ulCurPrivilege = DBPROPVAL_TAKE_OWNERSHIP;
  3027. }
  3028. else if(!_tcscmp(strName,SE_LOAD_DRIVER_NAME))
  3029. {
  3030. ulCurPrivilege = DBPROPVAL_LOAD_DRIVER;
  3031. }
  3032. else if(!_tcscmp(strName,SE_SYSTEM_PROFILE_NAME))
  3033. {
  3034. ulCurPrivilege = DBPROPVAL_SYSTEM_PROFILE;
  3035. }
  3036. else if(!_tcscmp(strName,SE_SYSTEMTIME_NAME))
  3037. {
  3038. ulCurPrivilege = DBPROPVAL_SYSTEMTIME;
  3039. }
  3040. else if(!_tcscmp(strName,SE_PROF_SINGLE_PROCESS_NAME))
  3041. {
  3042. ulCurPrivilege = DBPROPVAL_PROF_SINGLE_PROCESS;
  3043. }
  3044. else if(!_tcscmp(strName,SE_INC_BASE_PRIORITY_NAME))
  3045. {
  3046. ulCurPrivilege = DBPROPVAL_INC_BASE_PRIORITY;
  3047. }
  3048. else if(!_tcscmp(strName,SE_CREATE_PAGEFILE_NAME))
  3049. {
  3050. ulCurPrivilege = DBPROPVAL_CREATE_PAGEFILE;
  3051. }
  3052. else if(!_tcscmp(strName,SE_CREATE_PERMANENT_NAME))
  3053. {
  3054. ulCurPrivilege = DBPROPVAL_CREATE_PERMANENT;
  3055. }
  3056. else if(!_tcscmp(strName,SE_BACKUP_NAME))
  3057. {
  3058. ulCurPrivilege = DBPROPVAL_BACKUP;
  3059. }
  3060. else if(!_tcscmp(strName,SE_RESTORE_NAME))
  3061. {
  3062. ulCurPrivilege = DBPROPVAL_RESTORE;
  3063. }
  3064. else if(!_tcscmp(strName,SE_SHUTDOWN_NAME))
  3065. {
  3066. ulCurPrivilege = DBPROPVAL_SHUTDOWN;
  3067. }
  3068. else if(!_tcscmp(strName,SE_DEBUG_NAME))
  3069. {
  3070. ulCurPrivilege = DBPROPVAL_DEBUG;
  3071. }
  3072. else if(!_tcscmp(strName,SE_AUDIT_NAME))
  3073. {
  3074. ulCurPrivilege = DBPROPVAL_AUDIT;
  3075. }
  3076. else if(!_tcscmp(strName,SE_SYSTEM_ENVIRONMENT_NAME))
  3077. {
  3078. ulCurPrivilege = DBPROPVAL_SYSTEM_ENVIRONMENT;
  3079. }
  3080. else if(!_tcscmp(strName,SE_CHANGE_NOTIFY_NAME))
  3081. {
  3082. ulCurPrivilege = DBPROPVAL_CHANGE_NOTIFY;
  3083. }
  3084. else if(!_tcscmp(strName,SE_REMOTE_SHUTDOWN_NAME))
  3085. {
  3086. ulCurPrivilege = DBPROPVAL_REMOTE_SHUTDOWN;
  3087. }
  3088. else if(!_tcscmp(strName,SE_UNDOCK_NAME))
  3089. {
  3090. ulCurPrivilege = DBPROPVAL_UNDOCK;
  3091. }
  3092. else if(!_tcscmp(strName,SE_SYNC_AGENT_NAME))
  3093. {
  3094. ulCurPrivilege = DBPROPVAL_SYNC_AGENT;
  3095. }
  3096. else if(!_tcscmp(strName,SE_ENABLE_DELEGATION_NAME))
  3097. {
  3098. ulCurPrivilege = DBPROPVAL_ENABLE_DELEGATION;
  3099. }
  3100. if(ulCurPrivilege != 0)
  3101. {
  3102. if(m_pPrevTokenPrev->Privileges[i].Attributes == SE_PRIVILEGE_ENABLED)
  3103. {
  3104. ulProperty = ulProperty | ulCurPrivilege;
  3105. }
  3106. else
  3107. {
  3108. ulProperty = ulProperty | !(ulCurPrivilege);
  3109. }
  3110. }
  3111. memset(strName,0,PRIVILEGE_NAMESIZE * sizeof(TCHAR));
  3112. } // for loop
  3113. }
  3114. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  3115. // Function to get priveleges from the DBPROP structure
  3116. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  3117. void CPreviligeToken::ConvertDBPropToPriveleges(ULONG ulProperty)
  3118. {
  3119. LUID luid;
  3120. ULONG lPropValTemp = 1;
  3121. ULONG lProp = 0;
  3122. TCHAR * pName = NULL;
  3123. BOOL bPrivelege = TRUE;
  3124. m_pPrevTokenPrev->PrivilegeCount = 0;
  3125. for(ULONG i = 0 ; i < NUMBER_OF_PREVILAGE_PROPERTIES ; i++)
  3126. {
  3127. bPrivelege = TRUE;
  3128. switch(lPropValTemp)
  3129. {
  3130. case DBPROPVAL_CREATE_TOKEN :
  3131. pName = SE_CREATE_TOKEN_NAME;
  3132. break;
  3133. case DBPROPVAL_ASSIGNPRIMARYTOKEN:
  3134. pName = SE_ASSIGNPRIMARYTOKEN_NAME;
  3135. break;
  3136. case DBPROPVAL_LOCK_MEMORY :
  3137. pName = SE_LOCK_MEMORY_NAME;
  3138. break;
  3139. case DBPROPVAL_INCREASE_QUOTA:
  3140. pName = SE_INCREASE_QUOTA_NAME;
  3141. break;
  3142. case DBPROPVAL_MACHINE_ACCOUNT :
  3143. pName = SE_MACHINE_ACCOUNT_NAME;
  3144. break;
  3145. case DBPROPVAL_TCB :
  3146. pName = SE_TCB_NAME;
  3147. break;
  3148. case DBPROPVAL_SECURITY :
  3149. pName = SE_SECURITY_NAME;
  3150. break;
  3151. case DBPROPVAL_TAKE_OWNERSHIP:
  3152. pName = SE_TAKE_OWNERSHIP_NAME;
  3153. break;
  3154. case DBPROPVAL_LOAD_DRIVER:
  3155. pName = SE_LOAD_DRIVER_NAME;
  3156. break;
  3157. case DBPROPVAL_SYSTEM_PROFILE :
  3158. pName = SE_SYSTEM_PROFILE_NAME;
  3159. break;
  3160. case DBPROPVAL_SYSTEMTIME:
  3161. pName = SE_SYSTEMTIME_NAME;
  3162. break;
  3163. case DBPROPVAL_PROF_SINGLE_PROCESS:
  3164. pName = SE_PROF_SINGLE_PROCESS_NAME;
  3165. break;
  3166. case DBPROPVAL_INC_BASE_PRIORITY:
  3167. pName = SE_INC_BASE_PRIORITY_NAME;
  3168. break;
  3169. case DBPROPVAL_CREATE_PAGEFILE :
  3170. pName = SE_CREATE_PAGEFILE_NAME;
  3171. break;
  3172. case DBPROPVAL_CREATE_PERMANENT:
  3173. pName = SE_CREATE_PERMANENT_NAME;
  3174. break;
  3175. case DBPROPVAL_BACKUP:
  3176. pName = SE_BACKUP_NAME;
  3177. break;
  3178. case DBPROPVAL_RESTORE:
  3179. pName = SE_RESTORE_NAME;
  3180. break;
  3181. case DBPROPVAL_SHUTDOWN:
  3182. pName = SE_SHUTDOWN_NAME;
  3183. break;
  3184. case DBPROPVAL_DEBUG:
  3185. pName = SE_DEBUG_NAME;
  3186. break;
  3187. case DBPROPVAL_AUDIT:
  3188. pName = SE_AUDIT_NAME;
  3189. break;
  3190. case DBPROPVAL_SYSTEM_ENVIRONMENT:
  3191. pName = SE_SYSTEM_ENVIRONMENT_NAME;
  3192. break;
  3193. case DBPROPVAL_CHANGE_NOTIFY :
  3194. pName = SE_CHANGE_NOTIFY_NAME;
  3195. break;
  3196. case DBPROPVAL_REMOTE_SHUTDOWN :
  3197. pName = SE_REMOTE_SHUTDOWN_NAME;
  3198. break;
  3199. case DBPROPVAL_UNDOCK:
  3200. pName = SE_UNDOCK_NAME;
  3201. break;
  3202. case DBPROPVAL_SYNC_AGENT:
  3203. pName = SE_SYNC_AGENT_NAME;
  3204. break;
  3205. case DBPROPVAL_ENABLE_DELEGATION:
  3206. pName = SE_ENABLE_DELEGATION_NAME;
  3207. break;
  3208. default:
  3209. bPrivelege = FALSE;
  3210. }
  3211. if(bPrivelege)
  3212. {
  3213. LookupPrivilegeValue(NULL,pName,&luid);
  3214. m_pPrevTokenPrev->Privileges[m_pPrevTokenPrev->PrivilegeCount].Luid = luid;
  3215. //=============================================================================================
  3216. // Any setting other than SE_PRIVILEGE_ENABLED is interpreted by AdjustTokenPrivileges
  3217. // as a DISABLE request for the privelege
  3218. //=============================================================================================
  3219. m_pPrevTokenPrev->Privileges[m_pPrevTokenPrev->PrivilegeCount].Attributes = (ulProperty & lPropValTemp)
  3220. ? SE_PRIVILEGE_ENABLED : SE_PRIVILEGE_ENABLED_BY_DEFAULT;
  3221. m_pPrevTokenPrev->PrivilegeCount++;
  3222. pName = NULL;
  3223. lPropValTemp <<= 1;
  3224. }
  3225. }
  3226. }
  3227. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3228. // Function to get the index of a particular property in the array of properties
  3229. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3230. BOOL CPreviligeToken::GetPropIndex (ULONG cProps ,
  3231. DBPROP rgProp[],
  3232. DBPROPID dwPropertyID,
  3233. LONG* pulIndex)
  3234. {
  3235. ULONG cNumberOfProperties;
  3236. BOOL fRc = FALSE;
  3237. assert( pulIndex );
  3238. *pulIndex = -1;
  3239. for ( cNumberOfProperties = 0; cNumberOfProperties < cProps; cNumberOfProperties++) {
  3240. if (dwPropertyID == rgProp[cNumberOfProperties].dwPropertyID ) {
  3241. //==============================================================
  3242. // found a match
  3243. //==============================================================
  3244. *pulIndex = cNumberOfProperties;
  3245. fRc = TRUE;
  3246. break;
  3247. }
  3248. }
  3249. return fRc;
  3250. }
  3251. void CPreviligeToken::OpenToken(HANDLE &hToken)
  3252. {
  3253. HANDLE hObject = NULL;
  3254. DWORD dwError = 0;
  3255. BOOL bRet = FALSE;
  3256. hObject = GetCurrentThread();
  3257. if(!OpenThreadToken(hObject,TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES,TRUE,&hToken))
  3258. {
  3259. dwError = GetLastError();
  3260. }
  3261. if(dwError == ERROR_NO_TOKEN)
  3262. {
  3263. dwError = 0;
  3264. CloseHandle(hObject);
  3265. hObject = GetCurrentProcess();
  3266. if(!OpenProcessToken(hObject,TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,&hToken))
  3267. {
  3268. dwError = GetLastError();
  3269. }
  3270. }
  3271. CloseHandle(hObject);
  3272. if(!dwError)
  3273. {
  3274. DWORD dwLen = m_nMemAllocated;
  3275. bRet = GetTokenInformation(hToken,
  3276. TokenPrivileges,
  3277. m_pPrevTokenPrev,
  3278. dwLen,
  3279. &dwLen);
  3280. dwError = GetLastError();
  3281. }
  3282. }