diff options
author | Ron Yorston <rmy@pobox.com> | 2015-02-26 15:50:39 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2015-02-26 15:50:39 +0000 |
commit | 59abbf391be4ddaab0e0335b4f3691cc48590574 (patch) | |
tree | ceeea37fd680410c15689ce42e19ec62b7f5e69b | |
parent | 63dbf1908bc51918d9d963f4d9b7657306b2970d (diff) | |
download | busybox-w32-59abbf391be4ddaab0e0335b4f3691cc48590574.tar.gz busybox-w32-59abbf391be4ddaab0e0335b4f3691cc48590574.tar.bz2 busybox-w32-59abbf391be4ddaab0e0335b4f3691cc48590574.zip |
Make uid/gid handling more consistent
Various fake POSIX routines returned different values for uid/gid:
getuid/getgid used 1, stat used 0 and getpwuid used 1000. Standardise
on 1000.
Also, add fake getgrgid.
-rw-r--r-- | include/mingw.h | 16 | ||||
-rw-r--r-- | win32/mingw.c | 65 |
2 files changed, 61 insertions, 20 deletions
diff --git a/include/mingw.h b/include/mingw.h index 090dd1776..970b689fd 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -13,6 +13,9 @@ typedef int pid_t; | |||
13 | typedef __int64 pid_t; | 13 | typedef __int64 pid_t; |
14 | #endif | 14 | #endif |
15 | 15 | ||
16 | #define DEFAULT_UID 1000 | ||
17 | #define DEFAULT_GID 1000 | ||
18 | |||
16 | /* | 19 | /* |
17 | * arpa/inet.h | 20 | * arpa/inet.h |
18 | */ | 21 | */ |
@@ -42,7 +45,7 @@ struct group { | |||
42 | char **gr_mem; | 45 | char **gr_mem; |
43 | }; | 46 | }; |
44 | IMPL(getgrnam,struct group *,NULL,const char *name UNUSED_PARAM); | 47 | IMPL(getgrnam,struct group *,NULL,const char *name UNUSED_PARAM); |
45 | IMPL(getgrgid,struct group *,NULL,gid_t gid UNUSED_PARAM); | 48 | struct group *getgrgid(gid_t gid); |
46 | NOIMPL(initgroups,const char *group UNUSED_PARAM,gid_t gid UNUSED_PARAM); | 49 | NOIMPL(initgroups,const char *group UNUSED_PARAM,gid_t gid UNUSED_PARAM); |
47 | static inline void endgrent(void) {} | 50 | static inline void endgrent(void) {} |
48 | 51 | ||
@@ -71,6 +74,7 @@ struct sockaddr_un { | |||
71 | */ | 74 | */ |
72 | struct passwd { | 75 | struct passwd { |
73 | char *pw_name; | 76 | char *pw_name; |
77 | char *pw_passwd; | ||
74 | char *pw_gecos; | 78 | char *pw_gecos; |
75 | char *pw_dir; | 79 | char *pw_dir; |
76 | char *pw_shell; | 80 | char *pw_shell; |
@@ -79,7 +83,7 @@ struct passwd { | |||
79 | }; | 83 | }; |
80 | 84 | ||
81 | IMPL(getpwnam,struct passwd *,NULL,const char *name UNUSED_PARAM); | 85 | IMPL(getpwnam,struct passwd *,NULL,const char *name UNUSED_PARAM); |
82 | struct passwd *getpwuid(int uid); | 86 | struct passwd *getpwuid(uid_t uid); |
83 | static inline void setpwent(void) {} | 87 | static inline void setpwent(void) {} |
84 | static inline void endpwent(void) {} | 88 | static inline void endpwent(void) {} |
85 | IMPL(getpwent_r,int,ENOENT,struct passwd *pwbuf UNUSED_PARAM,char *buf UNUSED_PARAM,size_t buflen UNUSED_PARAM,struct passwd **pwbufp UNUSED_PARAM); | 89 | IMPL(getpwent_r,int,ENOENT,struct passwd *pwbuf UNUSED_PARAM,char *buf UNUSED_PARAM,size_t buflen UNUSED_PARAM,struct passwd **pwbufp UNUSED_PARAM); |
@@ -360,13 +364,13 @@ int mingw_dup2 (int fd, int fdto); | |||
360 | char *mingw_getcwd(char *pointer, int len); | 364 | char *mingw_getcwd(char *pointer, int len); |
361 | 365 | ||
362 | 366 | ||
363 | IMPL(getgid,int,1,void); | 367 | IMPL(getgid,int,DEFAULT_GID,void); |
364 | NOIMPL(getgroups,int n UNUSED_PARAM,gid_t *groups UNUSED_PARAM); | 368 | NOIMPL(getgroups,int n UNUSED_PARAM,gid_t *groups UNUSED_PARAM); |
365 | IMPL(getppid,int,1,void); | 369 | IMPL(getppid,int,1,void); |
366 | IMPL(getegid,int,1,void); | 370 | IMPL(getegid,int,DEFAULT_GID,void); |
367 | IMPL(geteuid,int,1,void); | 371 | IMPL(geteuid,int,DEFAULT_UID,void); |
368 | NOIMPL(getsid,pid_t pid UNUSED_PARAM); | 372 | NOIMPL(getsid,pid_t pid UNUSED_PARAM); |
369 | IMPL(getuid,int,1,void); | 373 | IMPL(getuid,int,DEFAULT_UID,void); |
370 | int fcntl(int fd, int cmd, ...); | 374 | int fcntl(int fd, int cmd, ...); |
371 | #define fork() -1 | 375 | #define fork() -1 |
372 | IMPL(fsync,int,0,int fd UNUSED_PARAM); | 376 | IMPL(fsync,int,0,int fd UNUSED_PARAM); |
diff --git a/win32/mingw.c b/win32/mingw.c index 83a7ab3a7..197f331f6 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -233,8 +233,8 @@ static int do_lstat(int follow, const char *file_name, struct mingw_stat *buf) | |||
233 | int len = strlen(file_name); | 233 | int len = strlen(file_name); |
234 | 234 | ||
235 | buf->st_ino = 0; | 235 | buf->st_ino = 0; |
236 | buf->st_gid = 0; | 236 | buf->st_uid = DEFAULT_UID; |
237 | buf->st_uid = 0; | 237 | buf->st_gid = DEFAULT_GID; |
238 | buf->st_nlink = 1; | 238 | buf->st_nlink = 1; |
239 | buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes); | 239 | buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes); |
240 | if (len > 4 && (!strcasecmp(file_name+len-4, ".exe") || | 240 | if (len > 4 && (!strcasecmp(file_name+len-4, ".exe") || |
@@ -340,8 +340,8 @@ int mingw_fstat(int fd, struct mingw_stat *buf) | |||
340 | buf->st_ino = 0; | 340 | buf->st_ino = 0; |
341 | buf->st_mode = S_IREAD|S_IWRITE; | 341 | buf->st_mode = S_IREAD|S_IWRITE; |
342 | buf->st_nlink = 1; | 342 | buf->st_nlink = 1; |
343 | buf->st_uid = 0; | 343 | buf->st_uid = DEFAULT_UID; |
344 | buf->st_gid = 0; | 344 | buf->st_gid = DEFAULT_GID; |
345 | buf->st_rdev = 0; | 345 | buf->st_rdev = 0; |
346 | buf->st_size = buf64.st_size; | 346 | buf->st_size = buf64.st_size; |
347 | buf->st_atime = buf64.st_atime; | 347 | buf->st_atime = buf64.st_atime; |
@@ -353,8 +353,8 @@ int mingw_fstat(int fd, struct mingw_stat *buf) | |||
353 | 353 | ||
354 | if (GetFileInformationByHandle(fh, &fdata)) { | 354 | if (GetFileInformationByHandle(fh, &fdata)) { |
355 | buf->st_ino = 0; | 355 | buf->st_ino = 0; |
356 | buf->st_gid = 0; | 356 | buf->st_uid = DEFAULT_UID; |
357 | buf->st_uid = 0; | 357 | buf->st_gid = DEFAULT_GID; |
358 | buf->st_nlink = 1; | 358 | buf->st_nlink = 1; |
359 | buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes); | 359 | buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes); |
360 | buf->st_size = fdata.nFileSizeLow | | 360 | buf->st_size = fdata.nFileSizeLow | |
@@ -568,25 +568,62 @@ static char *gethomedir(void) | |||
568 | return buf; | 568 | return buf; |
569 | } | 569 | } |
570 | 570 | ||
571 | struct passwd *getpwuid(int uid UNUSED_PARAM) | 571 | static char *get_user_name(void) |
572 | { | 572 | { |
573 | static char user_name[100]; | 573 | static char user_name[100] = ""; |
574 | static struct passwd p; | 574 | char *s; |
575 | DWORD len = sizeof(user_name); | 575 | DWORD len = sizeof(user_name); |
576 | 576 | ||
577 | user_name[0] = '\0'; | 577 | if ( user_name[0] != '\0' ) { |
578 | if (!GetUserName(user_name, &len)) | 578 | return user_name; |
579 | } | ||
580 | |||
581 | if ( !GetUserName(user_name, &len) ) { | ||
579 | return NULL; | 582 | return NULL; |
580 | p.pw_name = user_name; | 583 | } |
584 | |||
585 | for ( s=user_name; *s; ++s ) { | ||
586 | if ( *s == ' ' ) { | ||
587 | *s = '_'; | ||
588 | } | ||
589 | } | ||
590 | |||
591 | return user_name; | ||
592 | } | ||
593 | |||
594 | struct passwd *getpwuid(uid_t uid UNUSED_PARAM) | ||
595 | { | ||
596 | static struct passwd p; | ||
597 | |||
598 | if ( (p.pw_name=get_user_name()) == NULL ) { | ||
599 | return NULL; | ||
600 | } | ||
601 | p.pw_passwd = (char *)"secret"; | ||
581 | p.pw_gecos = (char *)"unknown"; | 602 | p.pw_gecos = (char *)"unknown"; |
582 | p.pw_dir = gethomedir(); | 603 | p.pw_dir = gethomedir(); |
583 | p.pw_shell = NULL; | 604 | p.pw_shell = NULL; |
584 | p.pw_uid = 1000; | 605 | p.pw_uid = DEFAULT_UID; |
585 | p.pw_gid = 1000; | 606 | p.pw_gid = DEFAULT_GID; |
586 | 607 | ||
587 | return &p; | 608 | return &p; |
588 | } | 609 | } |
589 | 610 | ||
611 | struct group *getgrgid(gid_t gid UNUSED_PARAM) | ||
612 | { | ||
613 | static char *members[2] = { NULL, NULL }; | ||
614 | static struct group g; | ||
615 | |||
616 | if ( (g.gr_name=get_user_name()) == NULL ) { | ||
617 | return NULL; | ||
618 | } | ||
619 | g.gr_passwd = (char *)"secret"; | ||
620 | g.gr_gid = DEFAULT_GID; | ||
621 | members[0] = g.gr_name; | ||
622 | g.gr_mem = members; | ||
623 | |||
624 | return &g; | ||
625 | } | ||
626 | |||
590 | long sysconf(int name) | 627 | long sysconf(int name) |
591 | { | 628 | { |
592 | if ( name == _SC_CLK_TCK ) { | 629 | if ( name == _SC_CLK_TCK ) { |