s3: Implement wbcGetpwsid
[ira/wip.git] / nsswitch / libwbclient / wbc_pwd.c
index cd945996c89968414c576ef4a0f0b354ef2d2917..dacd9499dd4ab459e23469ccaa84fea6764cf4cc 100644 (file)
@@ -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)
 {