📄 users.cpp
字号:
this realm.", pRealm );
MessageBox( hDlg, szBuf, "Remove Realm", MB_OK | MB_ICONEXCLAMATION );
return 0;
};
};
/*
** Check if realm is used by a mapping
*/
iTmp = 0;
for(;; iTmp++ )
{
const char *pTmp = M_LookupValueEx( pConfig, "Users",
"Mapping", iTmp );
if ( !pTmp ) { break; };
int i=0;
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
pTmp = &( pTmp[i] );
for( ; pTmp[i] && pTmp[i]!='\t'; i++ ); /* read length of realm */
PIString sRealm( pTmp, i );
if ( sRealm==pRealm )
{
sprintf( szBuf, "Realm '%s' is being used for directory mapping. \
Remove all Realm-URL Path mappings in 'Mapping' before removing \
this realm.", pRealm );
MessageBox( hDlg, szBuf, "Remove Realm", MB_OK | MB_ICONEXCLAMATION );
return 0;
};
};
return 1;
};
int Internal_findMethod( char *pName )
{
for(int iTmp = 0;; iTmp++ ) {
const char *pTmp = M_LookupValueEx( pConfig, "Realms", "Basic",
iTmp );
if ( !pTmp ) { break; };
if (!strcmp(pTmp,pName)) {
strcpy(pName, "Basic");
return 1;
}
}
for(iTmp=0;; iTmp++ ) {
const char *pTmp = M_LookupValueEx( pConfig, "Realms", "Digest",
iTmp );
if ( !pTmp ) { break; };
if (!strcmp(pTmp,pName)) {
strcpy(pName, "Digest");
return 1;
}
}
for(iTmp=0;; iTmp++ ) {
const char *pTmp = M_LookupValueEx( pConfig, "Realms", "Ntlm",
iTmp );
if ( !pTmp ) { break; };
if (!strcmp(pTmp,pName)) {
strcpy(pName, "Ntlm");
return 1;
}
}
return 0;
}
void Internal_saveItems( const char *pRealm )
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
assert( pRealm );
int i;
int iCount = SendMessage( hWndList, LB_GETCOUNT, 0, 0 );
/*
** Save all user types
*/
/*
** No users for Ntlm authentication
*/
strcpy(szBuf, pRealm);
if ( Internal_findMethod( szBuf ) && strcmp(szBuf,"Ntlm"))
{
/*
** Basic authentication
*/
if (!strcmp(szBuf,"Basic"))
{
/* --- remove old ones first --- */
PIString sSection( "__" );
sSection.Concatenate( pRealm );
M_DeleteValue( pConfig, sSection, "Base64" );
for( i=0; i<iCount; i++ )
{
*szBuf = '\0';
szBuf[BUF_SIZE] = '\0';
SendMessage( hWndList, LB_GETTEXT, i, (LPARAM)szBuf );
int iLen = strlen( szBuf );
int j;
for( j=0; j<iLen && szBuf[j]!='\t'; j++ );
if ( szBuf[j]=='\t' ) { szBuf[j] = ':'; };
PIString sBase64;
Base64Encode( szBuf, sBase64 );
M_AddValue( pConfig, sSection, "Base64", sBase64 );
};
}
/*
** Digest authentication
*/
else
{
/* --- remove old ones first --- */
PIString sSection( "__" );
sSection.Concatenate( pRealm );
M_DeleteValue( pConfig, sSection, "Digest" );
for( i=0; i<iCount; i++ )
{
*szBuf = '\0';
szBuf[BUF_SIZE] = '\0';
SendMessage( hWndList, LB_GETTEXT, i, (LPARAM)szBuf );
M_AddValue( pConfig, sSection, "Digest", szBuf );
};
}
}
};
BOOL CALLBACK NewRealmDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
switch (uMsg)
{
case WM_INITDIALOG:
hWndDlgOK = GetDlgItem( hDlg, IDOK );
hWndDlgRealm = GetDlgItem( hDlg, IDC_REALM );
hWndDlgBasic = GetDlgItem( hDlg, IDC_BASIC );
hWndDlgDigest = GetDlgItem( hDlg, IDC_DIGEST );
hWndDlgNtlm = GetDlgItem( hDlg, IDC_NTLM );
assert( hWndDlgOK && hWndDlgRealm && hWndDlgBasic
&& hWndDlgDigest && hWndDlgNtlm);
SendMessage( hWndDlgRealm, EM_SETLIMITTEXT, 256, 0 );
EnableWindow( hWndDlgOK, FALSE );
SendMessage( hWndDlgBasic, BM_SETCHECK, BST_CHECKED, 0 );
/*
** Enable NTLM authentication only for NT systems
*/
EnableWindow( hWndDlgNtlm,
!strcmp(M_LookupValue(pConfig,"General","OS"),"NT" ));
break;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case IDOK:
{
/*
** Validate content of edit field
*/
*szBuf = '\0';
SendMessage( hWndDlgRealm, WM_GETTEXT, BUF_SIZE,
(LPARAM)szBuf );
PIString sRealm( szBuf );
int i;
int iCount = SendMessage( hWndRealm, CB_GETCOUNT, 0, 0 );
for( i=0; i<iCount; i++ )
{
*szBuf = '\0';
SendMessage( hWndRealm, CB_GETLBTEXT, i,
(LPARAM)szBuf );
if ( sRealm == szBuf )
{
sprintf( szBuf, "Realm '%s' already exists.",
(const char *)sRealm );
MessageBox( hDlg, szBuf, "New Realm",
MB_OK | MB_ICONEXCLAMATION );
return (TRUE);
};
};
/*
** Can't use '(none)'
*/
if ( !stricmp( sRealm, "(none)" ) )
{
sprintf( szBuf, "'%s' is a reserved realm.",
(const char *)sRealm );
::MessageBox( hDlg, szBuf, "Remove Realm",
MB_OK | MB_ICONEXCLAMATION );
::SetFocus( hWndDlgRealm );
::SendMessage( hWndDlgRealm, EM_SETSEL, 0, -1 );
return (TRUE);
};
/*
** Add new realm
*/
SendMessage( hWndRealm, CB_ADDSTRING, 0, (LPARAM)(const char *)sRealm );
*szBuf = '\0';
if (SendMessage( hWndDlgBasic, BM_GETCHECK, 0, 0 ) == BST_CHECKED ) {
strcpy(szBuf, "Basic");
};
if (SendMessage( hWndDlgDigest, BM_GETCHECK, 0, 0 ) == BST_CHECKED ) {
strcpy(szBuf, "Digest");
};
if (SendMessage( hWndDlgNtlm, BM_GETCHECK, 0, 0 ) == BST_CHECKED ) {
strcpy(szBuf, "Ntlm");
};
M_AddValue( pConfig, "Realms", szBuf, (const char *)sRealm );
SendMessage( hWndMethod, WM_SETTEXT, 0, (LPARAM)szBuf );
/*
** Save old items
*/
*szBuf = '\0';
SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
Internal_saveItems( szBuf );
int iSel = SendMessage( hWndRealm, CB_FINDSTRINGEXACT,
(WPARAM)-1,
(LPARAM)(const char *)sRealm );
if ( iSel!=CB_ERR )
{
SendMessage( hWndRealm, CB_SETCURSEL, iSel, 0 );
if ( SendMessage( hWndRealm, CB_GETCURSEL, 0, 0 )!=
CB_ERR )
{
EnableWindow( hWndUser, TRUE );
EnableWindow( hWndPassword, TRUE );
EnableWindow( hWndConfirm, TRUE );
};
Internal_loadItems( sRealm );
}
else
{ assert( 0 ); };
};
EndDialog( hDlg, 1 );
break;
case IDCANCEL:
EndDialog( hDlg, 0 );
break;
case IDC_REALM:
if ( GET_WM_COMMAND_CMD(wParam, lParam)==EN_CHANGE )
{
if ( SendMessage( GET_WM_COMMAND_HWND(wParam,
lParam ), EM_LINELENGTH, 0, 0 )>0 )
{ EnableWindow( hWndDlgOK, TRUE ); }
else
{ EnableWindow( hWndDlgOK, FALSE ); }
}
else
return (FALSE);
break;
default:;
};
default:
return (FALSE);
};
return (TRUE);
};
BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
szBuf[BUF_SIZE]='\0';
int aTabstop[2];
switch (uMsg)
{
case WM_INITDIALOG:
HourglassOn();
{
hWndRealm = GetDlgItem( hDlg, IDC_REALM );
hWndList = GetDlgItem( hDlg, IDC_LIST );
hWndUser = GetDlgItem( hDlg, IDC_USER );
hWndPassword = GetDlgItem( hDlg, IDC_PASSWORD );
hWndConfirm = GetDlgItem( hDlg, IDC_CONFIRM );
hWndAdd = GetDlgItem( hDlg, IDC_ADD );
hWndReplace = GetDlgItem( hDlg, IDC_REPLACE );
hWndDelete= GetDlgItem( hDlg, IDC_DELETE );
hWndMethod = GetDlgItem( hDlg, IDC_AUTHMETHOD );
assert( hWndRealm && hWndList && hWndUser && hWndPassword );
assert( hWndConfirm && hWndAdd && hWndReplace && hWndDelete );
EnableWindow( hWndAdd, FALSE );
EnableWindow( hWndReplace, FALSE );
EnableWindow( hWndDelete, FALSE );
/*
** Limit edit field lengths, really just a sanity thing
*/
SendMessage( hWndUser, EM_SETLIMITTEXT, 256, 0 );
SendMessage( hWndPassword, EM_SETLIMITTEXT, 256, 0 );
SendMessage( hWndConfirm, EM_SETLIMITTEXT, 256, 0 );
/*
** Setup tabstops
*/
aTabstop[0] = 0;
aTabstop[1] = 750;
SendMessage( hWndList, LB_SETTABSTOPS, 2, (LPARAM)&aTabstop );
/*
** Load all realms into realm box
*/
for(int iTmp = 0;; iTmp++ ) {
const char *pTmp = M_LookupValueEx( pConfig, "Realms", "Basic", iTmp );
if ( !pTmp ) { break; };
SendMessage( hWndRealm, CB_ADDSTRING, 0, (LPARAM)pTmp );
};
for(iTmp = 0;; iTmp++ ) {
const char *pTmp = M_LookupValueEx( pConfig, "Realms", "Digest", iTmp );
if ( !pTmp ) { break; };
SendMessage( hWndRealm, CB_ADDSTRING, 0, (LPARAM)pTmp );
};
for(iTmp = 0;; iTmp++ ) {
const char *pTmp = M_LookupValueEx( pConfig, "Realms", "Ntlm", iTmp );
if ( !pTmp ) { break; };
SendMessage( hWndRealm, CB_ADDSTRING, 0, (LPARAM)pTmp );
};
/*
** Load all users into realm box
*/
if ( SendMessage( hWndRealm, CB_GETCOUNT, 0, 0 )>0 )
{
SendMessage( hWndRealm, CB_SETCURSEL, 0, 0 );
*szBuf = '\0';
SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE,
(LPARAM)szBuf );
/*
** Load items into list box
*/
Internal_loadItems( szBuf );
/*
** update static method text for realm
*/
if ( Internal_findMethod( szBuf ))
{
SendMessage( hWndMethod, WM_SETTEXT, 0,
(LPARAM)szBuf );
if (!strcmp(szBuf,"Ntlm"))
{
EnableWindow( hWndUser, FALSE);
EnableWindow( hWndPassword, FALSE );
EnableWindow( hWndConfirm, FALSE );
}
}
}
else
{
/* --- no realms, disable edit fields --- */
EnableWindow( hWndUser, FALSE );
EnableWindow( hWndPassword, FALSE );
EnableWindow( hWndConfirm, FALSE );
};
}
HourglassOff();
break;
case WM_DESTROY:
{ Internal_clearArrays(); };
break;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case IDC_REALM:
switch( GET_WM_COMMAND_CMD(wParam, lParam) )
{
case CBN_DROPDOWN:
/*
** Save current realm users
*/
*szBuf = '\0';
SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE,
(LPARAM)szBuf );
Internal_saveItems( szBuf );
break;
case CBN_SELCHANGE:
/*
** Load new realm users
*/
*szBuf = '\0';
SendMessage( hWndRealm, WM_GETTEXT,
BUF_SIZE, (LPARAM)szBuf );
if ( SendMessage( hWndRealm, CB_GETCURSEL, 0,
0 )!= CB_ERR )
{
EnableWindow( hWndUser, TRUE );
EnableWindow( hWndPassword, TRUE );
EnableWindow( hWndConfirm, TRUE );
};
Internal_loadItems( szBuf );
/*
** update static method text for realm
*/
if ( Internal_findMethod( szBuf ))
{
SendMessage( hWndMethod, WM_SETTEXT, 0,
(LPARAM)szBuf );
if (!strcmp(szBuf,"Ntlm"))
{
EnableWindow( hWndUser, FALSE);
EnableWindow( hWndPassword, FALSE );
EnableWindow( hWndConfirm, FALSE );
}
}
break;
default:;
};
break;
case IDC_NEW:
if ( DialogBoxParam(
tPsp.hInstance,
MAKEINTRESOURCE( IDD_NEWREALM ),
hDlg,
(DLGPROC)fnNewRealmDialogProc,
(LPARAM)this
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -