Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2003.10.30;
Скачать: [xml.tar.bz2];

Вниз

Работа с учетными записями   Найти похожие ветки 

 
aldapooh   (2003-08-22 14:22) [0]

Добрый день! Есть сеть, есть домен. Нужно сделать чтобы дельфовская программа перед запуском спрашивала логин и пароль пользователя и только если есть такая учетная запись программа запускалась.
Как лучше получить эту информацию? Любые вашт рекомендации и советы, ссылки и тд.
Спасибо!


 
Игорь Шевченко   (2003-08-22 14:23) [1]

Зачем ?


 
aldapooh   (2003-08-22 14:25) [2]

Хорошо, скажем так... Логин и пароль должны совпадать с теми которые заданы сисадмином, как я могу это проверить?


 
Игорь Шевченко   (2003-08-22 14:27) [3]

Ничего не понятно. Зачем нужно решение такой задачи ? (Кроме подбора паролей к имеющимся учетным записям) ?


 
aldapooh   (2003-08-22 14:37) [4]

Нет, мне не нужны ни пароли, ничего такого.
Есть база данных, там прописаны права для пользователей. А подключаюсь я к базе через ADO используя integrated security. На самом деле можно было бы кадый раз делать Log Off Log In в Винде, чтобы менять имя учетной записи, но так как делать это приходиться часто, то логично было бы сделать вход в программу с теми же параметрами что и в винду (Логин пароль домен), так вот как проверить может ли данный человек работать с программой или нет.
Очень не хочу попасть в орехи :)


 
Игорь Шевченко   (2003-08-22 14:40) [5]

Есть у меня подозрение, что integrated security не даст подключиться с другой учетной записью, кроме текущей..Или я ошибаюсь ?


 
aldapooh   (2003-08-22 14:43) [6]

ну так если я сделаю как хочу то флажок переставлю на "use a specific user name and password"
Вы мне лучше скажите вообще возможно ли то что я задумал...


 
Игорь Шевченко   (2003-08-22 14:50) [7]

Возможно. Через функции SSPI, точного названия функции не помню


 
aldapooh   (2003-08-22 14:53) [8]

ну спасибо и на том! если вдруг вспомните или советк какой дадите буду благодарен!


 
Игорь Шевченко   (2003-08-22 15:14) [9]

#define _WIN32_WINNT 0x500
#define UNICODE
#include <windows.h>
#include <stdio.h>
#define SECURITY_WIN32
#include <security.h>
#pragma comment(lib, "secur32.lib")

// brain-dead error routine that dumps the last error and exits
void _err(const wchar_t* pszFcn, DWORD nErr = GetLastError())
{
wchar_t szErr[256];
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, nErr, 0,
szErr, sizeof szErr / sizeof *szErr, 0))
wprintf(L"%s failed: %s", pszFcn, szErr);
else wprintf(L"%s failed: 0x%08X", nErr);
exit(1);
}

// Upon success, returns a handle to a NETWORK logon session
// for the specified principal (it will *not* have network
// credentials). Call CloseHandle to dispose of it when
// you are finished.
HANDLE _logonUserWithSSPI(wchar_t* pszSSP,
DWORD grfDesiredAccessToToken,
wchar_t* pszAuthority,
wchar_t* pszPrincipal,
wchar_t* pszPassword) {

// the following code loads the SSPI interface DLL
// and initializes it, getting a table of function ptrs
HINSTANCE hdll = LoadLibrary(L"security.dll");
if (!hdll)
_err(L"LoadLibrary");
INIT_SECURITY_INTERFACE_W initSecurityInterface =
(INIT_SECURITY_INTERFACE_W)GetProcAddress(hdll,
SECURITY_ENTRYPOINT_ANSIW);
if (!initSecurityInterface)
_err(L"GetProcAddress");
PSecurityFunctionTable pSSPI = initSecurityInterface();

// here"s where we specify the credentials to verify
SEC_WINNT_AUTH_IDENTITY_EX authIdent = {
SEC_WINNT_AUTH_IDENTITY_VERSION,
sizeof authIdent,
pszPrincipal, lstrlenW(pszPrincipal),
pszAuthority, lstrlenW(pszAuthority),
pszPassword, lstrlenW(pszPassword),
SEC_WINNT_AUTH_IDENTITY_UNICODE,
0, 0
};

// get an SSPI handle for these credentials
CredHandle hcredClient;
TimeStamp expiryClient;
SECURITY_STATUS err =
pSSPI->AcquireCredentialsHandle(0, pszSSP, SECPKG_CRED_OUTBOUND,
0, &authIdent, 0, 0,
&hcredClient, &expiryClient);
if (err)
_err(L"AcquireCredentialsHandle for client", err);

// use the caller"s credentials for the server
CredHandle hcredServer;
TimeStamp expiryServer;
err = pSSPI->AcquireCredentialsHandle(0, pszSSP, SECPKG_CRED_INBOUND,
0, 0, 0, 0, &hcredServer,
&expiryServer);
if (err)
_err(L"AcquireCredentialsHandle for server", err);

CtxtHandle hctxClient;
CtxtHandle hctxServer;

// create two buffers:
// one for the client sending tokens to the server,
// one for the server sending tokens to the client
// (buffer size chosen based on current Kerb SSP setting
// for cbMaxToken - you may need to adjust this)
BYTE bufC2S[8000];
BYTE bufS2C[8000];
SecBuffer sbufC2S = { sizeof bufC2S, SECBUFFER_TOKEN, bufC2S };
SecBuffer sbufS2C = { sizeof bufS2C, SECBUFFER_TOKEN, bufS2C };
SecBufferDesc bdC2S = { SECBUFFER_VERSION, 1, &sbufC2S };
SecBufferDesc bdS2C = { SECBUFFER_VERSION, 1, &sbufS2C };

// don"t really need any special context attributes
DWORD grfRequiredCtxAttrsClient = ISC_REQ_CONNECTION;
DWORD grfRequiredCtxAttrsServer = ISC_REQ_CONNECTION;

// set up some aliases to make it obvious what"s happening
PCtxtHandle pClientCtxHandleIn = 0;
PCtxtHandle pClientCtxHandleOut = &hctxClient;
PCtxtHandle pServerCtxHandleIn = 0;
PCtxtHandle pServerCtxHandleOut = &hctxServer;
SecBufferDesc* pClientInput = 0;
SecBufferDesc* pClientOutput = &bdC2S;
SecBufferDesc* pServerInput = &bdC2S;
SecBufferDesc* pServerOutput = &bdS2C;
DWORD grfCtxAttrsClient = 0;
DWORD grfCtxAttrsServer = 0;
TimeStamp expiryClientCtx;
TimeStamp expiryServerCtx;

// since the caller is acting as the server, we need
// a server principal name so that the client will
// be able to get a Kerb ticket (if Kerb is used)
wchar_t szSPN[256];
ULONG cchSPN = sizeof szSPN / sizeof *szSPN;
GetUserNameEx(NameSamCompatible, szSPN, &cchSPN);

// perform the authentication handshake, playing the
// role of both client *and* server.
bool bClientContinue = true;
bool bServerContinue = true;
while (bClientContinue || bServerContinue) {
if (bClientContinue) {
sbufC2S.cbBuffer = sizeof bufC2S;
err = pSSPI->InitializeSecurityContext(
&hcredClient, pClientCtxHandleIn,
szSPN,
grfRequiredCtxAttrsClient,
0, SECURITY_NATIVE_DREP,
pClientInput, 0,
pClientCtxHandleOut,
pClientOutput,
&grfCtxAttrsClient,
&expiryClientCtx);
switch (err) {
case 0:
bClientContinue = false;
break;
case SEC_I_CONTINUE_NEEDED:
pClientCtxHandleIn = pClientCtxHandleOut;
pClientInput = pServerOutput;
break;
default:
_err(L"InitializeSecurityContext", err);
}
}

if (bServerContinue) {
sbufS2C.cbBuffer = sizeof bufS2C;
err = pSSPI->AcceptSecurityContext(
&hcredServer, pServerCtxHandleIn,
pServerInput,
grfRequiredCtxAttrsServer,
SECURITY_NATIVE_DREP,
pServerCtxHandleOut,
pServerOutput,
&grfCtxAttrsServer,
&expiryServerCtx);
switch (err) {
case 0:
bServerContinue = false;
break;
case SEC_I_CONTINUE_NEEDED:
pServerCtxHandleIn = pServerCtxHandleOut;
break;
default:
_err(L"AcceptSecurityContext", err);
}
}
}
// if everything has gone smoothly, we"ve now got a logon
// session for the client - let"s grab the token now
pSSPI->ImpersonateSecurityContext(pServerCtxHandleOut);
HANDLE htok;
if (!OpenThreadToken(GetCurrentThread(),
grfDesiredAccessToToken,
TRUE, &htok))
_err(L"OpenThreadToken");

// clean up
pSSPI->FreeCredentialsHandle(&hcredClient);
pSSPI->FreeCredentialsHandle(&hcredServer);
pSSPI->DeleteSecurityContext(pServerCtxHandleOut);
pSSPI->DeleteSecurityContext(pClientCtxHandleOut);

return htok;
}

// here"s an example of usage
void main() {
// use "NTLM" or "Kerberos"
HANDLE htok = _logonUserWithSSPI(L"Kerberos",
TOKEN_QUERY,
L"bar.com",
L"alice",
L"alice");
CloseHandle(htok);
}


 
aldapooh   (2003-08-23 10:07) [10]

супер пупер спасибо! большое спасибо!


 
aldapooh   (2003-08-23 13:39) [11]

вот кстати нашел CredUIPromptForCredentials и CredUIConfirmCredentials в MSDN. мне кажется эти функции тоже могут мне помочь в данной ситуации, или я ошибаюсь?


 
aldapooh   (2003-08-25 10:24) [12]

самый глупый вопрос на свете - в какой библиотеке эти функции я могу взять чтобы использовать в Delphi?



Страницы: 1 вся ветка

Форум: "WinAPI";
Текущий архив: 2003.10.30;
Скачать: [xml.tar.bz2];

Наверх




Память: 0.49 MB
Время: 0.011 c
14-98794
Stariy
2003-10-12 21:21
2003.10.30
Delphi и стертый текст в Word


3-98501
Данила
2003-10-09 13:18
2003.10.30
ProgressBar во время SQL запроса.


1-98632
SPIRIT
2003-10-16 03:36
2003.10.30
TDriveCombobox или другие способы определения жестких дисков!!!


1-98642
tania
2003-10-17 13:07
2003.10.30
Разработка Com приложений в Delphi


4-98923
aldapooh
2003-08-26 12:01
2003.10.30
Работа с учетными записями (продолжение)





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский