netman.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* --- BEGIN COPYRIGHT BLOCK ---
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2005 Red Hat, Inc.
  35. * All rights reserved.
  36. * --- END COPYRIGHT BLOCK --- */
  37. // ****************************************************************
  38. // netman.h
  39. // ****************************************************************
  40. #include <windows.h>
  41. #include <lm.h>
  42. #include <stdio.h>
  43. #define USER_INFO_LEVEL 3
  44. #define USER_GROUPS_INFO_LEVEL 0
  45. #define USER_LOCALGROUPS_INFO_LEVEL 0
  46. #define GROUP_INFO_LEVEL 2
  47. #define GROUP_USERS_INFO_LEVEL 0
  48. #define LOCALGROUP_INFO_LEVEL 1
  49. #define LOCALGROUP_USERS_INFO_LEVEL 0
  50. #define NETMAN_BUF_LEN 256
  51. // ****************************************************************
  52. // NTUser
  53. // ****************************************************************
  54. class NTUser
  55. {
  56. public:
  57. NTUser();
  58. ~NTUser();
  59. void NewUser(char* username);
  60. int RetriveUserByAccountName(char* username);
  61. int RetriveUserBySIDHexStr(char* sidHexStr);
  62. int StoreUser();
  63. int AddUser();
  64. int DeleteUser(char* username);
  65. int ChangeUsername(char* oldUsername, char* newUsername);
  66. char* GetAccountName();
  67. char* GetSIDHexStr();
  68. unsigned long GetAccountExpires();
  69. int SetAccountExpires(unsigned long accountExpires);
  70. unsigned long GetBadPasswordCount();
  71. unsigned long GetCodePage();
  72. int SetCodePage(unsigned long codePage);
  73. char* GetComment();
  74. int SetComment(char* comment);
  75. unsigned long GetCountryCode();
  76. int SetCountryCode(unsigned long countryCode);
  77. unsigned long GetFlags();
  78. int SetFlags(unsigned long flags);
  79. char* GetHomeDir();
  80. int SetHomeDir(char* path);
  81. char* GetHomeDirDrive();
  82. int SetHomeDirDrive(char* path);
  83. unsigned long GetLastLogoff();
  84. unsigned long GetLastLogon();
  85. char* GetLogonHours();
  86. int SetLogonHours(char* logonHours);
  87. unsigned long GetMaxStorage();
  88. int SetMaxStorage(unsigned long maxStorage);
  89. unsigned long GetNumLogons();
  90. char* GetProfile();
  91. int SetProfile(char* path);
  92. char* GetScriptPath();
  93. int SetScriptPath(char* path);
  94. char* GetWorkstations();
  95. int SetWorkstations(char* workstations);
  96. char* GetFullname();
  97. int SetFullname(char* fullname);
  98. int SetPassword(char* password);
  99. int AddToGroup(char* groupName);
  100. int RemoveFromGroup(char* groupName);
  101. int LoadGroups();
  102. bool HasMoreGroups();
  103. char* NextGroupName();
  104. int AddToLocalGroup(char* localGroupName);
  105. int RemoveFromLocalGroup(char* localGroupName);
  106. int LoadLocalGroups();
  107. bool HasMoreLocalGroups();
  108. char* NextLocalGroupName();
  109. private:
  110. USER_INFO_3* userInfo;
  111. GROUP_USERS_INFO_0* groupsInfo;
  112. DWORD currentGroupEntry;
  113. DWORD groupEntriesRead;
  114. DWORD groupEntriesTotal;
  115. LOCALGROUP_USERS_INFO_0* localGroupsInfo;
  116. DWORD currentLocalGroupEntry;
  117. DWORD localGroupEntriesRead;
  118. DWORD localGroupEntriesTotal;
  119. };
  120. // ****************************************************************
  121. // NTUserList
  122. // ****************************************************************
  123. class NTUserList
  124. {
  125. public:
  126. NTUserList();
  127. ~NTUserList();
  128. int loadList();
  129. bool hasMore();
  130. char* nextUsername();
  131. private:
  132. USER_INFO_3* bufptr;
  133. DWORD entriesRead;
  134. DWORD totalEntries;
  135. DWORD resumeHandle;
  136. DWORD currentEntry;
  137. };
  138. // ****************************************************************
  139. // NTGroup
  140. // ****************************************************************
  141. class NTGroup
  142. {
  143. public:
  144. NTGroup();
  145. ~NTGroup();
  146. void NewGroup(char* groupName);
  147. int DeleteGroup(char* groupName);
  148. int RetriveGroupByAccountName(char* groupName);
  149. int RetriveGroupBySIDHexStr(char* sidHexStr);
  150. int AddGroup();
  151. int StoreGroup();
  152. char* GetAccountName();
  153. char* GetSIDHexStr();
  154. int AddUser(char* username);
  155. int RemoveUser(char* username);
  156. int LoadUsers();
  157. bool HasMoreUsers();
  158. char* NextUserName();
  159. private:
  160. GROUP_INFO_2* groupInfo;
  161. LOCALGROUP_USERS_INFO_0* usersInfo;
  162. DWORD currentUserEntry;
  163. DWORD userEntriesRead;
  164. DWORD userEntriesTotal;
  165. };
  166. // ****************************************************************
  167. // NTGroupList
  168. // ****************************************************************
  169. class NTGroupList
  170. {
  171. public:
  172. NTGroupList();
  173. ~NTGroupList();
  174. int loadList();
  175. bool hasMore();
  176. char* nextGroupName();
  177. private:
  178. GROUP_INFO_2* bufptr;
  179. DWORD entriesRead;
  180. DWORD totalEntries;
  181. DWORD resumeHandle;
  182. DWORD currentEntry;
  183. };
  184. // ****************************************************************
  185. // NTLocalGroup
  186. // ****************************************************************
  187. class NTLocalGroup
  188. {
  189. public:
  190. NTLocalGroup();
  191. ~NTLocalGroup();
  192. void NewLocalGroup(char* localGroupName);
  193. int DeleteLocalGroup(char* localGroupName);
  194. int RetriveLocalGroupByAccountName(char* localGroupName);
  195. int RetriveLocalGroupBySIDHexStr(char* sidHexStr);
  196. int AddLocalGroup();
  197. int StoreLocalGroup();
  198. char* GetAccountName();
  199. char* GetSIDHexStr();
  200. int AddUser(char* username);
  201. int RemoveUser(char* username);
  202. int LoadUsers();
  203. bool HasMoreUsers();
  204. char* NextUserName();
  205. private:
  206. LOCALGROUP_INFO_1* localGroupInfo;
  207. LOCALGROUP_MEMBERS_INFO_0* usersInfo;
  208. DWORD currentUserEntry;
  209. DWORD userEntriesRead;
  210. DWORD userEntriesTotal;
  211. };
  212. // ****************************************************************
  213. // NTLocalGroupList
  214. // ****************************************************************
  215. class NTLocalGroupList
  216. {
  217. public:
  218. NTLocalGroupList();
  219. ~NTLocalGroupList();
  220. int loadList();
  221. bool hasMore();
  222. char* nextLocalGroupName();
  223. private:
  224. LOCALGROUP_INFO_1* bufptr;
  225. DWORD entriesRead;
  226. DWORD totalEntries;
  227. DWORD resumeHandle;
  228. DWORD currentEntry;
  229. };