From c5045141b065479e4aa3d0c1eebaac2337321852 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Sat, 18 Jul 2009 13:15:36 +0800 Subject: [PATCH] handling upn name Signed-off-by: Bo Yang --- source/nsswitch/pam_winbind.c | 17 +++++++++++++++-- source/winbindd/winbindd_sid.c | 4 ++++ source/winbindd/winbindd_util.c | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/source/nsswitch/pam_winbind.c b/source/nsswitch/pam_winbind.c index ad063c3..a816572 100644 --- a/source/nsswitch/pam_winbind.c +++ b/source/nsswitch/pam_winbind.c @@ -1910,6 +1910,9 @@ static char* winbind_upn_to_username(struct pwb_context *ctx, char *account_name; int account_name_len; char sep; + char *p; + char *name; + char *domain; /* This cannot work when the winbind separator = @ */ @@ -1918,14 +1921,23 @@ static char* winbind_upn_to_username(struct pwb_context *ctx, return NULL; } + name = strdup(upn); + if (!name) { + return NULL; + } + if ((p = strchr(name, '@')) != NULL) { + *p = 0; + domain = p + 1; + } + /* Convert the UPN to a SID */ ZERO_STRUCT(req); ZERO_STRUCT(resp); - strncpy(req.data.name.dom_name, "", + strncpy(req.data.name.dom_name, domain, sizeof(req.data.name.dom_name) - 1); - strncpy(req.data.name.name, upn, + strncpy(req.data.name.name, name, sizeof(req.data.name.name) - 1); retval = pam_winbind_request_log(ctx, WINBINDD_LOOKUPNAME, &req, &resp, upn); @@ -1947,6 +1959,7 @@ static char* winbind_upn_to_username(struct pwb_context *ctx, account_name_len = asprintf(&account_name, "%s\\%s", resp.data.name.dom_name, resp.data.name.name); + SAFE_FREE(name); return account_name; } diff --git a/source/winbindd/winbindd_sid.c b/source/winbindd/winbindd_sid.c index 0e8e6ca..0471a2c 100644 --- a/source/winbindd/winbindd_sid.c +++ b/source/winbindd/winbindd_sid.c @@ -93,6 +93,10 @@ void winbindd_lookupname(struct winbindd_cli_state *state) *p = 0; name_domain = state->request.data.name.name; name_user = p+1; + } else if ((p = strchr(state->request.data.name.name, '@')) != NULL) { + name_domain = p + 1; + *p = 0; + name_user = state->request.data.name.name; } else { name_domain = state->request.data.name.dom_name; name_user = state->request.data.name.name; diff --git a/source/winbindd/winbindd_util.c b/source/winbindd/winbindd_util.c index 624d68e..8046d36 100644 --- a/source/winbindd/winbindd_util.c +++ b/source/winbindd/winbindd_util.c @@ -1102,7 +1102,8 @@ bool parse_domain_user(const char *domuser, fstring domain, fstring user) if ( assume_domain(lp_workgroup())) { fstrcpy(domain, lp_workgroup()); } else if ((p = strchr(domuser, '@')) != NULL) { - fstrcpy(domain, ""); + fstrcpy(domain, p + 1); + user[PTR_DIFF(p, domuser)] = 0; } else { return False; } -- 1.5.3