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)
159 for (size_t ii = 0; ii < ENCRYPTIONKEYLENGTH; ++ii)
164 if (ii == ENCRYPTIONKEYLENGTH)
166 GetString (psz, IDS_USER_KEY_HIDDEN);
170 for (ii = 0; ii < ENCRYPTIONKEYLENGTH; ++ii)
172 WORD ch1 = (WORD)(pKey[ii]) / 64;
173 WORD ch2 = ((WORD)(pKey[ii]) - (ch1 * 64)) / 8;
174 WORD ch3 = ((WORD)(pKey[ii]) - (ch1 * 64) - (ch2 * 8));
175 wsprintf (psz, TEXT("\\%0d%0d%0d"), ch1, ch2, ch3);
183 BOOL ScanServerKey (PBYTE pKey, LPTSTR psz)
185 for (size_t ich = 0; psz && *psz; )
187 if (ich == ENCRYPTIONKEYLENGTH)
192 pKey[ ich++ ] = (BYTE)*psz++;
196 if ((lstrlen(psz) < 4) || (!isdigit(*(1+psz))))
199 ++psz; // skip the backslash
200 WORD ch1 = (WORD)((*psz++) - TEXT('0'));
201 WORD ch2 = (WORD)((*psz++) - TEXT('0'));
202 WORD ch3 = (WORD)((*psz++) - TEXT('0'));
203 pKey[ ich++ ] = (BYTE)( ch1 * 64 + ch2 * 8 + ch3 );
206 return (ich == ENCRYPTIONKEYLENGTH) ? TRUE : FALSE;
210 int CALLBACK General_ListSortFunction (HWND hList, HLISTITEM hItem1, LPARAM lpItem1, HLISTITEM hItem2, LPARAM lpItem2)
212 // Find out what kind of sort we're performing. To speed things up,
213 // we'll only gather this information when we start a sort
217 static BOOL fReverse;
218 static COLUMNTYPE ct;
219 static GetColumnFunction fnGetColumn = NULL;
220 if (!hItem1 || !hItem2)
222 switch (GetWindowLong (hList, GWL_ID))
227 case IDC_GROUPS_LIST:
235 FastList_GetSortStyle (hList, &iColumn, &fReverse);
240 iCol = gr.viewUsr.aColumns[ iColumn ];
241 fnGetColumn = (GetColumnFunction)User_GetColumn;
244 iCol = gr.viewGrp.aColumns[ iColumn ];
245 fnGetColumn = (GetColumnFunction)Group_GetColumn;
250 (*fnGetColumn)(g.idCell, iCol, NULL, NULL, NULL, &ct);
259 TCHAR szTextA[ 1024 ];
260 TCHAR szTextB[ 1024 ];
261 FILETIME ftTextA = { 0, 0 };
262 FILETIME ftTextB = { 0, 0 };
264 ASID idItem1 = (ASID)( (fReverse) ? lpItem2 : lpItem1 );
265 ASID idItem2 = (ASID)( (fReverse) ? lpItem1 : lpItem2 );
270 (*fnGetColumn)(idItem1, iCol, szTextA, NULL, NULL, NULL);
271 (*fnGetColumn)(idItem2, iCol, szTextB, NULL, NULL, NULL);
272 return lstrcmpi (szTextA, szTextB);
275 (*fnGetColumn)(idItem1, iCol, szTextA, NULL, NULL, NULL);
276 (*fnGetColumn)(idItem2, iCol, szTextB, NULL, NULL, NULL);
277 return atol(szTextA) - atol(szTextB);
282 (*fnGetColumn)(idItem1, iCol, NULL, &stTextA, NULL, NULL);
283 (*fnGetColumn)(idItem2, iCol, NULL, &stTextB, NULL, NULL);
284 SystemTimeToFileTime (&stTextA, &ftTextA);
285 SystemTimeToFileTime (&stTextB, &ftTextB);
286 return CompareFileTime (&ftTextA, &ftTextB);
291 (*fnGetColumn)(idItem1, iCol, NULL, NULL, &csecTextA, NULL);
292 (*fnGetColumn)(idItem2, iCol, NULL, NULL, &csecTextB, NULL);
293 return csecTextA - csecTextB;
300 void AppendUID (LPTSTR psz, int uid)
303 wsprintf (&psz[ lstrlen(psz) ], TEXT(" (%ld)"), uid);
307 LPTSTR GetEditText (HWND hEdit)
309 size_t cch = 1 + SendMessage (hEdit, EM_LINELENGTH, 0, 0);
310 LPTSTR psz = AllocateString (cch);
311 cch = GetWindowText (hEdit, psz, cch);
312 psz[cch] = TEXT('\0');
317 BOOL fIsMachineAccount (ASID idAccount)
319 TCHAR szName[ cchNAME ];
320 if (!asc_ObjectNameGet_Fast (g.idClient, g.idCell, idAccount, szName))
322 return fIsMachineAccount (szName);
326 BOOL fIsMachineAccount (LPTSTR pszName)
328 for ( ; pszName && *pszName; ++pszName)
330 if (!( (*pszName == TEXT('.')) || ((*pszName >= TEXT('0')) && (*pszName <= TEXT('9'))) ))