Windows: roken.h ordering
[openafs.git] / src / WINNT / afsadmsvr / TaAfsAdmSvrClientUser.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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  */
9
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
12
13 extern "C" {
14 #include <afsconfig.h>
15 #include <afs/param.h>
16 #include <afs/stds.h>
17 #include <roken.h>
18 }
19
20 #include "TaAfsAdmSvrClientInternal.h"
21
22
23 /*
24  * ROUTINES ___________________________________________________________________
25  *
26  */
27
28 BOOL ADMINAPI asc_UserChange (UINT_PTR idClient, ASID idCell, ASID idUser, LPAFSADMSVR_CHANGEUSER_PARAMS pChange, ULONG *pStatus)
29 {
30    BOOL rc = TRUE;
31    ULONG status = 0;
32
33    RpcTryExcept
34       {
35       if ((rc = AfsAdmSvr_ChangeUser (idClient, idCell, idUser, pChange, &status)) != FALSE)
36          {
37          // If we succeeded in changing this user's properties, get the
38          // newest values for our cache.
39          //
40          ASOBJPROP Properties;
41          rc = asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, idUser, &Properties, &status);
42          }
43       }
44    RpcExcept(1)
45       {
46       rc = FALSE;
47       status = RPC_S_CALL_FAILED_DNE;
48       }
49    RpcEndExcept
50
51    if (!rc && pStatus)
52       *pStatus = status;
53    return rc;
54 }
55
56
57 BOOL ADMINAPI asc_UserPasswordSet (UINT_PTR idClient, ASID idCell, ASID idUser, int keyVersion, LPCTSTR pkeyString, PBYTE pkeyData, ULONG *pStatus)
58 {
59    BOOL rc = TRUE;
60    ULONG status = 0;
61
62    RpcTryExcept
63       {
64       BYTE keyData[ ENCRYPTIONKEYLENGTH ];
65       if (pkeyData)
66          memcpy (keyData, pkeyData, sizeof(keyData));
67       else
68          memset (keyData, 0x00, sizeof(keyData));
69
70       STRING keyString;
71       if (pkeyString)
72          lstrcpy (keyString, pkeyString);
73       else
74          memset (keyString, 0x00, sizeof(keyString));
75
76       if ((rc = AfsAdmSvr_SetUserPassword (idClient, idCell, idUser, keyVersion, keyString, keyData, &status)) == TRUE)
77          {
78          // If we succeeded in changing this user's password, get the
79          // newest user properties for our cache.
80          //
81          ASOBJPROP Properties;
82          rc = asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, idUser, &Properties, &status);
83          }
84       }
85    RpcExcept(1)
86       {
87       rc = FALSE;
88       status = RPC_S_CALL_FAILED_DNE;
89       }
90    RpcEndExcept
91
92    if (!rc && pStatus)
93       *pStatus = status;
94    return rc;
95 }
96
97
98 BOOL ADMINAPI asc_UserUnlock (UINT_PTR idClient, ASID idCell, ASID idUser, ULONG *pStatus)
99 {
100    BOOL rc = TRUE;
101    ULONG status = 0;
102
103    RpcTryExcept
104       {
105       if ((rc = AfsAdmSvr_UnlockUser (idClient, idCell, idUser, &status)) == TRUE)
106          {
107          // If we succeeded in unlocking this user's account, get the
108          // newest user properties for our cache.
109          //
110          ASOBJPROP Properties;
111          rc = asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, idUser, &Properties, &status);
112          }
113       }
114    RpcExcept(1)
115       {
116       rc = FALSE;
117       status = RPC_S_CALL_FAILED_DNE;
118       }
119    RpcEndExcept
120
121    if (!rc && pStatus)
122       *pStatus = status;
123    return rc;
124 }
125
126
127 BOOL ADMINAPI asc_UserCreate (UINT_PTR idClient, ASID idCell, LPAFSADMSVR_CREATEUSER_PARAMS pCreate, ASID *pidUser, ULONG *pStatus)
128 {
129    BOOL rc = TRUE;
130    ULONG status = 0;
131
132    RpcTryExcept
133       {
134       if ((rc = AfsAdmSvr_CreateUser (idClient, idCell, pCreate, pidUser, &status)) == TRUE)
135          {
136          // If we succeeded in creating this user's account, get the
137          // initial user properties for our cache.
138          //
139          ASOBJPROP Properties;
140          rc = asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, *pidUser, &Properties, &status);
141          }
142       }
143    RpcExcept(1)
144       {
145       rc = FALSE;
146       status = RPC_S_CALL_FAILED_DNE;
147       }
148    RpcEndExcept
149
150    if (!rc && pStatus)
151       *pStatus = status;
152    return rc;
153 }
154
155
156 BOOL ADMINAPI asc_UserDelete (UINT_PTR idClient, ASID idCell, ASID idUser, LPAFSADMSVR_DELETEUSER_PARAMS pDelete, ULONG *pStatus)
157 {
158    BOOL rc = TRUE;
159    ULONG status = 0;
160
161    RpcTryExcept
162       {
163       if ((rc = AfsAdmSvr_DeleteUser (idClient, idCell, idUser, pDelete, &status)) == TRUE)
164          {
165          // If we succeeded in deleting this user's account, clean up our cache.
166          // Expect this call to fail (the user's deleted, right?)
167          //
168          ASOBJPROP Properties;
169          ULONG dummy;
170          (void)asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, idUser, &Properties, &dummy);
171          }
172       }
173    RpcExcept(1)
174       {
175       rc = FALSE;
176       status = RPC_S_CALL_FAILED_DNE;
177       }
178    RpcEndExcept
179
180    if (!rc && pStatus)
181       *pStatus = status;
182    return rc;
183 }
184