s3: Implement wbcGetpwsid
[ira/wip.git] / source3 / lib / winbind_util.c
index 3cf068a6e0da11d812a89c4f3954ce066f960e90..686e70f4ad7860a17d3374f002f5e3756daffc27 100644 (file)
 
 #include "nsswitch/libwbclient/wbclient.h"
 
+struct passwd * winbind_getpwnam(const char * name)
+{
+       wbcErr result;
+       struct passwd * tmp_pwd = NULL;
+       struct passwd * pwd = NULL;
+
+       result = wbcGetpwnam(name, &tmp_pwd);
+       if (result != WBC_ERR_SUCCESS)
+               return pwd;
+
+       pwd = tcopy_passwd(talloc_tos(), tmp_pwd);
+
+       wbcFreeMemory(tmp_pwd);
+
+       return pwd;
+}
+
+struct passwd * winbind_getpwsid(const DOM_SID *sid)
+{
+       wbcErr result;
+       struct passwd * tmp_pwd = NULL;
+       struct passwd * pwd = NULL;
+       struct wbcDomainSid dom_sid;
+
+       memcpy(&dom_sid, sid, sizeof(dom_sid));
+
+       result = wbcGetpwsid(&dom_sid, &tmp_pwd);
+       if (result != WBC_ERR_SUCCESS)
+               return pwd;
+
+       pwd = tcopy_passwd(talloc_tos(), tmp_pwd);
+
+       wbcFreeMemory(tmp_pwd);
+
+       return pwd;
+}
+
 /* Call winbindd to convert a name to a sid */
 
 bool winbind_lookup_name(const char *dom_name, const char *name, DOM_SID *sid, 
@@ -201,7 +238,7 @@ bool winbind_lookup_rids(TALLOC_CTX *mem_ctx,
        *types       = TALLOC_ARRAY(mem_ctx, enum lsa_SidType, num_rids);
 
        for(i=0; i<num_rids; i++) {
-               (*names)[i] = talloc_strdup(names, namelist[i]);
+               (*names)[i] = talloc_strdup(*names, namelist[i]);
                (*types)[i] = (enum lsa_SidType)name_types[i];
        }
 
@@ -236,6 +273,16 @@ bool winbind_allocate_gid(gid_t *gid)
 
 #else      /* WITH_WINBIND */
 
+struct passwd * winbind_getpwnam(const char * name)
+{
+       return NULL;
+}
+
+struct passwd * winbind_getpwsid(const DOM_SID *sid)
+{
+       return NULL;
+}
+
 bool winbind_lookup_name(const char *dom_name, const char *name, DOM_SID *sid, 
                          enum lsa_SidType *name_type)
 {