diff options
author | Dan Sledz <dsledz@isilon.com> | 2009-02-10 11:06:44 -0800 |
---|---|---|
committer | Steven Danneman <steven.danneman@isilon.com> | 2009-02-11 19:39:15 -0800 |
commit | aed8e9aa0a887e31562ac9da38ee4a878a4dd4ba (patch) | |
tree | cc359f1206534de4b875ea06b822f0e8802908b6 /nsswitch | |
parent | 4e69f23857289bd58f4adad85602c8afc3bed03a (diff) | |
download | samba-aed8e9aa0a887e31562ac9da38ee4a878a4dd4ba.tar.gz samba-aed8e9aa0a887e31562ac9da38ee4a878a4dd4ba.tar.bz2 samba-aed8e9aa0a887e31562ac9da38ee4a878a4dd4ba.zip |
s3: Implement wbcGetpwsid
* Adds the plumbing required to lookup users by sid into winbind, wbinfo
and smbd helper lib (winbind_util.c).
* Removes some double declarations of winbind_util.c functions.
* Bumps the winbind protocol version to 21 and the minor version of
wbclient to 3.
Diffstat (limited to 'nsswitch')
-rw-r--r-- | nsswitch/libwbclient/wbc_pwd.c | 39 | ||||
-rw-r--r-- | nsswitch/libwbclient/wbclient.h | 14 | ||||
-rw-r--r-- | nsswitch/wbinfo.c | 34 | ||||
-rw-r--r-- | nsswitch/winbind_struct_protocol.h | 9 |
4 files changed, 92 insertions, 4 deletions
diff --git a/nsswitch/libwbclient/wbc_pwd.c b/nsswitch/libwbclient/wbc_pwd.c index cd945996c8..dacd9499dd 100644 --- a/nsswitch/libwbclient/wbc_pwd.c +++ b/nsswitch/libwbclient/wbc_pwd.c @@ -190,6 +190,45 @@ wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd) return wbc_status; } +/* Fill in a struct passwd* for a domain user based on sid */ +wbcErr wbcGetpwsid(struct wbcDomainSid *sid, struct passwd **pwd) +{ + wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; + struct winbindd_request request; + struct winbindd_response response; + char * sid_string = NULL; + + if (!pwd) { + wbc_status = WBC_ERR_INVALID_PARAM; + BAIL_ON_WBC_ERROR(wbc_status); + } + + wbc_status = wbcSidToString(sid, &sid_string); + BAIL_ON_WBC_ERROR(wbc_status); + + /* Initialize request */ + + ZERO_STRUCT(request); + ZERO_STRUCT(response); + + strncpy(request.data.sid, sid_string, sizeof(request.data.sid)); + + wbc_status = wbcRequestResponse(WINBINDD_GETPWSID, + &request, + &response); + BAIL_ON_WBC_ERROR(wbc_status); + + *pwd = copy_passwd_entry(&response.data.pw); + BAIL_ON_PTR_ERROR(*pwd, wbc_status); + + done: + if (sid_string) { + wbcFreeMemory(sid_string); + } + + return wbc_status; +} + /* Fill in a struct passwd* for a domain user based on username */ wbcErr wbcGetgrnam(const char *name, struct group **grp) { diff --git a/nsswitch/libwbclient/wbclient.h b/nsswitch/libwbclient/wbclient.h index 990cc52df7..4663624f91 100644 --- a/nsswitch/libwbclient/wbclient.h +++ b/nsswitch/libwbclient/wbclient.h @@ -60,9 +60,10 @@ const char *wbcErrorString(wbcErr error); * 0.1: Initial version * 0.2: Added wbcRemoveUidMapping() * Added wbcRemoveGidMapping() + * 0.3: Added wbcGetpwsid() **/ #define WBCLIENT_MAJOR_VERSION 0 -#define WBCLIENT_MINOR_VERSION 2 +#define WBCLIENT_MINOR_VERSION 3 #define WBCLIENT_VENDOR_VERSION "Samba libwbclient" struct wbcLibraryDetails { uint16_t major_version; @@ -838,6 +839,17 @@ wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd); /** * @brief Fill in a struct passwd* for a domain user based + * on sid + * + * @param sid Sid to lookup + * @param **pwd Pointer to resulting struct passwd* from the query. + * + * @return #wbcErr + **/ +wbcErr wbcGetpwsid(struct wbcDomainSid * sid, struct passwd **pwd); + +/** + * @brief Fill in a struct passwd* for a domain user based * on username * * @param *name Username to lookup diff --git a/nsswitch/wbinfo.c b/nsswitch/wbinfo.c index ce53cadc58..372896ce71 100644 --- a/nsswitch/wbinfo.c +++ b/nsswitch/wbinfo.c @@ -202,6 +202,31 @@ static bool wbinfo_get_uidinfo(int uid) return true; } +static bool wbinfo_get_user_sidinfo(const char *sid_str) +{ + wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; + struct passwd *pwd = NULL; + struct wbcDomainSid sid; + + wbc_status = wbcStringToSid(sid_str, &sid); + wbc_status = wbcGetpwsid(&sid, &pwd); + if (!WBC_ERROR_IS_OK(wbc_status)) { + return false; + } + + d_printf("%s:%s:%d:%d:%s:%s:%s\n", + pwd->pw_name, + pwd->pw_passwd, + pwd->pw_uid, + pwd->pw_gid, + pwd->pw_gecos, + pwd->pw_dir, + pwd->pw_shell); + + return true; +} + + /* pull grent for a given group */ static bool wbinfo_get_groupinfo(const char *group) { @@ -1564,6 +1589,7 @@ enum { OPT_LIST_ALL_DOMAINS, OPT_LIST_OWN_DOMAIN, OPT_UID_INFO, + OPT_USER_SIDINFO, OPT_GROUP_INFO, OPT_GID_INFO, OPT_VERBOSE, @@ -1622,6 +1648,7 @@ int main(int argc, char **argv, char **envp) { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" }, { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" }, { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" }, + { "user-sidinfo", 0, POPT_ARG_STRING, &string_arg, OPT_USER_SIDINFO, "Get user info from sid", "SID" }, { "gid-info", 0, POPT_ARG_INT, &int_arg, OPT_GID_INFO, "Get group info from gid", "GID" }, { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" }, { "user-domgroups", 0, POPT_ARG_STRING, &string_arg, @@ -1860,6 +1887,13 @@ int main(int argc, char **argv, char **envp) goto done; } break; + case OPT_USER_SIDINFO: + if ( !wbinfo_get_user_sidinfo(string_arg)) { + d_fprintf(stderr, "Could not get info for user sid %s\n", + string_arg); + goto done; + } + break; case OPT_UID_INFO: if ( !wbinfo_get_uidinfo(int_arg)) { d_fprintf(stderr, "Could not get info for uid " diff --git a/nsswitch/winbind_struct_protocol.h b/nsswitch/winbind_struct_protocol.h index 0b3e74492c..26e45f3c7f 100644 --- a/nsswitch/winbind_struct_protocol.h +++ b/nsswitch/winbind_struct_protocol.h @@ -39,9 +39,11 @@ #define WINBINDD_DONT_ENV "_NO_WINBINDD" #define WINBINDD_LOCATOR_KDC_ADDRESS "WINBINDD_LOCATOR_KDC_ADDRESS" -/* Update this when you change the interface. */ - -#define WINBIND_INTERFACE_VERSION 20 +/* Update this when you change the interface. + * 21: added WINBINDD_GETPWSID + * added WINBINDD_GETSIDALIASES + */ +#define WINBIND_INTERFACE_VERSION 21 /* Have to deal with time_t being 4 or 8 bytes due to structure alignment. On a 64bit Linux box, we have to support a constant structure size @@ -60,6 +62,7 @@ enum winbindd_cmd { WINBINDD_GETPWNAM, WINBINDD_GETPWUID, + WINBINDD_GETPWSID, WINBINDD_GETGRNAM, WINBINDD_GETGRGID, WINBINDD_GETGROUPS, |