5ef20143d3886d2b49107f89f07ddf23898a1237
[public/netxms.git] / src / server / include / nms_users.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** $module: nms_users.h
20 **
21 **/
22
23 #ifndef _nms_users_h_
24 #define _nms_users_h_
25
26
27 //
28 // Maximum number of grace logins allowed for user
29 //
30
31 #define MAX_GRACE_LOGINS 5
32
33
34 //
35 // User structure
36 //
37
38 typedef struct
39 {
40 DWORD dwId;
41 char szName[MAX_USER_NAME];
42 BYTE szPassword[SHA1_DIGEST_SIZE];
43 WORD wSystemRights; // System-wide user's rights
44 WORD wFlags;
45 char szFullName[MAX_USER_FULLNAME];
46 char szDescription[MAX_USER_DESCR];
47 int nGraceLogins;
48 } NMS_USER;
49
50
51 //
52 // Group structure
53 //
54
55 typedef struct
56 {
57 DWORD dwId;
58 char szName[MAX_USER_NAME];
59 WORD wSystemRights;
60 WORD wFlags;
61 DWORD dwNumMembers;
62 DWORD *pMembers;
63 char szDescription[MAX_USER_DESCR];
64 } NMS_USER_GROUP;
65
66
67 //
68 // Access list element structure
69 //
70
71 typedef struct
72 {
73 DWORD dwUserId;
74 DWORD dwAccessRights;
75 } ACL_ELEMENT;
76
77
78 //
79 // Access list class
80 //
81
82 class AccessList
83 {
84 private:
85 DWORD m_dwNumElements;
86 ACL_ELEMENT *m_pElements;
87 MUTEX m_hMutex;
88
89 void Lock(void) { MutexLock(m_hMutex, INFINITE); }
90 void Unlock(void) { MutexUnlock(m_hMutex); }
91
92 public:
93 AccessList();
94 ~AccessList();
95
96 BOOL GetUserRights(DWORD dwUserId, DWORD *pdwAccessRights);
97 void AddElement(DWORD dwUserId, DWORD dwAccessRights);
98 BOOL DeleteElement(DWORD dwUserId);
99 void DeleteAll(void);
100
101 void EnumerateElements(void (* pHandler)(DWORD, DWORD, void *), void *pArg);
102
103 void CreateMessage(CSCPMessage *pMsg);
104 };
105
106
107 //
108 // Functions
109 //
110
111 BOOL LoadUsers(void);
112 void SaveUsers(DB_HANDLE hdb);
113 void AddUserToGroup(DWORD dwUserId, DWORD dwGroupId);
114 BOOL CheckUserMembership(DWORD dwUserId, DWORD dwGroupId);
115 DWORD AuthenticateUser(char *szName, BYTE *szPassword, DWORD *pdwId,
116 DWORD *pdwSystemRights, BOOL *pbChangePasswd);
117 void DumpUsers(CONSOLE_CTX pCtx);
118 DWORD CreateNewUser(char *pszName, BOOL bIsGroup, DWORD *pdwId);
119 DWORD DeleteUserFromDB(DWORD dwId);
120 DWORD ModifyUser(NMS_USER *pUserInfo);
121 DWORD ModifyGroup(NMS_USER_GROUP *pGroupInfo);
122 DWORD SetUserPassword(DWORD dwId, BYTE *pszPassword, BOOL bResetChPasswd);
123 void SendUserDBUpdate(int iCode, DWORD dwUserId, NMS_USER *pUser, NMS_USER_GROUP *pUserGroup);
124
125
126 //
127 // Global variables
128 //
129
130 extern NMS_USER *g_pUserList;
131 extern DWORD g_dwNumUsers;
132 extern NMS_USER_GROUP *g_pGroupList;
133 extern DWORD g_dwNumGroups;
134
135 #endif