aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-01-08 15:26:40 +0000
committerRon Yorston <rmy@pobox.com>2019-01-08 15:26:40 +0000
commit64a2959683ae6f876966ff81cbd87b1efd14de9d (patch)
tree71bf971430ab3d61c677de193bb3a1536dc6e057
parent26a1f54837da021aeeb72680acb2feb4ea1e02da (diff)
downloadbusybox-w32-64a2959683ae6f876966ff81cbd87b1efd14de9d.tar.gz
busybox-w32-64a2959683ae6f876966ff81cbd87b1efd14de9d.tar.bz2
busybox-w32-64a2959683ae6f876966ff81cbd87b1efd14de9d.zip
win32: add a fake root user and group
-rw-r--r--win32/mingw.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index c72a306ac..2a5f96c31 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -779,44 +779,57 @@ struct passwd *getpwnam(const char *name)
779 strcmp(myname, name) == 0 ) { 779 strcmp(myname, name) == 0 ) {
780 return getpwuid(DEFAULT_UID); 780 return getpwuid(DEFAULT_UID);
781 } 781 }
782 else if (strcmp(name, "root") == 0) {
783 return getpwuid(0);
784 }
782 785
783 return NULL; 786 return NULL;
784} 787}
785 788
786struct passwd *getpwuid(uid_t uid UNUSED_PARAM) 789struct passwd *getpwuid(uid_t uid)
787{ 790{
788 static struct passwd p; 791 static struct passwd p;
789 792
790 if ( (p.pw_name=get_user_name()) == NULL ) { 793 if (uid == 0) {
794 p.pw_name = (char *)"root";
795 p.pw_dir = (char *)"/";
796 }
797 else if (uid == DEFAULT_UID && (p.pw_name=get_user_name()) != NULL) {
798 p.pw_dir = gethomedir();
799 }
800 else {
791 return NULL; 801 return NULL;
792 } 802 }
793 p.pw_passwd = (char *)"secret"; 803
794 p.pw_gecos = (char *)"unknown"; 804 p.pw_passwd = (char *)"";
795 p.pw_dir = gethomedir(); 805 p.pw_gecos = p.pw_name;
796 p.pw_shell = NULL; 806 p.pw_shell = NULL;
797 p.pw_uid = DEFAULT_UID; 807 p.pw_uid = uid;
798 p.pw_gid = DEFAULT_GID; 808 p.pw_gid = uid;
799 809
800 return &p; 810 return &p;
801} 811}
802 812
803struct group *getgrgid(gid_t gid UNUSED_PARAM) 813struct group *getgrgid(gid_t gid)
804{ 814{
805 static char *members[2] = { NULL, NULL }; 815 static char *members[2] = { NULL, NULL };
806 static struct group g; 816 static struct group g;
807 817
808 if ( (g.gr_name=get_user_name()) == NULL ) { 818 if (gid == 0) {
819 g.gr_name = (char *)"root";
820 }
821 else if (gid != DEFAULT_GID || (g.gr_name=get_user_name()) == NULL) {
809 return NULL; 822 return NULL;
810 } 823 }
811 g.gr_passwd = (char *)"secret"; 824 g.gr_passwd = (char *)"";
812 g.gr_gid = DEFAULT_GID; 825 g.gr_gid = gid;
813 members[0] = g.gr_name; 826 members[0] = g.gr_name;
814 g.gr_mem = members; 827 g.gr_mem = members;
815 828
816 return &g; 829 return &g;
817} 830}
818 831
819int getgrouplist(const char *user UNUSED_PARAM, gid_t group UNUSED_PARAM, 832int getgrouplist(const char *user UNUSED_PARAM, gid_t group,
820 gid_t *groups, int *ngroups) 833 gid_t *groups, int *ngroups)
821{ 834{
822 if ( *ngroups == 0 ) { 835 if ( *ngroups == 0 ) {
@@ -825,7 +838,7 @@ int getgrouplist(const char *user UNUSED_PARAM, gid_t group UNUSED_PARAM,
825 } 838 }
826 839
827 *ngroups = 1; 840 *ngroups = 1;
828 groups[0] = DEFAULT_GID; 841 groups[0] = group;
829 return 1; 842 return 1;
830} 843}
831 844