void GetCredentialsDlgParams (LPCREDENTIALSDLG_PARAMS lpp) { memset (lpp, 0x00, sizeof(CREDENTIALSDLG_PARAMS)); lpp->hParent = g.hMain; lpp->hCreds = g.hCreds; if (g.idCell) asc_CellNameGet_Fast (g.idClient, g.idCell, lpp->szCell); else AfsAppLib_GetLocalCell (lpp->szCell); GetBadCredsDlgParams (&lpp->bcdp); }
void ShowOptionsDialog (void) { TCHAR szCell[ cchNAME ]; if (g.lpiCell) g.lpiCell->GetCellName (szCell); else AfsAppLib_GetLocalCell (szCell); LPPROPSHEET psh = PropSheet_Create (IDS_OPTIONS_TITLE, FALSE); psh->sh.hwndParent = g.hMain; PropSheet_AddTab (psh, IDS_OPTIONS_GENERAL_TAB, IDD_OPTIONS_GENERAL, (DLGPROC)Options_General_DlgProc, 0, TRUE); PropSheet_ShowModal (psh, PumpMessage); }
BOOL DlgProc_Browse_StartSearch (BROWSEDIALOGPARAMS *pbdp, BOOL fCloseDlgIfFail) { DWORD dwThreadID; // Can't start a new search until the old search terminates. // DlgProc_Browse_StopSearch (pbdp); // Then make sure that we have a valid cell to query--if not, it may // be grounds to terminate the entire browse dialog. // lstrcpy (pbdp->szThreadCell, pbdp->szCell); if (!pbdp->szCell[0]) { AfsAppLib_GetLocalCell (pbdp->szCell); lstrcpy (pbdp->szThreadCell, pbdp->szCell); DlgProc_Browse_UpdateCellText (pbdp, pbdp->szThreadCell); } if (!pbdp->szCell[0]) { if (fCloseDlgIfFail) EndDialog (pbdp->hDlg, IDCANCEL); MessageBeep (MB_ICONHAND); Message (MB_ICONHAND, IDS_BROWSE_BADCELL_TITLE, IDS_BROWSE_BADCELL_DESC); if (!fCloseDlgIfFail) PostMessage (pbdp->hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (pbdp->hDlg, IDC_BROWSE_CELL), (LPARAM)TRUE); return FALSE; } // Great--we can do the search. Start a thread to do so. // pbdp->fCanStopThreadEasily = FALSE; pbdp->fShouldStopThread = FALSE; pbdp->fThreadActive = FALSE; ListView_DeleteAllItems (GetDlgItem (pbdp->hDlg, IDC_BROWSE_LIST)); pbdp->hThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)DlgProc_Browse_ThreadProc, pbdp, 0, &dwThreadID); return (pbdp->hThread == 0) ? FALSE : TRUE; }
void OpenCell_OnInitDialog (HWND hDlg, LPOPENCELLDLG_PARAMS lpp) { // Fix the title of the dialog (unless the caller has supplied a // custom dialog template) // if (lpp && (lpp->idd == IDD_APPLIB_OPENCELL)) { TCHAR szApplication[ cchNAME ]; AfsAppLib_GetAppName (szApplication); if (szApplication[0] != TEXT('\0')) { TCHAR szTitle[ cchRESOURCE ]; GetWindowText (hDlg, szTitle, cchRESOURCE); lstrcat (szTitle, TEXT(" - ")); lstrcat (szTitle, szApplication); SetWindowText (hDlg, szTitle); } } // Fill in the 'Cell:' combobox; we'll list the default cell, and any // cell which the user has specified before. // CB_StartChange (GetDlgItem (hDlg, IDC_OPENCELL_CELL), TRUE); if (!lpp->lpcl) { TCHAR szDefCell[ cchNAME ]; if (AfsAppLib_GetLocalCell (szDefCell) && *szDefCell) { CB_AddItem (GetDlgItem (hDlg, IDC_OPENCELL_CELL), szDefCell, 1); } } else for (size_t ii = 0; ii < lpp->lpcl->nCells; ++ii) { CB_AddItem (GetDlgItem (hDlg, IDC_OPENCELL_CELL), lpp->lpcl->aCells[ii], 1+ii); } CB_EndChange (GetDlgItem (hDlg, IDC_OPENCELL_CELL), 1); // Set up the "Credentials" box; if the user needs credentials to edit // this default cell, jump the cursor to the appropriate field // SetDlgItemText (hDlg, IDC_OPENCELL_ID, TEXT("admin")); OpenCell_OnCell (hDlg); }
BOOL AfsAppLib_CheckCredentials (LPCHECKCREDS_PARAMS lpp) { BOOL fCredsOK = TRUE; int idsWarning = IDS_BADCREDS_DESC_GENERAL; TCHAR szCell[ cchNAME ]; TCHAR szUser[ cchNAME ]; SYSTEMTIME stExpire; if (!AfsAppLib_CrackCredentials (lpp->hCreds, szCell, szUser, &stExpire)) { fCredsOK = FALSE; } else if (!AfsAppLib_IsUserAdmin (lpp->hCreds, szUser)) { fCredsOK = FALSE; idsWarning = IDS_BADCREDS_DESC_BADCHOICE; } else if (!AfsAppLib_IsTimeInFuture (&stExpire)) { fCredsOK = FALSE; idsWarning = IDS_BADCREDS_DESC_EXPIRED; } if (!fCredsOK && lpp->fShowWarning) { if (lpp->bcdp.pfShowWarningEver && !(*lpp->bcdp.pfShowWarningEver)) { fCredsOK = TRUE; // user says always ignore bad credentials. } else { if (!szCell[0]) AfsAppLib_GetLocalCell (szCell); int idsDesc = (lpp->bcdp.idsDesc) ? lpp->bcdp.idsDesc : IDS_BADCREDS_DESC2; LPTSTR pszDesc = FormatString (idsDesc, TEXT("%s"), szCell); LPTSTR pszFullText = FormatString (idsWarning, TEXT("%s%s%m"), szCell, pszDesc, IDS_BADCREDS_DESC3); FreeString (pszDesc); REALBADCREDSDLG_PARAMS pp; memset (&pp, 0x00, sizeof(pp)); pp.pszFullText = pszFullText; memcpy (&pp.bcdp, &lpp->bcdp, sizeof(BADCREDSDLG_PARAMS)); HINSTANCE hInst = APP_HINST; if (pp.bcdp.idd == 0) { hInst = APPLIB_HINST; pp.bcdp.idd = IDD_APPLIB_BADCREDS; } INT_PTR rc = ModalDialogParam (pp.bcdp.idd, pp.bcdp.hParent, (DLGPROC)BadCreds_DlgProc, (LPARAM)&pp); if (rc == IDCANCEL) { fCredsOK = TRUE; // user says ignore bad credentials this time. } FreeString (pszFullText); } } return fCredsOK; }
void DlgProc_Browse_OnInitDialog (HWND hDlg, BROWSEDIALOGPARAMS *pbdp) { TCHAR szText[ cchRESOURCE ]; LPTSTR psz; pbdp->hDlg = hDlg; // We'll need an imagelist, if we want icons in the listview. // This looks difficult but it's not--tis just a matter of selecting // an appropriate bitmap. // if ((pbdp->hImages = ImageList_Create (cxICON, cyICON, ILC_COLOR4 | ILC_MASK, 1, 1)) != 0) { HBITMAP bmp; if (pbdp->bt == btLOCAL_USER) { bmp = LoadBitmap (APPLIB_HINST, MAKEINTRESOURCE( IDB_LOCAL_USER )); } else if (pbdp->bt == btANY_USER) { bmp = LoadBitmap (APPLIB_HINST, MAKEINTRESOURCE( IDB_FOREIGN_USER )); } else if (pbdp->bt == btLOCAL_GROUP) { bmp = LoadBitmap (APPLIB_HINST, MAKEINTRESOURCE( IDB_LOCAL_GROUP )); } else if (pbdp->bt == btANY_GROUP) { bmp = LoadBitmap (APPLIB_HINST, MAKEINTRESOURCE( IDB_FOREIGN_GROUP )); } if (bmp != NULL) { ImageList_AddMasked (pbdp->hImages, bmp, clrTRANSPARENT); DeleteObject (bmp); } ListView_SetImageList (GetDlgItem (hDlg, IDC_BROWSE_LIST), pbdp->hImages, LVSIL_SMALL); } // There's a default pushbutton on this dialog, so that hitting // RETURN when you're in the Cell combobox will restart the search // (a default pushbutton always gets called when RETURN is hit, // unless your control traps it). But the user doesn't want to *see* // that thing, so move it way off the dialog's client area. // RECT r; GetWindowRect (GetDlgItem (hDlg, IDC_BROWSE_RESTART), &r); SetWindowPos (GetDlgItem (hDlg, IDC_BROWSE_RESTART), NULL, 0 - (r.right-r.left), 0 - (r.bottom-r.top), 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); // Fill in the choices underneath IDC_BROWSE_CELL. Can the // user enter a new cell name? // if (pbdp->fThisCellOnly) { EnableWindow (GetDlgItem (hDlg, IDC_BROWSE_CELL), FALSE); } else { CB_StartChange (GetDlgItem (hDlg, IDC_BROWSE_CELL)); if (!pbdp->lpcl) { TCHAR szDefCell[ cchNAME ]; if (AfsAppLib_GetLocalCell (szDefCell) && *szDefCell) { CB_AddItem (GetDlgItem (hDlg, IDC_BROWSE_CELL), szDefCell, 1); } } else for (size_t ii = 0; ii < pbdp->lpcl->nCells; ++ii) { CB_AddItem (GetDlgItem (hDlg, IDC_BROWSE_CELL), pbdp->lpcl->aCells[ii], 1+ii); } CB_EndChange (GetDlgItem (hDlg, IDC_BROWSE_CELL), 1); } // Select various texts to display in the dialog // psz = FormatString (TEXT("%1"), TEXT("%m"), pbdp->idsTitle); SetWindowText (hDlg, psz); FreeString (psz); GetString (szText, pbdp->idsPrompt); SetDlgItemText (hDlg, IDC_BROWSE_TYPE, szText); // If the caller wants us to display a "[X] No Group" checkbox, do so // by creating a checkbox right underneath the IDC_BROWSE_NAMED edit // control--note that we'll have to hide IDC_BROWSE_STATUS if that's // the case. // if (pbdp->idsNone != 0) { ShowWindow (GetDlgItem (pbdp->hDlg, IDC_BROWSE_STATUS), FALSE); RECT rr; GetRectInParent (GetDlgItem (pbdp->hDlg, IDC_BROWSE_NAMED), &rr); LONG cy; cy = rr.bottom -rr.top; rr.top += cy +3; rr.bottom = rr.top +cy; GetString (szText, pbdp->idsNone); CreateWindow ("Button", szText, WS_CHILD | BS_AUTOCHECKBOX, rr.left, rr.top, rr.right-rr.left, rr.bottom-rr.top, pbdp->hDlg, (HMENU)IDC_BROWSE_NONE, APPLIB_HINST, 0); HFONT hf = (HFONT)GetStockObject (DEFAULT_GUI_FONT); SendMessage (GetDlgItem (pbdp->hDlg, IDC_BROWSE_NONE), WM_SETFONT, (WPARAM)hf, FALSE); ShowWindow (GetDlgItem (pbdp->hDlg, IDC_BROWSE_NONE), TRUE); if (pbdp->szNamed[0] == TEXT('\0')) CheckDlgButton (pbdp->hDlg, IDC_BROWSE_NONE, TRUE); else CheckDlgButton (pbdp->hDlg, IDC_BROWSE_NONE, FALSE); DlgProc_Browse_OnNone (pbdp->hDlg, pbdp); } SetDlgItemText (hDlg, IDC_BROWSE_CELL, pbdp->szCell); SetDlgItemText (hDlg, IDC_BROWSE_NAMED, pbdp->szNamed); // Start looking for users/groups // DlgProc_Browse_StartSearch (pbdp, TRUE); }
CMDLINEOP ParseCommandLine (LPTSTR pszCmdLine) { size_t ii; for (ii = 0; ii < nSWITCHES; ++ii) aSWITCHES[ ii ].fPresent = FALSE; // Search through pszCmdLine for switches; each switch must be // preceeded by "/" or "-". // while (pszCmdLine && *pszCmdLine) { while (iswhite(*pszCmdLine)) ++pszCmdLine; if (!*pszCmdLine) break; if ( (*pszCmdLine != '-') && (*pszCmdLine != '/') ) { CommandLineHelp (IDS_CMDLINE_SYNTAX); return opCLOSEAPP; } ++pszCmdLine; // Okay, we've found what is probably the start of a switch. // See if it matches anything. // for (ii = 0; ii < nSWITCHES; ++ii) { size_t cch = lstrlen(aSWITCHES[ ii ].szSwitch); if (lstrncmpi (pszCmdLine, aSWITCHES[ ii ].szSwitch, cch)) continue; // If the switch wants a value, it must be followed by ":" // or whitespace; if it doesn't, it must be followed by "/" // or whitespace. // LPTSTR pszAfter = &pszCmdLine[ cch ]; if (iswhite (*pszAfter) || (!*pszAfter) || ((*pszAfter == TEXT(':')) && (aSWITCHES[ ii ].fGetsValue)) || ((*pszAfter == TEXT('/')) && (!aSWITCHES[ ii ].fGetsValue)) ) { break; // found a switch! } } if (ii >= nSWITCHES) { TCHAR szCopy[ cchRESOURCE ]; lstrcpy (szCopy, pszCmdLine); LPTSTR pch; for (pch = szCopy; *pch && !iswhite(*pch) && !(*pch == TEXT('/')) && !(*pch == TEXT(':')); ++pch) ; *pch = TEXT('\0'); CommandLineHelp (IDS_CMDLINE_UNRECOGNIZED, TEXT("%s"), szCopy); return opCLOSEAPP; } if (aSWITCHES[ ii ].fPresent) { CommandLineHelp (IDS_CMDLINE_DUPLICATE, TEXT("%s"), aSWITCHES[ ii ].szSwitch); return opCLOSEAPP; } // Woo hoo! Found what appears to be a valid switch. Parse it now. // aSWITCHES[ ii ].fPresent = TRUE; pszCmdLine += lstrlen( aSWITCHES[ ii ].szSwitch ); while (iswhite (*pszCmdLine)) ++pszCmdLine; if (*pszCmdLine == TEXT(':')) { if (!aSWITCHES[ ii ].fGetsValue) { CommandLineHelp (IDS_CMDLINE_UNEXPECTVALUE, TEXT("%s"), aSWITCHES[ ii ].szSwitch); return opCLOSEAPP; } for (++pszCmdLine; iswhite (*pszCmdLine); ++pszCmdLine) ; } if (aSWITCHES[ ii ].fGetsValue) { if ( (*pszCmdLine == TEXT('/')) || (*pszCmdLine == TEXT('\0')) ) { CommandLineHelp (IDS_CMDLINE_MISSINGVAL, TEXT("%s"), aSWITCHES[ ii ].szSwitch); return opCLOSEAPP; } BOOL fQuoted = FALSE; LPTSTR pszTarget; for (pszTarget = aSWITCHES[ ii ].szValue; *pszCmdLine && !(*pszCmdLine == TEXT('/') && !fQuoted) && !(iswhite(*pszCmdLine) && !fQuoted); ) { if (*pszCmdLine == TEXT('"')) { ++pszCmdLine; if (fQuoted) break; fQuoted = TRUE; continue; } *pszTarget++ = *pszCmdLine++; } *pszTarget++ = TEXT('\0'); } } // Was the -CONFIRM switch given? It works with any other switch // combination. // if (aSWITCHES[ swCONFIRM ].fPresent) { Action_ShowConfirmations (TRUE); } // Now test the command-line for syntactical correctness. // First test: if the SUBSET switch is given, the CELL switch must // be given as well. // if ( (aSWITCHES[ swSUBSET ].fPresent) && (!aSWITCHES[ swCELL ].fPresent) ) { CommandLineHelp (IDS_CMDLINE_SUBSETNOTCELL); return opCLOSEAPP; } // Similarly, if the SERVER switch is given, the CELL switch must // be given as well. // if ( (aSWITCHES[ swSERVER ].fPresent) && (!aSWITCHES[ swCELL ].fPresent) ) { CommandLineHelp (IDS_CMDLINE_SERVERNOTCELL); return opCLOSEAPP; } // And if the USER or PASSWORD switch is given, the other is required. // if ( (aSWITCHES[ swUSER ].fPresent && !aSWITCHES[ swPASSWORD ].fPresent) || (aSWITCHES[ swPASSWORD ].fPresent && !aSWITCHES[ swUSER ].fPresent) ) { CommandLineHelp (IDS_CMDLINE_USERPASSWORD); return opCLOSEAPP; } // Implement the command-line switches. // if (aSWITCHES[ swRESET ].fPresent) { if (aSWITCHES[ swSERVER ].fPresent) { ErasePreferences (aSWITCHES[ swCELL ].szValue, aSWITCHES[ swSERVER ].szValue); } else if (aSWITCHES[ swCELL ].fPresent) { ErasePreferences (aSWITCHES[ swCELL ].szValue); } else // neither cell nor server specified--kill just the general stuff { EraseSettings (REGSTR_SETTINGS_BASE, REGSTR_SETTINGS_PATH, REGVAL_SETTINGS); } Message (MB_OK | MB_ICONINFORMATION, IDS_CMDLINE_RESET_TITLE, IDS_CMDLINE_RESET_DESC); return opCLOSEAPP; } if (aSWITCHES[ swUSER ].fPresent) { LPTSTR pszCell = (aSWITCHES[ swCELL ].fPresent) ? (aSWITCHES[ swCELL ].szValue) : NULL; ULONG status; if (!AfsAppLib_SetCredentials (pszCell, aSWITCHES[ swUSER ].szValue, aSWITCHES[ swPASSWORD ].szValue, &status)) { ImmediateErrorDialog (status, IDS_SVR_ERROR_BAD_CREDENTIALS); return opCLOSEAPP; } } if (aSWITCHES[ swLOOKUP ].fPresent) { return opLOOKUPERRORCODE; } if (aSWITCHES[ swUSEEXISTING ].fPresent) { ULONG ulStatus; TCHAR szDefCell[ cchNAME ]; if (aSWITCHES[ swCELL ].fPresent) { lstrcpy(szDefCell,aSWITCHES[ swCELL ].szValue); } else { AfsAppLib_GetLocalCell(szDefCell); } g.hCreds = AfsAppLib_GetCredentials(szDefCell,&ulStatus); if (g.hCreds != NULL) { LPOPENCELL_PACKET lpocp = New (OPENCELL_PACKET); memset(lpocp,0x00,sizeof(OPENCELL_PACKET)); lstrcpy(lpocp->szCell,szDefCell); lpocp->fCloseAppOnFail = TRUE; lpocp->hCreds = g.hCreds; lpocp->sub = NULL; StartTask(taskOPENCELL,NULL,lpocp); return opNOCELLDIALOG; } else return opCLOSEAPP; } if (aSWITCHES[ swCELL ].fPresent) { LPOPENCELL_PACKET lpp = New (OPENCELL_PACKET); memset (lpp, 0x00, sizeof(OPENCELL_PACKET)); lstrcpy (lpp->szCell, aSWITCHES[ swCELL ].szValue); lpp->fCloseAppOnFail = TRUE; if (aSWITCHES[ swSUBSET ].fPresent) { lpp->sub = Subsets_LoadSubset (lpp->szCell, aSWITCHES[ swSUBSET ].szValue); if (lpp->sub == NULL) { Delete (lpp); lpp = NULL; CommandLineHelp (IDS_CMDLINE_INVALIDSUBSET, TEXT("%s%s"), aSWITCHES[ swCELL ].szValue, aSWITCHES[ swSUBSET ].szValue); return opCLOSEAPP; } } else if (aSWITCHES[ swSERVER ].fPresent) { lpp->sub = New (SUBSET); memset (lpp->sub, 0x0, sizeof(SUBSET)); FormatMultiString (&lpp->sub->pszMonitored, TRUE, TEXT("%1"), TEXT("%s"), aSWITCHES[ swSERVER ].szValue); } StartTask (taskOPENCELL, NULL, lpp); return opNOCELLDIALOG; } // Okay--nothing sufficiently special took place to prevent us // from running the tool normally. // return opNORMAL; }