Windows: fix checked UNICODE build of talocale
[openafs.git] / src / WINNT / afsusrmgr / usr_col.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 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include "TaAfsUsrMgr.h"
16 #include "usr_col.h"
17
18
19 /*
20  * USER-VIEW COLUMNS __________________________________________________________
21  *
22  */
23
24 void User_SetDefaultView (LPVIEWINFO lpvi, ICONVIEW *piv)
25 {
26    lpvi->lvsView = FLS_VIEW_SMALL;
27    lpvi->nColsAvail = nUSERCOLUMNS;
28
29    for (size_t iCol = 0; iCol < nUSERCOLUMNS; ++iCol)
30       {
31       lpvi->cxColumns[ iCol ]  = USERCOLUMNS[ iCol ].cxWidth;
32       lpvi->idsColumns[ iCol ] = USERCOLUMNS[ iCol ].idsColumn;
33       }
34
35    lpvi->iSort = usrcolNAME;
36
37    lpvi->nColsShown = 5;
38    lpvi->aColumns[0] = (int)usrcolNAME;
39    lpvi->aColumns[1] = (int)usrcolUID;
40    lpvi->aColumns[2] = (int)usrcolCHANGEPW;
41    lpvi->aColumns[3] = (int)usrcolREUSEPW;
42    lpvi->aColumns[4] = (int)usrcolEXPIRES;
43
44    *piv = ivSTATUS;
45 }
46
47
48 void User_GetColumn (ASID idObject, USERCOLUMN iCol, LPTSTR pszText, LPSYSTEMTIME pstDate, LONG *pcsec, COLUMNTYPE *pcType)
49 {
50    if (pszText)
51       *pszText = TEXT('\0');
52    if (pstDate)
53       memset (pstDate, 0x00, sizeof(SYSTEMTIME));
54    if (pcsec)
55       *pcsec = 0;
56    if (pcType)
57       *pcType = ctALPHABETIC;
58
59    ASOBJPROP Properties;
60    if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, idObject, &Properties))
61       {
62       switch (iCol)
63          {
64          case usrcolNAME:
65             if (pcType)
66                *pcType = ctALPHABETIC;
67             if (pszText)
68                User_GetDisplayName (pszText, &Properties);
69             break;
70
71          case usrcolFLAGS:
72             if (pcType)
73                *pcType = ctALPHABETIC;
74             if (pszText)
75                {
76                if (Properties.u.UserProperties.fHaveKasInfo)
77                   {
78                   if (Properties.u.UserProperties.KASINFO.fIsAdmin)
79                      {
80                      GetString (pszText, IDS_USRFLAG_ADMIN);
81                      pszText = &pszText[ lstrlen(pszText) -1 ];
82                      }
83                   if (Properties.u.UserProperties.KASINFO.fCanGetTickets)
84                      {
85                      GetString (pszText, IDS_USRFLAG_TICKET);
86                      pszText = &pszText[ lstrlen(pszText) -1 ];
87                      }
88                   if (Properties.u.UserProperties.KASINFO.fEncrypt)
89                      {
90                      GetString (pszText, IDS_USRFLAG_ENCRYPT);
91                      pszText = &pszText[ lstrlen(pszText) -1 ];
92                      }
93                   if (Properties.u.UserProperties.KASINFO.fCanChangePassword)
94                      {
95                      GetString (pszText, IDS_USRFLAG_CHANGEPW);
96                      pszText = &pszText[ lstrlen(pszText) -1 ];
97                      }
98                   if (Properties.u.UserProperties.KASINFO.fCanReusePasswords)
99                      {
100                      GetString (pszText, IDS_USRFLAG_REUSEPW);
101                      pszText = &pszText[ lstrlen(pszText) -1 ];
102                      }
103                   }
104                }
105             break;
106
107          case usrcolADMIN:
108             if (pcType)
109                *pcType = ctALPHABETIC;
110             if (Properties.u.UserProperties.fHaveKasInfo)
111                {
112                if (pszText)
113                   GetString (pszText, (Properties.u.UserProperties.KASINFO.fIsAdmin) ? IDS_YES : IDS_NO);
114                }
115             break;
116
117          case usrcolTICKET:
118             if (pcType)
119                *pcType = ctALPHABETIC;
120             if (Properties.u.UserProperties.fHaveKasInfo)
121                {
122                if (pszText)
123                   GetString (pszText, (Properties.u.UserProperties.KASINFO.fCanGetTickets) ? IDS_YES : IDS_NO);
124                }
125             break;
126
127          case usrcolSYSTEM:
128             if (pcType)
129                *pcType = ctALPHABETIC;
130             if (Properties.u.UserProperties.fHaveKasInfo)
131                {
132                if (pszText)
133                   GetString (pszText, (Properties.u.UserProperties.KASINFO.fEncrypt) ? IDS_NO : IDS_YES);
134                }
135             break;
136
137          case usrcolCHANGEPW:
138             if (pcType)
139                *pcType = ctALPHABETIC;
140             if (Properties.u.UserProperties.fHaveKasInfo)
141                {
142                if (pszText)
143                   GetString (pszText, (Properties.u.UserProperties.KASINFO.fCanChangePassword) ? IDS_YES : IDS_NO);
144                }
145             break;
146
147          case usrcolREUSEPW:
148             if (pcType)
149                *pcType = ctALPHABETIC;
150             if (Properties.u.UserProperties.fHaveKasInfo)
151                {
152                if (pszText)
153                   GetString (pszText, (Properties.u.UserProperties.KASINFO.fCanReusePasswords) ? IDS_YES : IDS_NO);
154                }
155             break;
156
157          case usrcolEXPIRES:
158             if (pcType)
159                *pcType = ctDATE;
160             if (Properties.u.UserProperties.fHaveKasInfo)
161                {
162                if (pszText)
163                   FormatTime (pszText, TEXT("%t"), &Properties.u.UserProperties.KASINFO.timeExpires);
164                if (pstDate)
165                   memcpy (pstDate, &Properties.u.UserProperties.KASINFO.timeExpires, sizeof(SYSTEMTIME));
166                }
167             break;
168
169          case usrcolLASTPW:
170             if (pcType)
171                *pcType = ctDATE;
172             if (Properties.u.UserProperties.fHaveKasInfo)
173                {
174                if (pszText)
175                   FormatTime (pszText, TEXT("%t"), &Properties.u.UserProperties.KASINFO.timeLastPwChange);
176                if (pstDate)
177                   memcpy (pstDate, &Properties.u.UserProperties.KASINFO.timeLastPwChange, sizeof(SYSTEMTIME));
178                }
179             break;
180
181          case usrcolLASTMOD:
182             if (pcType)
183                *pcType = ctDATE;
184             if (Properties.u.UserProperties.fHaveKasInfo)
185                {
186                if (pszText)
187                   FormatTime (pszText, TEXT("%t"), &Properties.u.UserProperties.KASINFO.timeLastMod);
188                if (pstDate)
189                   memcpy (pstDate, &Properties.u.UserProperties.KASINFO.timeLastMod, sizeof(SYSTEMTIME));
190                }
191             break;
192
193          case usrcolLASTMODBY:
194             if (pcType)
195                *pcType = ctALPHABETIC;
196             if (Properties.u.UserProperties.fHaveKasInfo)
197                {
198                if (pszText)
199                   lstrcpy (pszText, Properties.u.UserProperties.KASINFO.szUserLastMod);
200                }
201             break;
202
203          case usrcolLIFETIME:
204             if (pcType)
205                *pcType = ctELAPSED;
206             if (Properties.u.UserProperties.fHaveKasInfo)
207                {
208                if (pszText)
209                   FormatElapsedSeconds (pszText, Properties.u.UserProperties.KASINFO.csecTicketLifetime);
210                if (pcsec)
211                   *pcsec = Properties.u.UserProperties.KASINFO.csecTicketLifetime;
212                }
213             break;
214
215          case usrcolCDAYPW:
216             if (pcType)
217                *pcType = ctELAPSED;
218             if (Properties.u.UserProperties.fHaveKasInfo)
219                {
220                if (pszText)
221                   FormatElapsedSeconds (pszText, Properties.u.UserProperties.KASINFO.cdayPwExpire * csec1DAY);
222                if (pcsec)
223                   *pcsec = Properties.u.UserProperties.KASINFO.cdayPwExpire * csec1DAY;
224                }
225             break;
226
227          case usrcolCFAILLOGIN:
228             if (pcType)
229                *pcType = ctNUMERIC;
230             if (Properties.u.UserProperties.fHaveKasInfo)
231                {
232                if (pszText)
233                   wsprintf (pszText, TEXT("%lu"), Properties.u.UserProperties.KASINFO.cFailLogin);
234                }
235             break;
236
237          case usrcolCSECLOCK:
238             if (pcType)
239                *pcType = ctELAPSED;
240             if (Properties.u.UserProperties.fHaveKasInfo)
241                {
242                if (pszText)
243                   FormatElapsedSeconds (pszText, Properties.u.UserProperties.KASINFO.csecFailLoginLock);
244                if (pcsec)
245                   *pcsec = Properties.u.UserProperties.KASINFO.csecFailLoginLock;
246                }
247             break;
248
249          case usrcolCGROUPMAX:
250             if (pcType)
251                *pcType = ctNUMERIC;
252             if (Properties.u.UserProperties.fHavePtsInfo)
253                {
254                if (pszText)
255                   wsprintf (pszText, TEXT("%lu"), Properties.u.UserProperties.PTSINFO.cgroupCreationQuota);
256                }
257             break;
258
259          case usrcolUID:
260             if (pcType)
261                *pcType = ctNUMERIC;
262             if (Properties.u.UserProperties.fHavePtsInfo)
263                {
264                if (pszText)
265                   wsprintf (pszText, TEXT("%ld"), Properties.u.UserProperties.PTSINFO.uidName);
266                }
267             break;
268
269          case usrcolOWNER:
270             if (pcType)
271                *pcType = ctALPHABETIC;
272             if (Properties.u.UserProperties.fHavePtsInfo)
273                {
274                if (pszText)
275                   {
276                   if (Properties.u.UserProperties.PTSINFO.szOwner[0])
277                      wsprintf (pszText, TEXT("%s (%ld)"), Properties.u.UserProperties.PTSINFO.szOwner, Properties.u.UserProperties.PTSINFO.uidOwner);
278                   else
279                      wsprintf (pszText, TEXT("%ld"), Properties.u.UserProperties.PTSINFO.uidOwner);
280                   }
281                }
282             break;
283
284          case usrcolCREATOR:
285             if (pcType)
286                *pcType = ctALPHABETIC;
287             if (Properties.u.UserProperties.fHavePtsInfo)
288                {
289                if (pszText)
290                   {
291                   if (Properties.u.UserProperties.PTSINFO.szCreator[0])
292                      wsprintf (pszText, TEXT("%s (%ld)"), Properties.u.UserProperties.PTSINFO.szCreator, Properties.u.UserProperties.PTSINFO.uidCreator);
293                   else
294                      wsprintf (pszText, TEXT("%ld"), Properties.u.UserProperties.PTSINFO.uidCreator);
295                   }
296                }
297             break;
298          }
299       }
300 }
301
302
303 BOOL User_GetDisplayName (LPTSTR pszText, LPASOBJPROP pProperties)
304 {
305    lstrcpy (pszText, pProperties->szName);
306
307    if (pProperties->u.UserProperties.szInstance[0])
308       {
309       // Don't show the Instance value for certain entries
310       if ( (lstrcmpi (pProperties->szName, TEXT("admin"))) &&
311            (lstrcmpi (pProperties->szName, TEXT("krbtgt"))) )
312          {
313          wsprintf (&pszText[ lstrlen(pszText) ], TEXT(".%s"), pProperties->u.UserProperties.szInstance);
314          }
315       }
316
317    return !!*pszText;
318 }
319
320
321 BOOL User_GetDisplayName (LPTSTR pszText, ASID idUser)
322 {
323    ASOBJPROP Properties;
324    if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, idUser, &Properties))
325       {
326       return User_GetDisplayName (pszText, &Properties);
327       }
328    else
329       {
330       return asc_ObjectNameGet_Fast (g.idClient, g.idCell, idUser, pszText);
331       }
332 }
333
334
335 void User_SplitDisplayName (LPTSTR pszFull, LPTSTR pszName, LPTSTR pszInstance)
336 {
337    if (pszName)
338       lstrcpy (pszName, pszFull);
339    if (pszInstance)
340       lstrcpy (pszInstance, TEXT(""));
341
342    if (!fIsMachineAccount (pszFull))
343       {
344       if (pszName && pszInstance)
345          {
346          LPTSTR pchDot;
347          if ((pchDot = (LPTSTR)lstrchr (pszName, TEXT('.'))) != NULL)
348             {
349             *pchDot = TEXT('\0');
350             lstrcpy (pszInstance, &pchDot[1]);
351             }
352          }
353       }
354 }
355