Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afsadmsvr / TaAfsAdmSvrUser.cpp
blob15b16fdce6a70848f3779cb549fe287c534ec87c
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_ChangeUser
28 // ...changes a user account's properties.
30 extern "C" int AfsAdmSvr_ChangeUser (UINT_PTR idClient, ASID idCell, ASID idUser, LPAFSADMSVR_CHANGEUSER_PARAMS pChange, ULONG *pStatus)
32 ASACTION Action;
33 Action.Action = ACTION_USER_CHANGE;
34 Action.idClient = idClient;
35 Action.idCell = idCell;
36 Action.u.User_Change.idUser = idUser;
37 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
39 Print (dlDETAIL, TEXT("Client 0x%08lX: ChangeUser (idUser=0x%08lX)"), idClient, idUser);
41 if (!AfsAdmSvr_fIsValidClient (idClient))
42 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
44 // Find this user's current properties
46 LPASOBJPROP pCurrentProperties;
47 if ((pCurrentProperties = AfsAdmSvr_GetCurrentProperties (idUser, pStatus)) == NULL)
49 Print (dlERROR, TEXT("Client 0x%08lX: ChangeUser failed; no properties"), idClient);
50 AfsAdmSvr_EndOperation (iOp);
51 return FALSE;
54 // Build an AFSCLASS-style USERPROPERTIES structure that reflects the
55 // new properties for the user; mark the structure's dwMask bit to indicate
56 // what we're changing.
58 USERPROPERTIES NewProperties;
59 memset (&NewProperties, 0x00, sizeof(NewProperties));
61 if ((NewProperties.fAdmin = pChange->fIsAdmin) != pCurrentProperties->u.UserProperties.KASINFO.fIsAdmin)
62 NewProperties.dwMask |= MASK_USERPROP_fAdmin;
63 if ((NewProperties.fGrantTickets = pChange->fCanGetTickets) != pCurrentProperties->u.UserProperties.KASINFO.fCanGetTickets)
64 NewProperties.dwMask |= MASK_USERPROP_fGrantTickets;
65 if ((NewProperties.fCanEncrypt = pChange->fEncrypt) != pCurrentProperties->u.UserProperties.KASINFO.fEncrypt)
66 NewProperties.dwMask |= MASK_USERPROP_fCanEncrypt;
67 if ((NewProperties.fCanChangePassword = pChange->fCanChangePassword) != pCurrentProperties->u.UserProperties.KASINFO.fCanChangePassword)
68 NewProperties.dwMask |= MASK_USERPROP_fCanChangePassword;
69 if ((NewProperties.fCanReusePasswords = pChange->fCanReusePasswords) != pCurrentProperties->u.UserProperties.KASINFO.fCanReusePasswords)
70 NewProperties.dwMask |= MASK_USERPROP_fCanReusePasswords;
71 if ((NewProperties.cdayPwExpires = pChange->cdayPwExpire) != pCurrentProperties->u.UserProperties.KASINFO.cdayPwExpire)
72 NewProperties.dwMask |= MASK_USERPROP_cdayPwExpires;
73 if ((NewProperties.csecTicketLifetime = pChange->csecTicketLifetime) != pCurrentProperties->u.UserProperties.KASINFO.csecTicketLifetime)
74 NewProperties.dwMask |= MASK_USERPROP_csecTicketLifetime;
75 if ((NewProperties.nFailureAttempts = pChange->cFailLogin) != pCurrentProperties->u.UserProperties.KASINFO.cFailLogin)
76 NewProperties.dwMask |= MASK_USERPROP_nFailureAttempts;
77 if ((NewProperties.csecFailedLoginLockTime = pChange->csecFailLoginLock) != pCurrentProperties->u.UserProperties.KASINFO.csecFailLoginLock)
78 NewProperties.dwMask |= MASK_USERPROP_csecFailedLoginLockTime;
79 if ((NewProperties.cGroupCreationQuota = pChange->cgroupCreationQuota) != pCurrentProperties->u.UserProperties.PTSINFO.cgroupCreationQuota)
80 NewProperties.dwMask |= MASK_USERPROP_cGroupCreationQuota;
81 if ((NewProperties.aaListStatus = pChange->aaListStatus) != pCurrentProperties->u.UserProperties.PTSINFO.aaListStatus)
82 NewProperties.dwMask |= MASK_USERPROP_aaListStatus;
83 if ((NewProperties.aaGroupsOwned = pChange->aaGroupsOwned) != pCurrentProperties->u.UserProperties.PTSINFO.aaGroupsOwned)
84 NewProperties.dwMask |= MASK_USERPROP_aaGroupsOwned;
85 if ((NewProperties.aaMembership = pChange->aaMembership) != pCurrentProperties->u.UserProperties.PTSINFO.aaMembership)
86 NewProperties.dwMask |= MASK_USERPROP_aaMembership;
87 memcpy (&NewProperties.timeAccountExpires, &pChange->timeExpires, sizeof(SYSTEMTIME));
88 if (memcmp (&NewProperties.timeAccountExpires, &pCurrentProperties->u.UserProperties.KASINFO.timeExpires, sizeof(SYSTEMTIME)))
89 NewProperties.dwMask |= MASK_USERPROP_timeAccountExpires;
91 // If we've decided to change anything, call AfsClass to actually do it
93 if (NewProperties.dwMask == 0)
95 Print (dlDETAIL, TEXT("Client 0x%08lX: ChangeUser succeeded (nothing to do)"), idClient);
97 else
99 ULONG status;
100 if (!AfsClass_SetUserProperties ((LPIDENT)idUser, &NewProperties, &status))
102 Print (dlERROR, TEXT("Client 0x%08lX: ChangeUser failed; error 0x%08lX"), idClient, status);
103 return FALSE_(status,pStatus,iOp);
106 Print (dlDETAIL, TEXT("Client 0x%08lX: ChangeUser succeeded"), idClient);
109 AfsAdmSvr_EndOperation (iOp);
110 return TRUE;
114 // AfsAdmSvr_SetUserPassword
115 // ...changes the password for the specified user account. Pass a non-empty
116 // string in {keyString} to encrypt the specified string; otherwise,
117 // pass a valid encryption key in {keyData}.
119 extern "C" int AfsAdmSvr_SetUserPassword (UINT_PTR idClient, ASID idCell, ASID idUser, int keyVersion, STRING keyString, BYTE keyData[ ENCRYPTIONKEYLENGTH ], ULONG *pStatus)
121 BOOL rc = TRUE;
122 ULONG status = 0;
124 ASACTION Action;
125 Action.Action = ACTION_USER_PW_CHANGE;
126 Action.idClient = idClient;
127 Action.idCell = idCell;
128 Action.u.User_Pw_Change.idUser = idUser;
129 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
131 Print (dlDETAIL, TEXT("Client 0x%08lX: SetUserPassword (idUser=0x%08lX)"), idClient, idUser);
133 if (!AfsAdmSvr_fIsValidClient (idClient))
134 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
136 // Change the user's password
138 if (keyString && keyString[0])
140 rc = AfsClass_SetUserPassword ((LPIDENT)idUser, keyVersion, keyString, &status);
142 else // (!keyString || !keyString[0])
144 rc = AfsClass_SetUserPassword ((LPIDENT)idUser, keyVersion, (LPENCRYPTIONKEY)keyData, &status);
147 if (!rc)
148 return FALSE_(status,pStatus,iOp);
150 Print (dlDETAIL, TEXT("Client 0x%08lX: SetUserPassword succeeded"), idClient);
151 AfsAdmSvr_EndOperation (iOp);
152 return TRUE;
156 // AfsAdmSvr_UnlockUser
157 // ...unlocks a user's account
159 extern "C" int AfsAdmSvr_UnlockUser (UINT_PTR idClient, ASID idCell, ASID idUser, ULONG *pStatus)
161 ASACTION Action;
162 Action.Action = ACTION_USER_UNLOCK;
163 Action.idClient = idClient;
164 Action.idCell = idCell;
165 Action.u.User_Unlock.idUser = idUser;
166 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
168 Print (dlDETAIL, TEXT("Client 0x%08lX: UnlockUser (idUser=0x%08lX)"), idClient, idUser);
170 if (!AfsAdmSvr_fIsValidClient (idClient))
171 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
173 // Unlock the user's account
175 ULONG status;
176 if (!AfsClass_UnlockUser ((LPIDENT)idUser, &status))
177 return FALSE_(status,pStatus,iOp);
179 Print (dlDETAIL, TEXT("Client 0x%08lX: UnlockUser succeeded"), idClient);
180 AfsAdmSvr_EndOperation (iOp);
181 return TRUE;
185 // AfsAdmSvr_CreateUser
186 // ...creates a new user account
188 extern "C" int AfsAdmSvr_CreateUser (UINT_PTR idClient, ASID idCell, LPAFSADMSVR_CREATEUSER_PARAMS pCreate, ASID *pidUser, ULONG *pStatus)
190 ASACTION Action;
191 Action.Action = ACTION_USER_CREATE;
192 Action.idClient = idClient;
193 Action.idCell = idCell;
194 lstrcpy (Action.u.User_Create.szUser, pCreate->szName);
195 lstrcpy (Action.u.User_Create.szInstance, pCreate->szInstance);
196 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
198 Print (dlDETAIL, TEXT("Client 0x%08lX: CreateUser (szUser=%s)"), idClient, pCreate->szName);
200 if (!AfsAdmSvr_fIsValidClient (idClient))
201 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
203 // Create the user account
205 ULONG status;
206 LPIDENT lpiUser;
207 if ((lpiUser = AfsClass_CreateUser ((LPIDENT)idCell, pCreate->szName, pCreate->szInstance, pCreate->szPassword, pCreate->idUser, pCreate->fCreateKAS, pCreate->fCreatePTS, &status)) == NULL)
209 Print (dlERROR, TEXT("Client 0x%08lX: CreateUser failed; error 0x%08lX"), idClient, status);
210 return FALSE_(status,pStatus,iOp);
213 if (pidUser)
214 *pidUser = (ASID)lpiUser;
216 // Creating a user account may change the max user ID
217 AfsAdmSvr_TestProperties (idCell);
219 Print (dlDETAIL, TEXT("Client 0x%08lX: CreateUser succeeded"), idClient);
220 AfsAdmSvr_EndOperation (iOp);
221 return TRUE;
225 // AfsAdmSvr_DeleteUser
226 // ...deletes a user's account
228 extern "C" int AfsAdmSvr_DeleteUser (UINT_PTR idClient, ASID idCell, ASID idUser, LPAFSADMSVR_DELETEUSER_PARAMS pDelete, ULONG *pStatus)
230 ASACTION Action;
231 Action.Action = ACTION_USER_DELETE;
232 Action.idClient = idClient;
233 Action.idCell = idCell;
234 Action.u.User_Delete.idUser = idUser;
235 size_t iOp = AfsAdmSvr_BeginOperation (idClient, &Action);
237 Print (dlDETAIL, TEXT("Client 0x%08lX: DeleteUser (idUser=0x%08lX)"), idClient, idUser);
239 if (!AfsAdmSvr_fIsValidClient (idClient))
240 return FALSE_(ERROR_INVALID_PARAMETER,pStatus,iOp);
242 // Delete the user's accounts
244 ULONG status;
245 if (!AfsClass_DeleteUser ((LPIDENT)idUser, pDelete->fDeleteKAS, pDelete->fDeletePTS, &status))
247 Print (dlERROR, TEXT("Client 0x%08lX: DeleteUser failed; error 0x%08lX"), idClient, status);
248 return FALSE_(status,pStatus,iOp);
251 Print (dlDETAIL, TEXT("Client 0x%08lX: DeleteUser succeeded"), idClient);
252 AfsAdmSvr_EndOperation (iOp);
253 return TRUE;