Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.11.26;
Скачать: CL | DM;

Вниз

Ошибка 1332 - Пользователям не сопоставлены коды защиты данных   Найти похожие ветки 

 
Ildar ©   (2006-07-06 16:01) [0]

Люди, возникает ошибка при LookupAccountNameW(nil, Username, MypSid, cbSid, @RefDomain[0], cchDomain, peUse). Она возвращает значение False. Ошибка 1332 - Именам пользователей не сопоставлены коды защиты данных.
При отладке видно, что все поля заполняются нормально
Username:= StringToOleStr(MyUserName); заполняется нормально, но MessageBox(0, @Username, PChar("Error!"), MB_OK); показывает абракадабру.

sd объявлен в другом модуле и тамже происходит заполнение структуры TShareInfo502. Всё это сделано с целью расшаривания папки только для определённого опользователя.

Весь модуль:

unit untSecDesc;
interface
uses
 Windows, Messages, SysUtils, StrUtils, LM;

// functions
 function GetSD(MyDirectoryToShare: String; MyUserName: String): Integer;

implementation

type
   _ACE_HEADER = record
     AceType: BYTE;
     AceFlags: BYTE;
     AceSize: WORD;
   end;
   ACE_HEADER = ^_ACE_HEADER;
   PACE_HEADER = ^ACE_HEADER;

type
   _ACCESS_ALLOWED_ACE = record
     Header: ACE_HEADER;
     Mask: ACCESS_MASK;
     SidStart: DWORD;
   end;
   ACCESS_ALLOWED_ACE = ^_ACCESS_ALLOWED_ACE;

const
 RTN_OK: Integer = 0;
 RTN_USAGE: Integer = 1;
 RTN_ERROR: Integer = 13;

 SID_SIZE: Integer = 96;
 ACL_REVISION: Integer = 1;
//#pragma comment(lib,"NetApi32.lib")
// Note: UNICODE entry point and argv.  This way, we don"t need to bother
// with converting commandline args to Unicode //

//int __cdecl wmain(     int argc,     wchar_t *argv[]     )

function GetSD(MyDirectoryToShare: String; MyUserName: String): Integer;
var
 DirectoryToShare: LPWSTR;
//  Sharename: LPWSTR;
 Username: LPWSTR;
 Server: LPWSTR;
 MypSid: PSID; // !!!!!!!!!!!!!
 cbSid: DWORD;
 RefDomain: array [0..DNLEN] of WideChar;
 cchDomain: DWORD;
 peUse: SID_NAME_USE;
 sd: SECURITY_DESCRIPTOR;
 MypDacl: PACL; // !!!!!!!!!!!!!
 dwAclSize: DWORD;
 si502: SHARE_INFO_502;
 nas: NET_API_STATUS;
 bSuccess: BOOL; // assume this function fails
begin
 MypSid:= nil;
 cchDomain:= DNLEN+ 1;
 FillChar(RefDomain, SizeOf(RefDomain), #0);

 MypDacl:= nil;
 bSuccess:= False;
 //
 // since the commandline was Unicode, just provide pointers to
 // the relevant items
 //
 DirectoryToShare:= PWideChar(MyDirectoryToShare);
//  Username:= PWideChar(MyUserName);
 Username:= StringToOleStr(MyUserName);
 MessageBox(0, @Username, PChar("Error!"), MB_OK);
 //
 // initial allocation attempt for Sid
 //
 cbSid:= SID_SIZE;
 MypSid:= HeapAlloc(GetProcessHeap(), 0, cbSid);
// -----------------------------------------------------------------------------
 if  MypSid = nil then
 begin
   MessageBox(0, PChar("HeapAlloc error!"), PChar("Error!"), MB_OK);
   Exit;
 end;
// -----------------------------------------------------------------------------
       //
       // get the Sid associated with the supplied user/group name
       // force Unicode API since we always pass Unicode string
       //
// -----------------------------------------------------------------------------
 if not LookupAccountNameW(nil,  // default lookup logic
         Username,               // user/group of interest from commandline
         MypSid,                 // Sid buffer
         cbSid,                  // size of Sid
         @RefDomain[0],              // Domain account found on (unused)
         cchDomain,              // size of domain in chars
         peUse)
 then
 begin    //
          // if the buffer wasn"t large enough, try again
          //
          // ------------------------------------------------------------------
          if (GetLastError() = ERROR_INSUFFICIENT_BUFFER) then
          begin
            MypSid:= HeapReAlloc(GetProcessHeap(), 0, MypSid, cbSid);
            if(MypSid = nil) then
            begin
              MessageBox(0, PChar("HeapAlloc error!"), PChar("Error!"), MB_OK);
              Exit;
            end;
            cchDomain:= DNLEN+ 1;
            if not LookupAccountNameW(nil,  // default lookup logic
              Username,   // user/group of interest from commandline
              MypSid,       // Sid buffer
              cbSid,     // size of Sid
              @RefDomain[0],  // Domain account found on (unused)
              cchDomain, // size of domain in chars
              peUse)
            then
              begin
                MessageBox(0, PChar("1LookupAccountName error! Ошибка: "+ IntToStr(GetLastError()) + " - "+ SysErrorMessage(GetLastError())), PChar("Error!"), MB_OK);
                Exit;
              end;
          end
          else MessageBox(0, PChar("2LookupAccountName error! Ошибка: "+ IntToStr(GetLastError()) + " - "+ SysErrorMessage(GetLastError())), PChar("Error!"), MB_OK);
          // ------------------------------------------------------------------
         //
         // compute size of new acl
         //
 dwAclSize:= SizeOf(ACL) +1 * (SizeOf(ACCESS_ALLOWED_ACE) - SizeOf(DWORD)) + GetLengthSid(MypSid);
         //
         // allocate storage for Acl
         //
 MypDacl:= HeapAlloc(GetProcessHeap(), 0, dwAclSize);
 if MypDacl = nil then Exit;
 if not InitializeAcl(MypDacl^, dwAclSize, ACL_REVISION) then Exit;
         //
         // grant GENERIC_ALL (Full Control) access
         //
 if not AddAccessAllowedAce(MypDacl^, ACL_REVISION, GENERIC_ALL, MypSid) then Exit;
 if not InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION) then Exit;
 if not SetSecurityDescriptorDacl(@sd, TRUE, MypDacl, FALSE) then
 begin
   MessageBox(0, PChar("SetSecurityDescriptorDacl error! "+ SysErrorMessage(GetLastError())), PChar("Error!"), MB_OK);
   Exit;
 end;
         //
         // setup share info structure
         //
{          si502.shi502_netname:= LPTSTR(Sharename);
         si502.shi502_type:= STYPE_DISKTREE;
         si502.shi502_remark:= nil;
         si502.shi502_permissions:= 0;
         si502.shi502_max_uses:= SHI_USES_UNLIMITED;
         si502.shi502_current_uses:= 0;
         si502.shi502_path:= LPTSTR(DirectoryToShare);
         si502.shi502_passwd:= nil;
         si502.shi502_reserved:= 0;
         si502.shi502_security_descriptor:= @sd;
         nas:= NetShareAdd(LPTSTR(Server),         // share is on local machine
             502,            // info-level
             @si502,         // info-buffer
             nil             // don"t bother with parm
             );
             if nas <> NO_ERROR then
             begin
               MessageBox(0, PChar("NetShareAdd error! "+ SysErrorMessage(GetLastError())), PChar("Error!"), MB_OK);
               Exit;
             end;}
 end;
            bSuccess:= True;
            // indicate success
// cleanup:
            //     // free allocated resources     //
 if MypDacl <> nil then HeapFree(GetProcessHeap(), 0, MypDacl);
 if MypSid <> nil then HeapFree(GetProcessHeap(), 0, MypSid);
 if not bSuccess then Result:= RTN_ERROR else Result:= RTN_OK;
end;

end.


 
SoftMaker   (2006-07-06 16:26) [1]

Или я может быть неправильно что-то делаю?


 
Ildar ©   (2006-07-07 11:27) [2]

Этот вопрос решил, а вот теперь возникает ошибка при AddAccessAllowedAce 1344. Это значит, скорее всего, что размер dwAclSize определён неправильно. Кто-нибудь делал такое?

 dwAclSize:= SizeOf(ACL) + 1 * (SizeOf(ACCESS_ALLOWED_ACE) - SizeOf(DWORD)) + GetLengthSid(MypSid) ;

 MypDacl:= HeapAlloc(GetProcessHeap(), 0, dwAclSize);
 if MypDacl = nil then Exit;
 if not InitializeAcl(MypDacl^, dwAclSize, ACL_REVISION) then Exit;
 if not AddAccessAllowedAce(MypDacl^, ACL_REVISION, GENERIC_ALL, MypSid) then
 begin
   MessageBox(0, PChar("AddAccessAllowedAce error! № "+ IntToStr(GetLastError())+ " - "+ SysErrorMessage(GetLastError())), PChar("Error!"), MB_OK);
   // 1344 ERROR_ALLOTTED_SPACE_EXCEEDED
   Exit;
 end;



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

Текущий архив: 2006.11.26;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.052 c
2-1162989241
***mikle***
2006-11-08 15:34
2006.11.26
видно руки у меня совсем кривые!


15-1162909504
TIF
2006-11-07 17:25
2006.11.26
У кого есть опыт борьбы с троянами-шутдаунерами?


2-1162805595
alucard
2006-11-06 12:33
2006.11.26
Подскажите чем лучше сделать клиент серверное приложение


2-1163063007
Marat
2006-11-09 12:03
2006.11.26
Как проверить наличиетаблицы


15-1162970107
Некто_
2006-11-08 10:15
2006.11.26
Нужна простенькая программка для работы с *.dbf