Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afsadmsvr / TaAfsAdmSvrGroup.cpp
blobce44ba8f4a10b334b0a4178eadcd763ba0b8748f
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "TaAfsAdmSvrInternal.h"
22 * ROUTINES ___________________________________________________________________
27 // AfsAdmSvr_ChangeGroup
28 // ...changes a group account's properties.
30 extern "C" int AfsAdmSvr_ChangeGroup (UINT_PTR idClient, ASID idCell, ASID idGroup, LPAFSADMSVR_CHANGEGROUP_PARAMS pChange, ULONG *pStatus)
32 ASACTION Action;
33 Action.Action = ACTION_GROUP_CHANGE;
34 Action.idClient = idClient;
35 Action.idCell = idCell;
36 Action.u.Group_Change.idGroup = idGroup;
37 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
39 Print (dlDETAIL, TEXT("Client 0x%08lX: ChangeGroup (idGroup=0x%08lX)"), idClient, idGroup);
41 if (!AfsAdmSvr_fIsValidClient (idClient))
42 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
44 // Find this group's current properties
46 LPASOBJPROP pCurrentProperties;
47 if ((pCurrentProperties = AfsAdmSvr_GetCurrentProperties (idGroup, pStatus)) == NULL)
49 Print (dlERROR, TEXT("Client 0x%08lX: ChangeGroup failed; no properties"), idClient);
50 AfsAdmSvr_EndOperation (iOp);
51 return FALSE;
54 // Build an AFSCLASS-style GROUPPROPERTIES structure that reflects the
55 // new properties for the user; mark the structure's dwMask bit to indicate
56 // what we're changing.
58 GROUPPROPERTIES NewProperties;
59 memset (&NewProperties, 0x00, sizeof(NewProperties));
61 if (!pChange->szOwner[0])
62 lstrcpy (NewProperties.szOwner, pCurrentProperties->u.GroupProperties.szOwner);
63 else
65 lstrcpy (NewProperties.szOwner, pChange->szOwner);
66 if (lstrcmpi (NewProperties.szOwner, pCurrentProperties->u.GroupProperties.szOwner))
67 NewProperties.dwMask |= MASK_GROUPPROP_szOwner;
70 if ((NewProperties.aaListStatus = pChange->aaListStatus) != pCurrentProperties->u.GroupProperties.aaListStatus)
71 NewProperties.dwMask |= MASK_GROUPPROP_aaListStatus;
72 if ((NewProperties.aaListGroupsOwned = pChange->aaListGroupsOwned) != pCurrentProperties->u.GroupProperties.aaListGroupsOwned)
73 NewProperties.dwMask |= MASK_GROUPPROP_aaListGroupsOwned;
74 if ((NewProperties.aaListMembers = pChange->aaListMembers) != pCurrentProperties->u.GroupProperties.aaListMembers)
75 NewProperties.dwMask |= MASK_GROUPPROP_aaListMembers;
76 if ((NewProperties.aaAddMember = pChange->aaAddMember) != pCurrentProperties->u.GroupProperties.aaAddMember)
77 NewProperties.dwMask |= MASK_GROUPPROP_aaAddMember;
78 if ((NewProperties.aaDeleteMember = pChange->aaDeleteMember) != pCurrentProperties->u.GroupProperties.aaDeleteMember)
79 NewProperties.dwMask |= MASK_GROUPPROP_aaDeleteMember;
81 // If we've decided to change anything, call AfsClass to actually do it
83 if (NewProperties.dwMask == 0)
85 Print (dlDETAIL, TEXT("Client 0x%08lX: ChangeGroup succeeded (nothing to do)"), idClient);
87 else
89 ULONG status;
90 if (!AfsClass_SetGroupProperties ((LPIDENT)idGroup, &NewProperties, &status))
92 Print (dlERROR, TEXT("Client 0x%08lX: ChangeGroup failed; error 0x%08lX"), idClient, status);
93 return FALSE_(status,pStatus,iOp);
96 Print (dlDETAIL, TEXT("Client 0x%08lX: ChangeGroup succeeded"), idClient);
99 AfsAdmSvr_EndOperation (iOp);
100 return TRUE;
104 // AfsAdmSvr_GetGroupMembers
105 // ...retrieves the list of users which belong to a group
107 extern "C" int AfsAdmSvr_GetGroupMembers (UINT_PTR idClient, ASID idCell, ASID idGroup, LPASIDLIST *ppAsidList, ULONG *pStatus)
109 size_t iOp = AfsAdmSvr_BeginOperation (idClient);
111 Print (dlDETAIL, TEXT("Client 0x%08lX: GetGroupMembers (idGroup=0x%08lX)"), idClient, idGroup);
113 if (!AfsAdmSvr_fIsValidClient (idClient))
114 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
116 // Use AfsClass to get the list of group members
118 if (GetAsidType (idGroup) != itGROUP)
119 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
121 ULONG status;
122 LPPTSGROUP lpGroup;
123 if ((lpGroup = ((LPIDENT)idGroup)->OpenGroup (&status)) == NULL)
124 return FALSE_(status,pStatus,iOp);
126 LPTSTR pmszUsers = NULL;
127 lpGroup->GetMembers (&pmszUsers);
128 lpGroup->Close();
130 // Then translate those user names into an ASID list
132 if ((*ppAsidList = AfsAdmSvr_CreateAsidList()) == NULL)
134 if (pmszUsers)
135 FreeString (pmszUsers);
136 return FALSE_(ERROR_NOT_ENOUGH_MEMORY,pStatus,iOp);
139 if (pmszUsers)
141 for (LPTSTR psz = pmszUsers; psz && *psz; psz += 1+lstrlen(psz))
143 LPIDENT lpi;
144 if ((lpi = IDENT::FindGroup ((LPIDENT)idCell, psz)) == NULL)
146 TCHAR szName[ cchNAME ];
147 TCHAR szInstance[ cchNAME ];
148 USER::SplitUserName (psz, szName, szInstance);
150 if ((lpi = IDENT::FindUser ((LPIDENT)idCell, szName, szInstance)) == NULL)
152 continue;
156 AfsAdmSvr_AddToAsidList (ppAsidList, (ASID)lpi, 0);
158 FreeString (pmszUsers);
161 Print (dlDETAIL, TEXT("Client 0x%08lX: GetGroupMembers succeeded"), idClient);
162 AfsAdmSvr_EndOperation (iOp);
163 return TRUE;
167 // AfsAdmSvr_GetGroupMembership
168 // ...retrieves the list of groups to which a user or group belongs
170 extern "C" int AfsAdmSvr_GetGroupMembership (UINT_PTR idClient, ASID idCell, ASID idMember, LPASIDLIST *ppAsidList, ULONG *pStatus)
172 size_t iOp = AfsAdmSvr_BeginOperation (idClient);
174 Print (dlDETAIL, TEXT("Client 0x%08lX: GetGroupMembership (idMember=0x%08lX)"), idClient, idMember);
176 if (!AfsAdmSvr_fIsValidClient (idClient))
177 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
179 // Use AfsClass to get the appropriate list of groups
181 ULONG status;
182 LPTSTR pmszGroups = NULL;
184 if (GetAsidType (idMember) == itUSER)
186 LPUSER lpUser;
187 if ((lpUser = ((LPIDENT)idMember)->OpenUser (&status)) == NULL)
188 return FALSE_(status,pStatus,iOp);
189 lpUser->GetMemberOf (&pmszGroups);
190 lpUser->Close();
192 else if (GetAsidType (idMember) == itGROUP)
194 LPPTSGROUP lpGroup;
195 if ((lpGroup = ((LPIDENT)idMember)->OpenGroup (&status)) == NULL)
196 return FALSE_(status,pStatus,iOp);
197 lpGroup->GetMemberOf (&pmszGroups);
198 lpGroup->Close();
200 else // bogus type
202 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
205 // Then translate those group names into an ASID list
207 if ((*ppAsidList = AfsAdmSvr_CreateAsidList()) == NULL)
209 if (pmszGroups)
210 FreeString (pmszGroups);
211 return FALSE_(ERROR_NOT_ENOUGH_MEMORY,pStatus,iOp);
214 if (pmszGroups)
216 for (LPTSTR psz = pmszGroups; psz && *psz; psz += 1+lstrlen(psz))
218 LPIDENT lpi;
219 if ((lpi = IDENT::FindGroup ((LPIDENT)idCell, psz)) == NULL)
220 continue;
221 AfsAdmSvr_AddToAsidList (ppAsidList, (ASID)lpi, 0);
223 FreeString (pmszGroups);
226 Print (dlDETAIL, TEXT("Client 0x%08lX: GetGroupMembership succeeded"), idClient);
227 AfsAdmSvr_EndOperation (iOp);
228 return TRUE;
232 // AfsAdmSvr_GetGroupOwnership
233 // ...retrieves the list of groups which a user owns
235 extern "C" int AfsAdmSvr_GetGroupOwnership (UINT_PTR idClient, ASID idCell, ASID idOwner, LPASIDLIST *ppAsidList, ULONG *pStatus)
237 size_t iOp = AfsAdmSvr_BeginOperation (idClient);
239 Print (dlDETAIL, TEXT("Client 0x%08lX: GetGroupOwnership (idOwner=0x%08lX)"), idClient, idOwner);
241 if (!AfsAdmSvr_fIsValidClient (idClient))
242 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
244 // Use AfsClass to get the appropriate list of groups
246 ULONG status;
247 LPTSTR pmszGroups = NULL;
249 if (GetAsidType (idOwner) == itUSER)
251 LPUSER lpUser;
252 if ((lpUser = ((LPIDENT)idOwner)->OpenUser (&status)) == NULL)
253 return FALSE_(status,pStatus,iOp);
254 lpUser->GetOwnerOf (&pmszGroups);
255 lpUser->Close();
257 else if (GetAsidType (idOwner) == itGROUP)
259 LPPTSGROUP lpGroup;
260 if ((lpGroup = ((LPIDENT)idOwner)->OpenGroup (&status)) == NULL)
261 return FALSE_(status,pStatus,iOp);
262 lpGroup->GetOwnerOf (&pmszGroups);
263 lpGroup->Close();
265 else // bogus type
267 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
270 // Then translate those group names into an ASID list
272 if ((*ppAsidList = AfsAdmSvr_CreateAsidList()) == NULL)
274 if (pmszGroups)
275 FreeString (pmszGroups);
276 return FALSE_(ERROR_NOT_ENOUGH_MEMORY,pStatus,iOp);
279 if (pmszGroups)
281 for (LPTSTR psz = pmszGroups; psz && *psz; psz += 1+lstrlen(psz))
283 LPIDENT lpi;
284 if ((lpi = IDENT::FindGroup ((LPIDENT)idCell, psz)) == NULL)
285 continue;
286 AfsAdmSvr_AddToAsidList (ppAsidList, (ASID)lpi, 0);
288 FreeString (pmszGroups);
291 Print (dlDETAIL, TEXT("Client 0x%08lX: GetGroupOwnership succeeded"), idClient);
292 AfsAdmSvr_EndOperation (iOp);
293 return TRUE;
297 // AfsAdmSvr_AddGroupMember
298 // ...adds a member to the specified group
300 extern "C" int AfsAdmSvr_AddGroupMember (UINT_PTR idClient, ASID idCell, ASID idGroup, ASID idMember, ULONG *pStatus)
302 ASACTION Action;
303 Action.Action = ACTION_GROUP_MEMBER_ADD;
304 Action.idClient = idClient;
305 Action.idCell = idCell;
306 Action.u.Group_Member_Add.idGroup = idGroup;
307 Action.u.Group_Member_Add.idUser = idMember;
308 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
310 Print (dlDETAIL, TEXT("Client 0x%08lX: AddGroupMember (idGroup=0x%08lX, idUser=0x%08lX)"), idClient, idGroup, idMember);
312 if (!AfsAdmSvr_fIsValidClient (idClient))
313 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
315 // Modify the group as requested
317 ULONG status;
318 if (!AfsClass_AddUserToGroup ((LPIDENT)idGroup, (LPIDENT)idMember, &status))
319 return FALSE_(status,pStatus,iOp);
321 Print (dlDETAIL, TEXT("Client 0x%08lX: AddGroupMember succeeded"), idClient);
322 AfsAdmSvr_EndOperation (iOp);
323 return TRUE;
327 // AfsAdmSvr_RemoveGroupMember
328 // ...removes a member from the specified group
330 extern "C" int AfsAdmSvr_RemoveGroupMember (UINT_PTR idClient, ASID idCell, ASID idGroup, ASID idMember, ULONG *pStatus)
332 ASACTION Action;
333 Action.Action = ACTION_GROUP_MEMBER_REMOVE;
334 Action.idClient = idClient;
335 Action.idCell = idCell;
336 Action.u.Group_Member_Remove.idGroup = idGroup;
337 Action.u.Group_Member_Remove.idUser = idMember;
338 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
340 Print (dlDETAIL, TEXT("Client 0x%08lX: RemoveGroupMember (idGroup=0x%08lX, idUser=0x%08lX)"), idClient, idGroup, idMember);
342 if (!AfsAdmSvr_fIsValidClient (idClient))
343 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
345 // Modify the group as requested
347 ULONG status;
348 if (!AfsClass_RemoveUserFromGroup ((LPIDENT)idGroup, (LPIDENT)idMember, &status))
349 return FALSE_(status,pStatus,iOp);
351 Print (dlDETAIL, TEXT("Client 0x%08lX: RemoveGroupMember succeeded"), idClient);
352 AfsAdmSvr_EndOperation (iOp);
353 return TRUE;
357 // AfsAdmSvr_RenameGroup
358 // ...changes a group's name
360 extern "C" int AfsAdmSvr_RenameGroup (UINT_PTR idClient, ASID idCell, ASID idGroup, STRING szNewGroupName, ULONG *pStatus)
362 ASACTION Action;
363 Action.Action = ACTION_GROUP_RENAME;
364 Action.idClient = idClient;
365 Action.idCell = idCell;
366 Action.u.Group_Rename.idGroup = idGroup;
367 lstrcpy (Action.u.Group_Rename.szNewName, szNewGroupName);
368 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
370 Print (dlDETAIL, TEXT("Client 0x%08lX: RenameGroup (idGroup=0x%08lX, szNewName=%s)"), idClient, idGroup, szNewGroupName);
372 if (!AfsAdmSvr_fIsValidClient (idClient))
373 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
375 // Modify the group as requested
377 ULONG status;
378 if (!AfsClass_RenameGroup ((LPIDENT)idGroup, szNewGroupName, &status))
379 return FALSE_(status,pStatus,iOp);
381 Print (dlDETAIL, TEXT("Client 0x%08lX: RenameGroup succeeded"), idClient);
382 AfsAdmSvr_EndOperation (iOp);
383 return TRUE;
387 // AfsAdmSvr_CreateGroup
388 // ...creates a new PTS group
390 extern "C" int AfsAdmSvr_CreateGroup (UINT_PTR idClient, ASID idCell, LPAFSADMSVR_CREATEGROUP_PARAMS pCreate, ASID *pidGroup, ULONG *pStatus)
392 ASACTION Action;
393 Action.Action = ACTION_GROUP_CREATE;
394 Action.idClient = idClient;
395 Action.idCell = idCell;
396 lstrcpy (Action.u.Group_Create.szGroup, pCreate->szName);
397 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
399 Print (dlDETAIL, TEXT("Client 0x%08lX: CreateGroup (szGroup=%s)"), idClient, pCreate->szName);
401 if (!AfsAdmSvr_fIsValidClient (idClient))
402 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
404 // Find the owner (if we can)
406 LPIDENT lpiOwner;
407 if ((lpiOwner = IDENT::FindUser ((LPIDENT)idCell, pCreate->szOwner)) == NULL)
408 lpiOwner = IDENT::FindGroup ((LPIDENT)idCell, pCreate->szOwner);
410 // Create the group account
412 ULONG status;
413 LPIDENT lpiGroup;
414 if ((lpiGroup = AfsClass_CreateGroup ((LPIDENT)idCell, pCreate->szName, lpiOwner, pCreate->idGroup, &status)) == NULL)
416 Print (dlERROR, TEXT("Client 0x%08lX: CreateGroup failed; error 0x%08lX"), idClient, status);
417 return FALSE_(status,pStatus,iOp);
420 if (pidGroup)
421 *pidGroup = (ASID)lpiGroup;
423 // Creating a group account may change the max group ID
424 AfsAdmSvr_TestProperties (idCell);
426 Print (dlDETAIL, TEXT("Client 0x%08lX: CreateGroup succeeded"), idClient);
427 AfsAdmSvr_EndOperation (iOp);
428 return TRUE;
432 // AfsAdmSvr_DeleteGroup
433 // ...deletes a PTS group
435 extern "C" int AfsAdmSvr_DeleteGroup (UINT_PTR idClient, ASID idCell, ASID idGroup, ULONG *pStatus)
437 ASACTION Action;
438 Action.Action = ACTION_GROUP_DELETE;
439 Action.idClient = idClient;
440 Action.idCell = idCell;
441 Action.u.Group_Delete.idGroup = idGroup;
442 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
444 Print (dlDETAIL, TEXT("Client 0x%08lX: DeleteGroup (idGroup=0x%08lX)"), idClient, idGroup);
446 if (!AfsAdmSvr_fIsValidClient (idClient))
447 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
449 // Delete the group
451 ULONG status;
452 if (!AfsClass_DeleteGroup ((LPIDENT)idGroup, &status))
454 Print (dlERROR, TEXT("Client 0x%08lX: DeleteGroup failed; error 0x%08lX"), idClient, status);
455 return FALSE_(status,pStatus,iOp);
458 Print (dlDETAIL, TEXT("Client 0x%08lX: DeleteGroup succeeded"), idClient);
459 AfsAdmSvr_EndOperation (iOp);
460 return TRUE;