comparison src/w32.c @ 91878:a5f49adf9035

(init_user_info): Use TOKEN_USER and TOKEN_PRIMARY_GROUP instead of char arrays. Enlarge the size of array passed to get_token_information.
author Eli Zaretskii <eliz@gnu.org>
date Sat, 16 Feb 2008 17:04:22 +0000
parents 7c4da276fe17
children 0249dbc614f0
comparison
equal deleted inserted replaced
91877:66415e9a068a 91878:a5f49adf9035
71 #ifdef __GNUC__ 71 #ifdef __GNUC__
72 #define _ANONYMOUS_UNION 72 #define _ANONYMOUS_UNION
73 #define _ANONYMOUS_STRUCT 73 #define _ANONYMOUS_STRUCT
74 #endif 74 #endif
75 #include <windows.h> 75 #include <windows.h>
76 #include <lmcons.h>
76 #include <shlobj.h> 77 #include <shlobj.h>
77 78
78 #ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */ 79 #ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */
79 #include <sys/socket.h> 80 #include <sys/socket.h>
80 #undef socket 81 #undef socket
592 593
593 Use the relative portion of the identifier authority value from 594 Use the relative portion of the identifier authority value from
594 the user-sid as the user id value (same for group id using the 595 the user-sid as the user id value (same for group id using the
595 primary group sid from the process token). */ 596 primary group sid from the process token). */
596 597
597 char user_sid[256], name[256], domain[256]; 598 char name[UNLEN+1], domain[1025];
598 DWORD length = sizeof (name), dlength = sizeof (domain), trash; 599 DWORD length = sizeof (name), dlength = sizeof (domain), trash;
599 HANDLE token = NULL; 600 HANDLE token = NULL;
600 SID_NAME_USE user_type; 601 SID_NAME_USE user_type;
602 unsigned char buf[1024];
603 TOKEN_USER user_token;
604 TOKEN_PRIMARY_GROUP group_token;
601 605
602 if (open_process_token (GetCurrentProcess (), TOKEN_QUERY, &token) 606 if (open_process_token (GetCurrentProcess (), TOKEN_QUERY, &token)
603 && get_token_information (token, TokenUser, 607 && get_token_information (token, TokenUser,
604 (PVOID) user_sid, sizeof (user_sid), &trash) 608 (PVOID)buf, sizeof (buf), &trash)
605 && lookup_account_sid (NULL, *((PSID *) user_sid), name, &length, 609 && (memcpy (&user_token, buf, sizeof (user_token)),
606 domain, &dlength, &user_type)) 610 lookup_account_sid (NULL, user_token.User.Sid, name, &length,
611 domain, &dlength, &user_type)))
607 { 612 {
608 strcpy (the_passwd.pw_name, name); 613 strcpy (the_passwd.pw_name, name);
609 /* Determine a reasonable uid value. */ 614 /* Determine a reasonable uid value. */
610 if (stricmp ("administrator", name) == 0) 615 if (stricmp ("administrator", name) == 0)
611 { 616 {
615 else 620 else
616 { 621 {
617 /* Use the last sub-authority value of the RID, the relative 622 /* Use the last sub-authority value of the RID, the relative
618 portion of the SID, as user/group ID. */ 623 portion of the SID, as user/group ID. */
619 DWORD n_subauthorities = 624 DWORD n_subauthorities =
620 *get_sid_sub_authority_count (*((PSID *) user_sid)); 625 *get_sid_sub_authority_count (user_token.User.Sid);
621 626
622 if (n_subauthorities < 1) 627 if (n_subauthorities < 1)
623 the_passwd.pw_uid = 0; /* the "World" RID */ 628 the_passwd.pw_uid = 0; /* the "World" RID */
624 else 629 else
625 { 630 {
626 the_passwd.pw_uid = 631 the_passwd.pw_uid =
627 *get_sid_sub_authority (*((PSID *) user_sid), 632 *get_sid_sub_authority (user_token.User.Sid,
628 n_subauthorities - 1); 633 n_subauthorities - 1);
629 /* Restrict to conventional uid range for normal users. */ 634 /* Restrict to conventional uid range for normal users. */
630 the_passwd.pw_uid %= 60001; 635 the_passwd.pw_uid %= 60001;
631 } 636 }
632 637
633 /* Get group id */ 638 /* Get group id */
634 if (get_token_information (token, TokenPrimaryGroup, 639 if (get_token_information (token, TokenPrimaryGroup,
635 (PVOID) user_sid, sizeof (user_sid), &trash)) 640 (PVOID)buf, sizeof (buf), &trash))
636 { 641 {
642 memcpy (&group_token, buf, sizeof (group_token));
637 n_subauthorities = 643 n_subauthorities =
638 *get_sid_sub_authority_count (*((PSID *) user_sid)); 644 *get_sid_sub_authority_count (group_token.PrimaryGroup);
639 645
640 if (n_subauthorities < 1) 646 if (n_subauthorities < 1)
641 the_passwd.pw_gid = 0; /* the "World" RID */ 647 the_passwd.pw_gid = 0; /* the "World" RID */
642 else 648 else
643 { 649 {
644 the_passwd.pw_gid = 650 the_passwd.pw_gid =
645 *get_sid_sub_authority (*((PSID *) user_sid), 651 *get_sid_sub_authority (group_token.PrimaryGroup,
646 n_subauthorities - 1); 652 n_subauthorities - 1);
647 /* I don't know if this is necessary, but for safety... */ 653 /* I don't know if this is necessary, but for safety... */
648 the_passwd.pw_gid %= 60001; 654 the_passwd.pw_gid %= 60001;
649 } 655 }
650 } 656 }