aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-02-26 15:50:39 +0000
committerRon Yorston <rmy@pobox.com>2015-02-26 15:50:39 +0000
commit59abbf391be4ddaab0e0335b4f3691cc48590574 (patch)
treeceeea37fd680410c15689ce42e19ec62b7f5e69b /win32/mingw.c
parent63dbf1908bc51918d9d963f4d9b7657306b2970d (diff)
downloadbusybox-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.
Diffstat (limited to 'win32/mingw.c')
-rw-r--r--win32/mingw.c65
1 files changed, 51 insertions, 14 deletions
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
571struct passwd *getpwuid(int uid UNUSED_PARAM) 571static 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
594struct 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
611struct 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
590long sysconf(int name) 627long sysconf(int name)
591{ 628{
592 if ( name == _SC_CLK_TCK ) { 629 if ( name == _SC_CLK_TCK ) {