aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2008-01-26 13:04:14 +0000
committerEli Zaretskii2008-01-26 13:04:14 +0000
commitc617afcea160aeeaa8b00d4181fe784069a888d4 (patch)
tree7adc803e98cbca8715e56e56520baa30394f3cb0 /src
parent304484e4a0ba830c56a040cf8e137120573215a5 (diff)
downloademacs-c617afcea160aeeaa8b00d4181fe784069a888d4.tar.gz
emacs-c617afcea160aeeaa8b00d4181fe784069a888d4.zip
(g_b_init_get_sid_sub_authority, g_b_init_get_sid_sub_authority_count): New
static variables. (GetSidSubAuthority_Proc, GetSidSubAuthorityCount_Proc): New typedefs. (get_sid_sub_authority, get_sid_sub_authority_count): New functions. (init_user_info): Use the above two new functions to retrieve uid and gid. Use 500/513, the Windows defaults, as Administrator's uid/gid.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog10
-rw-r--r--src/w32.c111
2 files changed, 98 insertions, 23 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 469bc632182..9f620aae33e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
12008-01-26 Eli Zaretskii <eliz@gnu.org>
2
3 * w32.c (g_b_init_get_sid_sub_authority)
4 (g_b_init_get_sid_sub_authority_count): New static variables.
5 (GetSidSubAuthority_Proc, GetSidSubAuthorityCount_Proc): New typedefs.
6 (get_sid_sub_authority, get_sid_sub_authority_count): New functions.
7 (init_user_info): Use the above two new functions to retrieve uid
8 and gid. Use 500/513, the Windows defaults, as Administrator's
9 uid/gid.
10
12008-01-26 Jason Rumney <jasonr@gnu.org> 112008-01-26 Jason Rumney <jasonr@gnu.org>
2 12
3 * w32.c (logon_network_drive): New function. 13 * w32.c (logon_network_drive): New function.
diff --git a/src/w32.c b/src/w32.c
index f1be902707e..88c9c78316d 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -120,6 +120,8 @@ static BOOL g_b_init_open_process_token;
120static BOOL g_b_init_get_token_information; 120static BOOL g_b_init_get_token_information;
121static BOOL g_b_init_lookup_account_sid; 121static BOOL g_b_init_lookup_account_sid;
122static BOOL g_b_init_get_sid_identifier_authority; 122static BOOL g_b_init_get_sid_identifier_authority;
123static BOOL g_b_init_get_sid_sub_authority;
124static BOOL g_b_init_get_sid_sub_authority_count;
123 125
124/* 126/*
125 BEGIN: Wrapper functions around OpenProcessToken 127 BEGIN: Wrapper functions around OpenProcessToken
@@ -161,6 +163,12 @@ typedef BOOL (WINAPI * LookupAccountSid_Proc) (
161 PSID_NAME_USE peUse); 163 PSID_NAME_USE peUse);
162typedef PSID_IDENTIFIER_AUTHORITY (WINAPI * GetSidIdentifierAuthority_Proc) ( 164typedef PSID_IDENTIFIER_AUTHORITY (WINAPI * GetSidIdentifierAuthority_Proc) (
163 PSID pSid); 165 PSID pSid);
166typedef PDWORD (WINAPI * GetSidSubAuthority_Proc) (
167 PSID pSid,
168 DWORD n);
169typedef PUCHAR (WINAPI * GetSidSubAuthorityCount_Proc) (
170 PSID pSid);
171
164 172
165 /* ** A utility function ** */ 173 /* ** A utility function ** */
166static BOOL 174static BOOL
@@ -349,6 +357,55 @@ PSID_IDENTIFIER_AUTHORITY WINAPI get_sid_identifier_authority (
349 return (s_pfn_Get_Sid_Identifier_Authority (pSid)); 357 return (s_pfn_Get_Sid_Identifier_Authority (pSid));
350} 358}
351 359
360PDWORD WINAPI get_sid_sub_authority (
361 PSID pSid,
362 DWORD n)
363{
364 static GetSidSubAuthority_Proc s_pfn_Get_Sid_Sub_Authority = NULL;
365 HMODULE hm_advapi32 = NULL;
366 if (is_windows_9x () == TRUE)
367 {
368 return NULL;
369 }
370 if (g_b_init_get_sid_sub_authority == 0)
371 {
372 g_b_init_get_sid_sub_authority = 1;
373 hm_advapi32 = LoadLibrary ("Advapi32.dll");
374 s_pfn_Get_Sid_Sub_Authority =
375 (GetSidSubAuthority_Proc) GetProcAddress (
376 hm_advapi32, "GetSidSubAuthority");
377 }
378 if (s_pfn_Get_Sid_Sub_Authority == NULL)
379 {
380 return NULL;
381 }
382 return (s_pfn_Get_Sid_Sub_Authority (pSid, n));
383}
384
385PUCHAR WINAPI get_sid_sub_authority_count (
386 PSID pSid)
387{
388 static GetSidSubAuthorityCount_Proc s_pfn_Get_Sid_Sub_Authority_Count = NULL;
389 HMODULE hm_advapi32 = NULL;
390 if (is_windows_9x () == TRUE)
391 {
392 return NULL;
393 }
394 if (g_b_init_get_sid_sub_authority_count == 0)
395 {
396 g_b_init_get_sid_sub_authority_count = 1;
397 hm_advapi32 = LoadLibrary ("Advapi32.dll");
398 s_pfn_Get_Sid_Sub_Authority_Count =
399 (GetSidSubAuthorityCount_Proc) GetProcAddress (
400 hm_advapi32, "GetSidSubAuthorityCount");
401 }
402 if (s_pfn_Get_Sid_Sub_Authority_Count == NULL)
403 {
404 return NULL;
405 }
406 return (s_pfn_Get_Sid_Sub_Authority_Count (pSid));
407}
408
352/* 409/*
353 END: Wrapper functions around OpenProcessToken 410 END: Wrapper functions around OpenProcessToken
354 and other functions in advapi32.dll that are only 411 and other functions in advapi32.dll that are only
@@ -547,39 +604,47 @@ init_user_info ()
547 domain, &dlength, &user_type)) 604 domain, &dlength, &user_type))
548 { 605 {
549 strcpy (the_passwd.pw_name, name); 606 strcpy (the_passwd.pw_name, name);
550 /* Determine a reasonable uid value. */ 607 /* Determine a reasonable uid value. */
551 if (stricmp ("administrator", name) == 0) 608 if (stricmp ("administrator", name) == 0)
552 { 609 {
553 the_passwd.pw_uid = 0; 610 the_passwd.pw_uid = 500; /* well-known Administrator uid */
554 the_passwd.pw_gid = 0; 611 the_passwd.pw_gid = 513; /* well-known None gid */
555 } 612 }
556 else 613 else
557 { 614 {
558 SID_IDENTIFIER_AUTHORITY * pSIA; 615 /* Use RID, the relative portion of the SID, that is the last
559 616 sub-authority value of the SID. */
560 pSIA = get_sid_identifier_authority (*((PSID *) user_sid)); 617 DWORD n_subauthorities =
561 /* I believe the relative portion is the last 4 bytes (of 6) 618 *get_sid_sub_authority_count (*((PSID *) user_sid));
562 with msb first. */ 619
563 the_passwd.pw_uid = ((pSIA->Value[2] << 24) + 620 if (n_subauthorities < 1)
564 (pSIA->Value[3] << 16) + 621 the_passwd.pw_uid = 0; /* the "World" RID */
565 (pSIA->Value[4] << 8) + 622 else
566 (pSIA->Value[5] << 0)); 623 {
567 /* restrict to conventional uid range for normal users */ 624 the_passwd.pw_uid =
568 the_passwd.pw_uid = the_passwd.pw_uid % 60001; 625 *get_sid_sub_authority (*((PSID *) user_sid),
626 n_subauthorities - 1);
627 /* Restrict to conventional uid range for normal users. */
628 the_passwd.pw_uid %= 60001;
629 }
569 630
570 /* Get group id */ 631 /* Get group id */
571 if (get_token_information (token, TokenPrimaryGroup, 632 if (get_token_information (token, TokenPrimaryGroup,
572 (PVOID) user_sid, sizeof (user_sid), &trash)) 633 (PVOID) user_sid, sizeof (user_sid), &trash))
573 { 634 {
574 SID_IDENTIFIER_AUTHORITY * pSIA; 635 n_subauthorities =
575 636 *get_sid_sub_authority_count (*((PSID *) user_sid));
576 pSIA = get_sid_identifier_authority (*((PSID *) user_sid)); 637
577 the_passwd.pw_gid = ((pSIA->Value[2] << 24) + 638 if (n_subauthorities < 1)
578 (pSIA->Value[3] << 16) + 639 the_passwd.pw_gid = 0; /* the "World" RID */
579 (pSIA->Value[4] << 8) + 640 else
580 (pSIA->Value[5] << 0)); 641 {
581 /* I don't know if this is necessary, but for safety... */ 642 the_passwd.pw_gid =
582 the_passwd.pw_gid = the_passwd.pw_gid % 60001; 643 *get_sid_sub_authority (*((PSID *) user_sid),
644 n_subauthorities - 1);
645 /* I don't know if this is necessary, but for safety... */
646 the_passwd.pw_gid %= 60001;
647 }
583 } 648 }
584 else 649 else
585 the_passwd.pw_gid = the_passwd.pw_uid; 650 the_passwd.pw_gid = the_passwd.pw_uid;