2 * Copyright 2000, International Business Machines Corporation and others.
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
11 #include <afs/param.h>
15 #include "TaAfsUsrMgr.h"
21 * ROUTINES ___________________________________________________________________
25 BOOL fIsValidDate (LPSYSTEMTIME pst)
27 return (pst->wYear >= 1971) ? TRUE : FALSE;
31 void FormatElapsedSeconds (LPTSTR pszText, LONG csec)
33 LPTSTR pszTarget = pszText;
35 if (csec >= csec1WEEK)
37 if (pszTarget != pszText)
38 *pszTarget++ = TEXT(' ');
39 LPTSTR psz = FormatString (IDS_COUNT_WEEKS, TEXT("%lu"), csec / csec1WEEK);
41 lstrcpy (pszTarget, psz);
42 pszTarget += lstrlen(pszTarget);
48 if (pszTarget != pszText)
49 *pszTarget++ = TEXT(' ');
50 LPTSTR psz = FormatString (IDS_COUNT_DAYS, TEXT("%lu"), csec / csec1DAY);
52 lstrcpy (pszTarget, psz);
53 pszTarget += lstrlen(pszTarget);
57 if (csec >= csec1HOUR)
59 if (pszTarget != pszText)
60 *pszTarget++ = TEXT(' ');
61 LPTSTR psz = FormatString (IDS_COUNT_HOURS, TEXT("%lu"), csec / csec1HOUR);
63 lstrcpy (pszTarget, psz);
64 pszTarget += lstrlen(pszTarget);
68 if (csec >= csec1MINUTE)
70 if (pszTarget != pszText)
71 *pszTarget++ = TEXT(' ');
72 LPTSTR psz = FormatString (IDS_COUNT_MINUTES, TEXT("%lu"), csec / csec1MINUTE);
74 lstrcpy (pszTarget, psz);
75 pszTarget += lstrlen(pszTarget);
79 if (csec || (pszTarget == pszText))
81 if (pszTarget != pszText)
82 *pszTarget++ = TEXT(' ');
83 LPTSTR psz = FormatString (IDS_COUNT_SECONDS, TEXT("%lu"), csec);
84 lstrcpy (pszTarget, psz);
85 pszTarget += lstrlen(pszTarget);
89 *pszTarget = TEXT('\0');
93 LPTSTR CreateNameList (LPASIDLIST pAsidList, int idsHeader)
97 pszOut = FormatString (TEXT("%1"), TEXT("%m"), idsHeader);
101 for (size_t ii = 0; ii < pAsidList->cEntries; ++ii)
104 TCHAR szName[ cchRESOURCE ];
105 if (!asc_ObjectNameGet_Fast (g.idClient, g.idCell, pAsidList->aEntries[ ii ].idObject, szName, &status))
108 static TCHAR szSeparator[ cchRESOURCE ] = TEXT("");
109 if (szSeparator[0] == TEXT('\0'))
111 if (!GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SLIST, szSeparator, cchRESOURCE))
112 lstrcpy (szSeparator, TEXT(","));
113 lstrcat (szSeparator, TEXT(" "));
116 ASOBJPROP Properties;
117 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAsidList->aEntries[ ii ].idObject, &Properties, &status))
119 if (Properties.Type == TYPE_USER)
120 AppendUID (szName, Properties.u.UserProperties.PTSINFO.uidName);
121 else if (Properties.Type == TYPE_GROUP)
122 AppendUID (szName, Properties.u.GroupProperties.uidName);
127 pszNext = FormatString (TEXT("%1"), TEXT("%s"), szName);
129 pszNext = FormatString (TEXT("%1%2"), TEXT("%s%s"), pszOut, szName);
130 else // (pszOut && ii)
131 pszNext = FormatString (TEXT("%1%2%3"), TEXT("%s%s%s"), pszOut, szSeparator, szName);
142 void GetLocalSystemTime (LPSYSTEMTIME pst)
145 GetSystemTime (&st_gmt);
148 SystemTimeToFileTime (&st_gmt, &ft_gmt);
151 FileTimeToLocalFileTime (&ft_gmt, &ft_local);
153 FileTimeToSystemTime (&ft_local, pst);
157 void FormatServerKey (LPTSTR psz, PBYTE pKey)
160 for (ii = 0; ii < ENCRYPTIONKEYLENGTH; ++ii)
165 if (ii == ENCRYPTIONKEYLENGTH)
167 GetString (psz, IDS_USER_KEY_HIDDEN);
171 for (ii = 0; ii < ENCRYPTIONKEYLENGTH; ++ii)
173 WORD ch1 = (WORD)(pKey[ii]) / 64;
174 WORD ch2 = ((WORD)(pKey[ii]) - (ch1 * 64)) / 8;
175 WORD ch3 = ((WORD)(pKey[ii]) - (ch1 * 64) - (ch2 * 8));
176 wsprintf (psz, TEXT("\\%0d%0d%0d"), ch1, ch2, ch3);
184 BOOL ScanServerKey (PBYTE pKey, LPTSTR psz)
187 for (ich = 0; psz && *psz; )
189 if (ich == ENCRYPTIONKEYLENGTH)
194 pKey[ ich++ ] = (BYTE)*psz++;
198 if ((lstrlen(psz) < 4) || (!isdigit(*(1+psz))))
201 ++psz; // skip the backslash
202 WORD ch1 = (WORD)((*psz++) - TEXT('0'));
203 WORD ch2 = (WORD)((*psz++) - TEXT('0'));
204 WORD ch3 = (WORD)((*psz++) - TEXT('0'));
205 pKey[ ich++ ] = (BYTE)( ch1 * 64 + ch2 * 8 + ch3 );
208 return (ich == ENCRYPTIONKEYLENGTH) ? TRUE : FALSE;
212 int CALLBACK General_ListSortFunction (HWND hList, HLISTITEM hItem1, LPARAM lpItem1, HLISTITEM hItem2, LPARAM lpItem2)
214 // Find out what kind of sort we're performing. To speed things up,
215 // we'll only gather this information when we start a sort
219 static BOOL fReverse;
220 static COLUMNTYPE ct;
221 static GetColumnFunction fnGetColumn = NULL;
222 if (!hItem1 || !hItem2)
224 switch (GetWindowLong (hList, GWL_ID))
229 case IDC_GROUPS_LIST:
237 FastList_GetSortStyle (hList, &iColumn, &fReverse);
242 iCol = (LONG) gr.viewUsr.aColumns[ iColumn ];
243 fnGetColumn = (GetColumnFunction)User_GetColumn;
246 iCol = (LONG) gr.viewGrp.aColumns[ iColumn ];
247 fnGetColumn = (GetColumnFunction)Group_GetColumn;
252 (*fnGetColumn)(g.idCell, iCol, NULL, NULL, NULL, &ct);
261 TCHAR szTextA[ 1024 ];
262 TCHAR szTextB[ 1024 ];
263 FILETIME ftTextA = { 0, 0 };
264 FILETIME ftTextB = { 0, 0 };
266 ASID idItem1 = (ASID)( (fReverse) ? lpItem2 : lpItem1 );
267 ASID idItem2 = (ASID)( (fReverse) ? lpItem1 : lpItem2 );
272 (*fnGetColumn)(idItem1, iCol, szTextA, NULL, NULL, NULL);
273 (*fnGetColumn)(idItem2, iCol, szTextB, NULL, NULL, NULL);
274 return lstrcmpi (szTextA, szTextB);
277 (*fnGetColumn)(idItem1, iCol, szTextA, NULL, NULL, NULL);
278 (*fnGetColumn)(idItem2, iCol, szTextB, NULL, NULL, NULL);
279 return atol(szTextA) - atol(szTextB);
284 (*fnGetColumn)(idItem1, iCol, NULL, &stTextA, NULL, NULL);
285 (*fnGetColumn)(idItem2, iCol, NULL, &stTextB, NULL, NULL);
286 SystemTimeToFileTime (&stTextA, &ftTextA);
287 SystemTimeToFileTime (&stTextB, &ftTextB);
288 return CompareFileTime (&ftTextA, &ftTextB);
293 (*fnGetColumn)(idItem1, iCol, NULL, NULL, &csecTextA, NULL);
294 (*fnGetColumn)(idItem2, iCol, NULL, NULL, &csecTextB, NULL);
295 return csecTextA - csecTextB;
302 void AppendUID (LPTSTR psz, int uid)
305 wsprintf (&psz[ lstrlen(psz) ], TEXT(" (%ld)"), uid);
309 LPTSTR GetEditText (HWND hEdit)
311 size_t cch = 1 + SendMessage (hEdit, EM_LINELENGTH, 0, 0);
312 LPTSTR psz = AllocateString (cch);
313 cch = GetWindowText (hEdit, psz, (int)cch);
314 psz[cch] = TEXT('\0');
319 BOOL fIsMachineAccount (ASID idAccount)
321 TCHAR szName[ cchNAME ];
322 if (!asc_ObjectNameGet_Fast (g.idClient, g.idCell, idAccount, szName))
324 return fIsMachineAccount (szName);
328 BOOL fIsMachineAccount (LPTSTR pszName)
330 for ( ; pszName && *pszName; ++pszName)
332 if (!( (*pszName == TEXT('.')) || ((*pszName >= TEXT('0')) && (*pszName <= TEXT('9'))) ))