From 634d3003f7bb1ab297aadf862acb915785f385c2 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 16 Feb 2008 17:05:24 +0000 Subject: [PATCH] (init_user_info): Use TOKEN_USER and TOKEN_PRIMARY_GROUP instead of char arrays. Enlarge the size of array passed to get_token_information. --- src/ChangeLog | 4 ++++ src/w32.c | 24 +++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index bfe82a0d2a..eee3f678e5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2008-02-16 Eli Zaretskii + * w32.c (init_user_info): Use TOKEN_USER and TOKEN_PRIMARY_GROUP + instead of char arrays. Enlarge the size of array passed to + get_token_information. + * font.c (Ffont_fill_gstring, Fget_font_glyphs): Fix compilation warnings. diff --git a/src/w32.c b/src/w32.c index 2395c23676..4873311e86 100644 --- a/src/w32.c +++ b/src/w32.c @@ -73,6 +73,7 @@ Boston, MA 02110-1301, USA. #define _ANONYMOUS_STRUCT #endif #include +#include #include #ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */ @@ -594,16 +595,20 @@ init_user_info () the user-sid as the user id value (same for group id using the primary group sid from the process token). */ - char user_sid[256], name[256], domain[256]; + char name[UNLEN+1], domain[1025]; DWORD length = sizeof (name), dlength = sizeof (domain), trash; HANDLE token = NULL; SID_NAME_USE user_type; + unsigned char buf[1024]; + TOKEN_USER user_token; + TOKEN_PRIMARY_GROUP group_token; if (open_process_token (GetCurrentProcess (), TOKEN_QUERY, &token) && get_token_information (token, TokenUser, - (PVOID) user_sid, sizeof (user_sid), &trash) - && lookup_account_sid (NULL, *((PSID *) user_sid), name, &length, - domain, &dlength, &user_type)) + (PVOID)buf, sizeof (buf), &trash) + && (memcpy (&user_token, buf, sizeof (user_token)), + lookup_account_sid (NULL, user_token.User.Sid, name, &length, + domain, &dlength, &user_type))) { strcpy (the_passwd.pw_name, name); /* Determine a reasonable uid value. */ @@ -617,14 +622,14 @@ init_user_info () /* Use the last sub-authority value of the RID, the relative portion of the SID, as user/group ID. */ DWORD n_subauthorities = - *get_sid_sub_authority_count (*((PSID *) user_sid)); + *get_sid_sub_authority_count (user_token.User.Sid); if (n_subauthorities < 1) the_passwd.pw_uid = 0; /* the "World" RID */ else { the_passwd.pw_uid = - *get_sid_sub_authority (*((PSID *) user_sid), + *get_sid_sub_authority (user_token.User.Sid, n_subauthorities - 1); /* Restrict to conventional uid range for normal users. */ the_passwd.pw_uid %= 60001; @@ -632,17 +637,18 @@ init_user_info () /* Get group id */ if (get_token_information (token, TokenPrimaryGroup, - (PVOID) user_sid, sizeof (user_sid), &trash)) + (PVOID)buf, sizeof (buf), &trash)) { + memcpy (&group_token, buf, sizeof (group_token)); n_subauthorities = - *get_sid_sub_authority_count (*((PSID *) user_sid)); + *get_sid_sub_authority_count (group_token.PrimaryGroup); if (n_subauthorities < 1) the_passwd.pw_gid = 0; /* the "World" RID */ else { the_passwd.pw_gid = - *get_sid_sub_authority (*((PSID *) user_sid), + *get_sid_sub_authority (group_token.PrimaryGroup, n_subauthorities - 1); /* I don't know if this is necessary, but for safety... */ the_passwd.pw_gid %= 60001; -- 2.20.1