* external.cc (cygwin_internal): Add cases for CW_GETNSSSEP,

CW_GETPWSID and CW_GETGRSID.
	* grp.cc (internal_getgrsid_from_db): New function.
	* passwd.cc (internal_getpwsid_from_db): New function.
	(pg_ent::setent): Add special case for call from mkpasswd/mkgroup.
	* pwdgrp.h (internal_getpwsid_from_db): Declare.
	(internal_getgrsid_from_db): Declare.
	(enum nss_enum_t): Move to include/sys/cygwin.h.
	(class pg_ent): Add comment.
	* uinfo.cc (pwdgrp::fetch_account_from_windows): Fix typo in comment.
	Change "UNIX" to "Unix" in domain name.
	* include/sys/cygwin.h (cygwin_getinfo_types): Add CW_GETNSSSEP,
	CW_GETPWSID and CW_GETGRSID.
	(enum nss_enum_t): Define here.
This commit is contained in:
Corinna Vinschen 2014-02-22 19:38:12 +00:00
parent 98cc373860
commit b211f4c17e
7 changed files with 98 additions and 27 deletions

View File

@ -1,3 +1,20 @@
2014-02-22 Corinna Vinschen <corinna@vinschen.de>
* external.cc (cygwin_internal): Add cases for CW_GETNSSSEP,
CW_GETPWSID and CW_GETGRSID.
* grp.cc (internal_getgrsid_from_db): New function.
* passwd.cc (internal_getpwsid_from_db): New function.
(pg_ent::setent): Add special case for call from mkpasswd/mkgroup.
* pwdgrp.h (internal_getpwsid_from_db): Declare.
(internal_getgrsid_from_db): Declare.
(enum nss_enum_t): Move to include/sys/cygwin.h.
(class pg_ent): Add comment.
* uinfo.cc (pwdgrp::fetch_account_from_windows): Fix typo in comment.
Change "UNIX" to "Unix" in domain name.
* include/sys/cygwin.h (cygwin_getinfo_types): Add CW_GETNSSSEP,
CW_GETPWSID and CW_GETGRSID.
(enum nss_enum_t): Define here.
2014-02-21 Corinna Vinschen <corinna@vinschen.de>
* pwdgrp.h (pwdgrp::fetch_account_from_windows): Add bool parameter

View File

@ -595,6 +595,30 @@ cygwin_internal (cygwin_getinfo_types t, ...)
}
break;
case CW_GETNSSSEP:
res = (uintptr_t) cygheap->pg.nss_separator ();
break;
case CW_GETPWSID:
{
int db_only = va_arg (arg, int);
PSID psid = va_arg (arg, PSID);
cygpsid sid (psid);
res = (uintptr_t) (db_only ? internal_getpwsid_from_db (sid)
: internal_getpwsid (sid));
}
break;
case CW_GETGRSID:
{
int db_only = va_arg (arg, int);
PSID psid = va_arg (arg, PSID);
cygpsid sid (psid);
res = (uintptr_t) (db_only ? internal_getgrsid_from_db (sid)
: internal_getgrsid (sid));
}
break;
default:
set_errno (ENOSYS);
}

View File

@ -139,6 +139,14 @@ internal_getgrsid (cygpsid &sid)
return NULL;
}
/* This function gets only called from mkgroup via cygwin_internal. */
struct group *
internal_getgrsid_from_db (cygpsid &sid)
{
cygheap->pg.nss_init ();
return cygheap->pg.grp_cache.win.add_group_from_windows (sid);
}
struct group *
internal_getgrnam (const char *name)
{

View File

@ -146,7 +146,10 @@ typedef enum
CW_FREE_DRIVE_MAP,
CW_SETENT,
CW_GETENT,
CW_ENDENT
CW_ENDENT,
CW_GETNSSSEP,
CW_GETPWSID,
CW_GETGRSID
} cygwin_getinfo_types;
#define CW_LOCK_PINFO CW_LOCK_PINFO
@ -200,6 +203,9 @@ typedef enum
#define CW_SETENT CW_SETENT
#define CW_GETENT CW_GETENT
#define CW_ENDENT CW_ENDENT
#define CW_GETNSSSEP CW_GETNSSSEP
#define CW_GETPWSID CW_GETPWSID
#define CW_GETGRSID CW_GETGRSID
/* Token type for CW_SET_EXTERNAL_TOKEN */
enum
@ -208,6 +214,20 @@ CW_TOKEN_IMPERSONATION = 0,
CW_TOKEN_RESTRICTED = 1
};
/* Enumeration source constants for CW_SETENT called from mkpasswd/mkgroup. */
enum nss_enum_t
{
ENUM_NONE = 0x00,
ENUM_CACHE = 0x01,
ENUM_FILES = 0x02,
ENUM_BUILTIN = 0x04,
ENUM_LOCAL = 0x08,
ENUM_PRIMARY = 0x10,
ENUM_TDOMS = 0x20,
ENUM_TDOMS_ALL = 0x40,
ENUM_ALL = 0x7f
};
#define CW_NEXTPID 0x80000000 /* or with pid to get next one */
uintptr_t cygwin_internal (cygwin_getinfo_types, ...);

View File

@ -123,6 +123,14 @@ internal_getpwsid (cygpsid &sid)
return NULL;
}
/* This function gets only called from mkpasswd via cygwin_internal. */
struct passwd *
internal_getpwsid_from_db (cygpsid &sid)
{
cygheap->pg.nss_init ();
return cygheap->pg.pwd_cache.win.add_user_from_windows (sid);
}
struct passwd *
internal_getpwnam (const char *name)
{
@ -300,23 +308,28 @@ pg_ent::setent (bool _group, int _enums, PCWSTR _enum_tdoms)
endent (_group);
if (!_enums && !_enum_tdoms)
{
/* This is the default, when called from the usual setpwent/setgrent
functions. */
enums = cygheap->pg.nss_db_enums ();
enum_tdoms = cygheap->pg.nss_db_enum_tdoms ();
if (_group)
{
from_files = cygheap->pg.nss_grp_files ();
from_db = cygheap->pg.nss_grp_db ();
}
else
{
from_files = cygheap->pg.nss_pwd_files ();
from_db = cygheap->pg.nss_pwd_db ();
}
}
else
{
/* This case is when called from mkpasswd/mkgroup via cygwin_internal. */
enums = _enums;
enum_tdoms = _enum_tdoms;
}
if (_group)
{
from_files = cygheap->pg.nss_grp_files ();
from_db = cygheap->pg.nss_grp_db ();
}
else
{
from_files = cygheap->pg.nss_pwd_files ();
from_db = cygheap->pg.nss_pwd_db ();
from_files = false;
from_db = true;
}
state = from_cache;
}

View File

@ -15,9 +15,11 @@ details. */
/* These functions are needed to allow searching and walking through
the passwd and group lists */
extern struct passwd *internal_getpwsid (cygpsid &);
extern struct passwd *internal_getpwsid_from_db (cygpsid &sid);
extern struct passwd *internal_getpwnam (const char *);
extern struct passwd *internal_getpwuid (uid_t);
extern struct group *internal_getgrsid (cygpsid &);
extern struct group *internal_getgrsid_from_db (cygpsid &sid);
extern struct group *internal_getgrgid (gid_t);
extern struct group *internal_getgrnam (const char *);
int internal_getgroups (int, gid_t *, cygpsid * = NULL);
@ -158,19 +160,6 @@ public:
struct group *find_group (gid_t gid);
};
enum nss_enum_t
{
ENUM_NONE = 0x00,
ENUM_CACHE = 0x01,
ENUM_FILES = 0x02,
ENUM_BUILTIN = 0x04,
ENUM_LOCAL = 0x08,
ENUM_PRIMARY = 0x10,
ENUM_TDOMS = 0x20,
ENUM_TDOMS_ALL = 0x40,
ENUM_ALL = 0x7f
};
class pg_ent
{
protected:
@ -184,7 +173,7 @@ protected:
ULONG cnt;
ULONG max;
ULONG_PTR resume;
int enums;
int enums; /* ENUM_xxx values defined in sys/cygwin.h. */
PCWSTR enum_tdoms;
bool from_files;
bool from_db;

View File

@ -1720,12 +1720,12 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group,
{
/* Samba UNIX Users/Groups
This *might* colide with a posix_offset of some trusted domain.
This *might* collide with a posix_offset of some trusted domain.
It's just very unlikely. */
uid = MAP_UNIX_TO_CYGWIN_ID (sid_sub_auth_rid (sid));
/* Unfortunately we have no access to the file server from here,
so we can't generate correct user names. */
p = wcpcpy (dom, L"UNIX_");
p = wcpcpy (dom, L"Unix_");
wcpcpy (p, sid_sub_auth (sid, 0) == 1 ? L"User" : L"Group");
__small_swprintf (name = namebuf, L"%d", uid & UNIX_POSIX_MASK);
name_style = fully_qualified;