aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2008-05-09 09:40:56 +0000
committerEli Zaretskii2008-05-09 09:40:56 +0000
commit07f7980ac302dfe315d28923f0f2b77a42e80ece (patch)
tree0372068d2b8239d8dde7d63f09d1934e7de0a4ba /src
parent927a444ee81ce5b433ba01a2a559187d52c11c42 (diff)
downloademacs-07f7980ac302dfe315d28923f0f2b77a42e80ece.tar.gz
emacs-07f7980ac302dfe315d28923f0f2b77a42e80ece.zip
Rename the_passwd_* to dflt_passwd_*.
(dflt_group_name): New static variable. (dflt_group): Renamed from the_group. (init_user_info): Init dflt_group fields. Get user's group name from LookupAccountSid.
Diffstat (limited to 'src')
-rw-r--r--src/w32.c106
1 files changed, 59 insertions, 47 deletions
diff --git a/src/w32.c b/src/w32.c
index 25756087a63..9b4d18afcfd 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -513,35 +513,38 @@ getloadavg (double loadavg[], int nelem)
513 513
514#define PASSWD_FIELD_SIZE 256 514#define PASSWD_FIELD_SIZE 256
515 515
516static char the_passwd_name[PASSWD_FIELD_SIZE]; 516static char dflt_passwd_name[PASSWD_FIELD_SIZE];
517static char the_passwd_passwd[PASSWD_FIELD_SIZE]; 517static char dflt_passwd_passwd[PASSWD_FIELD_SIZE];
518static char the_passwd_gecos[PASSWD_FIELD_SIZE]; 518static char dflt_passwd_gecos[PASSWD_FIELD_SIZE];
519static char the_passwd_dir[PASSWD_FIELD_SIZE]; 519static char dflt_passwd_dir[PASSWD_FIELD_SIZE];
520static char the_passwd_shell[PASSWD_FIELD_SIZE]; 520static char dflt_passwd_shell[PASSWD_FIELD_SIZE];
521 521
522static struct passwd the_passwd = 522static struct passwd dflt_passwd =
523{ 523{
524 the_passwd_name, 524 dflt_passwd_name,
525 the_passwd_passwd, 525 dflt_passwd_passwd,
526 0, 526 0,
527 0, 527 0,
528 0, 528 0,
529 the_passwd_gecos, 529 dflt_passwd_gecos,
530 the_passwd_dir, 530 dflt_passwd_dir,
531 the_passwd_shell, 531 dflt_passwd_shell,
532}; 532};
533 533
534static struct group the_group = 534static char dflt_group_name[GNLEN+1];
535
536static struct group dflt_group =
535{ 537{
536 /* There are no groups on NT, so we just return "root" as the 538 /* When group information is not available, we return this as the
537 group name. */ 539 group for all files. */
538 "root", 540 dflt_group_name,
541 0,
539}; 542};
540 543
541int 544int
542getuid () 545getuid ()
543{ 546{
544 return the_passwd.pw_uid; 547 return dflt_passwd.pw_uid;
545} 548}
546 549
547int 550int
@@ -556,7 +559,7 @@ geteuid ()
556int 559int
557getgid () 560getgid ()
558{ 561{
559 return the_passwd.pw_gid; 562 return dflt_passwd.pw_gid;
560} 563}
561 564
562int 565int
@@ -568,15 +571,15 @@ getegid ()
568struct passwd * 571struct passwd *
569getpwuid (int uid) 572getpwuid (int uid)
570{ 573{
571 if (uid == the_passwd.pw_uid) 574 if (uid == dflt_passwd.pw_uid)
572 return &the_passwd; 575 return &dflt_passwd;
573 return NULL; 576 return NULL;
574} 577}
575 578
576struct group * 579struct group *
577getgrgid (gid_t gid) 580getgrgid (gid_t gid)
578{ 581{
579 return &the_group; 582 return &dflt_group;
580} 583}
581 584
582struct passwd * 585struct passwd *
@@ -604,27 +607,30 @@ init_user_info ()
604 the user-sid as the user id value (same for group id using the 607 the user-sid as the user id value (same for group id using the
605 primary group sid from the process token). */ 608 primary group sid from the process token). */
606 609
607 char name[UNLEN+1], domain[1025]; 610 char uname[UNLEN+1], gname[GNLEN+1], domain[1025];
608 DWORD length = sizeof (name), dlength = sizeof (domain), trash; 611 DWORD ulength = sizeof (uname), dlength = sizeof (domain), trash;
612 DWORD glength = sizeof (gname);
609 HANDLE token = NULL; 613 HANDLE token = NULL;
610 SID_NAME_USE user_type; 614 SID_NAME_USE user_type;
611 unsigned char buf[1024]; 615 unsigned char buf[1024];
612 TOKEN_USER user_token; 616 TOKEN_USER user_token;
613 TOKEN_PRIMARY_GROUP group_token; 617 TOKEN_PRIMARY_GROUP group_token;
614 618
619 /* "None" is the default group name on standalone workstations. */
620 strcpy (dflt_group_name, "None");
615 if (open_process_token (GetCurrentProcess (), TOKEN_QUERY, &token) 621 if (open_process_token (GetCurrentProcess (), TOKEN_QUERY, &token)
616 && get_token_information (token, TokenUser, 622 && get_token_information (token, TokenUser,
617 (PVOID)buf, sizeof (buf), &trash) 623 (PVOID)buf, sizeof (buf), &trash)
618 && (memcpy (&user_token, buf, sizeof (user_token)), 624 && (memcpy (&user_token, buf, sizeof (user_token)),
619 lookup_account_sid (NULL, user_token.User.Sid, name, &length, 625 lookup_account_sid (NULL, user_token.User.Sid, uname, &ulength,
620 domain, &dlength, &user_type))) 626 domain, &dlength, &user_type)))
621 { 627 {
622 strcpy (the_passwd.pw_name, name); 628 strcpy (dflt_passwd.pw_name, uname);
623 /* Determine a reasonable uid value. */ 629 /* Determine a reasonable uid value. */
624 if (stricmp ("administrator", name) == 0) 630 if (stricmp ("administrator", uname) == 0)
625 { 631 {
626 the_passwd.pw_uid = 500; /* well-known Administrator uid */ 632 dflt_passwd.pw_uid = 500; /* well-known Administrator uid */
627 the_passwd.pw_gid = 513; /* well-known None gid */ 633 dflt_passwd.pw_gid = 513; /* well-known None gid */
628 } 634 }
629 else 635 else
630 { 636 {
@@ -634,10 +640,10 @@ init_user_info ()
634 *get_sid_sub_authority_count (user_token.User.Sid); 640 *get_sid_sub_authority_count (user_token.User.Sid);
635 641
636 if (n_subauthorities < 1) 642 if (n_subauthorities < 1)
637 the_passwd.pw_uid = 0; /* the "World" RID */ 643 dflt_passwd.pw_uid = 0; /* the "World" RID */
638 else 644 else
639 { 645 {
640 the_passwd.pw_uid = 646 dflt_passwd.pw_uid =
641 *get_sid_sub_authority (user_token.User.Sid, 647 *get_sid_sub_authority (user_token.User.Sid,
642 n_subauthorities - 1); 648 n_subauthorities - 1);
643 } 649 }
@@ -651,35 +657,41 @@ init_user_info ()
651 *get_sid_sub_authority_count (group_token.PrimaryGroup); 657 *get_sid_sub_authority_count (group_token.PrimaryGroup);
652 658
653 if (n_subauthorities < 1) 659 if (n_subauthorities < 1)
654 the_passwd.pw_gid = 0; /* the "World" RID */ 660 dflt_passwd.pw_gid = 0; /* the "World" RID */
655 else 661 else
656 { 662 {
657 the_passwd.pw_gid = 663 dflt_passwd.pw_gid =
658 *get_sid_sub_authority (group_token.PrimaryGroup, 664 *get_sid_sub_authority (group_token.PrimaryGroup,
659 n_subauthorities - 1); 665 n_subauthorities - 1);
660 } 666 }
667 dlength = sizeof (domain);
668 if (lookup_account_sid (NULL, group_token.PrimaryGroup,
669 gname, &glength, NULL, &dlength,
670 &user_type))
671 strcpy (dflt_group_name, gname);
661 } 672 }
662 else 673 else
663 the_passwd.pw_gid = the_passwd.pw_uid; 674 dflt_passwd.pw_gid = dflt_passwd.pw_uid;
664 } 675 }
665 } 676 }
666 /* If security calls are not supported (presumably because we 677 /* If security calls are not supported (presumably because we
667 are running under Windows 95), fallback to this. */ 678 are running under Windows 95), fallback to this. */
668 else if (GetUserName (name, &length)) 679 else if (GetUserName (uname, &ulength))
669 { 680 {
670 strcpy (the_passwd.pw_name, name); 681 strcpy (dflt_passwd.pw_name, uname);
671 if (stricmp ("administrator", name) == 0) 682 if (stricmp ("administrator", uname) == 0)
672 the_passwd.pw_uid = 0; 683 dflt_passwd.pw_uid = 0;
673 else 684 else
674 the_passwd.pw_uid = 123; 685 dflt_passwd.pw_uid = 123;
675 the_passwd.pw_gid = the_passwd.pw_uid; 686 dflt_passwd.pw_gid = dflt_passwd.pw_uid;
676 } 687 }
677 else 688 else
678 { 689 {
679 strcpy (the_passwd.pw_name, "unknown"); 690 strcpy (dflt_passwd.pw_name, "unknown");
680 the_passwd.pw_uid = 123; 691 dflt_passwd.pw_uid = 123;
681 the_passwd.pw_gid = 123; 692 dflt_passwd.pw_gid = 123;
682 } 693 }
694 dflt_group.gr_gid = dflt_passwd.pw_gid;
683 695
684 /* Ensure HOME and SHELL are defined. */ 696 /* Ensure HOME and SHELL are defined. */
685 if (getenv ("HOME") == NULL) 697 if (getenv ("HOME") == NULL)
@@ -688,8 +700,8 @@ init_user_info ()
688 abort (); 700 abort ();
689 701
690 /* Set dir and shell from environment variables. */ 702 /* Set dir and shell from environment variables. */
691 strcpy (the_passwd.pw_dir, getenv ("HOME")); 703 strcpy (dflt_passwd.pw_dir, getenv ("HOME"));
692 strcpy (the_passwd.pw_shell, getenv ("SHELL")); 704 strcpy (dflt_passwd.pw_shell, getenv ("SHELL"));
693 705
694 if (token) 706 if (token)
695 CloseHandle (token); 707 CloseHandle (token);
@@ -2727,8 +2739,8 @@ stat (const char * path, struct stat * buf)
2727 buf->st_ino = fake_inode; 2739 buf->st_ino = fake_inode;
2728 2740
2729 /* consider files to belong to current user */ 2741 /* consider files to belong to current user */
2730 buf->st_uid = the_passwd.pw_uid; 2742 buf->st_uid = dflt_passwd.pw_uid;
2731 buf->st_gid = the_passwd.pw_gid; 2743 buf->st_gid = dflt_passwd.pw_gid;
2732 2744
2733 /* volume_info is set indirectly by map_w32_filename */ 2745 /* volume_info is set indirectly by map_w32_filename */
2734 buf->st_dev = volume_info.serialnum; 2746 buf->st_dev = volume_info.serialnum;
@@ -2815,8 +2827,8 @@ fstat (int desc, struct stat * buf)
2815 buf->st_ino = fake_inode; 2827 buf->st_ino = fake_inode;
2816 2828
2817 /* consider files to belong to current user */ 2829 /* consider files to belong to current user */
2818 buf->st_uid = the_passwd.pw_uid; 2830 buf->st_uid = dflt_passwd.pw_uid;
2819 buf->st_gid = the_passwd.pw_gid; 2831 buf->st_gid = dflt_passwd.pw_gid;
2820 2832
2821 buf->st_dev = info.dwVolumeSerialNumber; 2833 buf->st_dev = info.dwVolumeSerialNumber;
2822 buf->st_rdev = info.dwVolumeSerialNumber; 2834 buf->st_rdev = info.dwVolumeSerialNumber;