#include "libwbclient.h"
-/** @brief Convert a binary SID to a character string
- *
- * @param sid Binary Security Identifier
- * @param **sid_string Resulting character string
- *
- * @return #wbcErr
- **/
-
+/* Convert a binary SID to a character string */
wbcErr wbcSidToString(const struct wbcDomainSid *sid,
char **sid_string)
{
uint32_t id_auth;
int i;
char *tmp = NULL;
- TALLOC_CTX *ctx = NULL;
if (!sid) {
wbc_status = WBC_ERR_INVALID_SID;
BAIL_ON_WBC_ERROR(wbc_status);
}
- ctx = talloc_init("wbcSidToString");
- BAIL_ON_PTR_ERROR(ctx, wbc_status);
-
id_auth = sid->id_auth[5] +
(sid->id_auth[4] << 8) +
(sid->id_auth[3] << 16) +
(sid->id_auth[2] << 24);
- tmp = talloc_asprintf(ctx, "S-%d-%d", sid->sid_rev_num, id_auth);
+ tmp = talloc_asprintf(NULL, "S-%d-%d", sid->sid_rev_num, id_auth);
BAIL_ON_PTR_ERROR(tmp, wbc_status);
for (i=0; i<sid->num_auths; i++) {
tmp = tmp2;
}
- *sid_string=talloc_strdup(NULL, tmp);
- BAIL_ON_PTR_ERROR((*sid_string), wbc_status);
+ *sid_string = tmp;
+ tmp = NULL;
wbc_status = WBC_ERR_SUCCESS;
done:
- talloc_free(ctx);
+ talloc_free(tmp);
return wbc_status;
}
-/** @brief Convert a character string to a binary SID
- *
- * @param *str Character string in the form of S-...
- * @param sid Resulting binary SID
- *
- * @return #wbcErr
- **/
-
+/* Convert a character string to a binary SID */
wbcErr wbcStringToSid(const char *str,
struct wbcDomainSid *sid)
{
if (!str
|| (str[0]!='S' && str[0]!='s')
- || (str[1]!='-')
- || (strlen(str)<2))
+ || (str[1]!='-'))
{
wbc_status = WBC_ERR_INVALID_PARAM;
BAIL_ON_WBC_ERROR(wbc_status);
p = q+1;
x = (uint32_t)strtol(p, &q, 10);
- if (x==0 || !q || *q!='-') {
+ if (!q || *q!='-') {
wbc_status = WBC_ERR_INVALID_SID;
BAIL_ON_WBC_ERROR(wbc_status);
}
p = q +1;
sid->num_auths = 0;
while (sid->num_auths < WBC_MAXSUBAUTHS) {
- if ((x=(uint32_t)strtoul(p, &q, 10)) == 0)
+ x=(uint32_t)strtoul(p, &q, 10);
+ if (p == q)
break;
+ if (q == NULL) {
+ wbc_status = WBC_ERR_INVALID_SID;
+ BAIL_ON_WBC_ERROR(wbc_status);
+ }
sid->sub_auths[sid->num_auths++] = x;
- if (q && ((*q!='-') || (*q=='\0')))
+ if ((*q!='-') || (*q=='\0'))
break;
p = q + 1;
}
}
-/** @brief Convert a domain and name to SID
- *
- * @param domain Domain name (possibly "")
- * @param name User or group name
- * @param *sid Pointer to the resolved domain SID
- * @param *name_type Pointet to the SID type
- *
- * @return #wbcErr
- *
- **/
-
+/* Convert a domain and name to SID */
wbcErr wbcLookupName(const char *domain,
const char *name,
struct wbcDomainSid *sid,
return wbc_status;
}
-/** @brief Convert a SID to a domain and name
- *
- * @param *sid Pointer to the domain SID to be resolved
- * @param domain Resolved Domain name (possibly "")
- * @param name Resolved User or group name
- * @param *name_type Pointet to the resolved SID type
- *
- * @return #wbcErr
- *
- **/
-
+/* Convert a SID to a domain and name */
wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
char **pdomain,
char **pname,
char *sid_string = NULL;
char *domain = NULL;
char *name = NULL;
- enum wbcSidType name_type;
+ enum wbcSidType name_type = WBC_SID_NAME_USE_NONE;
if (!sid) {
wbc_status = WBC_ERR_INVALID_PARAM;
}
}
else {
+#if 0
+ /*
+ * Found by Coverity: In this particular routine we can't end
+ * up here with a non-NULL name. Further up there are just two
+ * exit paths that lead here, neither of which leave an
+ * allocated name. If you add more paths up there, re-activate
+ * this.
+ */
if (name != NULL) {
talloc_free(name);
}
+#endif
if (domain != NULL) {
talloc_free(domain);
}
return wbc_status;
}
-/** @brief Translate a collection of RIDs within a domain to names
- *
- **/
+/* Translate a collection of RIDs within a domain to names */
wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
int num_rids,
return wbc_status;
}
-/** @brief Get the groups a user belongs to
- *
- **/
-
+/* Get the groups a user belongs to */
wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
bool domain_groups_only,
uint32_t *num_sids,
return wbc_status;
}
-/** @brief Lists Users
- *
- **/
-
+/* Lists Users */
wbcErr wbcListUsers(const char *domain_name,
uint32_t *_num_users,
const char ***_users)
return wbc_status;
}
-/** @brief Lists Groups
- *
- **/
-
+/* Lists Groups */
wbcErr wbcListGroups(const char *domain_name,
uint32_t *_num_groups,
const char ***_groups)
}
return wbc_status;
}
+
+wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
+ char **pdomain,
+ char **pfullname,
+ enum wbcSidType *pname_type)
+{
+ wbcErr wbc_status;
+ char *domain = NULL;
+ char *name = NULL;
+ enum wbcSidType name_type;
+
+ wbc_status = wbcLookupSid(sid, &domain, &name, &name_type);
+ BAIL_ON_WBC_ERROR(wbc_status);
+
+ if (name_type == WBC_SID_NAME_USER) {
+ uid_t uid;
+ struct passwd *pwd;
+
+ wbc_status = wbcSidToUid(sid, &uid);
+ BAIL_ON_WBC_ERROR(wbc_status);
+
+ wbc_status = wbcGetpwuid(uid, &pwd);
+ BAIL_ON_WBC_ERROR(wbc_status);
+
+ wbcFreeMemory(name);
+
+ name = talloc_strdup(NULL, pwd->pw_gecos);
+ BAIL_ON_PTR_ERROR(name, wbc_status);
+ }
+
+ wbc_status = WBC_ERR_SUCCESS;
+
+ done:
+ if (WBC_ERROR_IS_OK(wbc_status)) {
+ *pdomain = domain;
+ *pfullname = name;
+ *pname_type = name_type;
+ } else {
+ wbcFreeMemory(domain);
+ wbcFreeMemory(name);
+ }
+
+ return wbc_status;
+}