}
for (i = 0; i < num_sids; i++) {
- char *str = NULL;
- wbc_status = wbcSidToString(&sids[i], &str);
- if (!WBC_ERROR_IS_OK(wbc_status)) {
- d_fprintf(stderr, "failed to call wbcSidToString: "
- "%s\n", wbcErrorString(wbc_status));
- wbcFreeMemory(sids);
- return false;
- }
+ char str[WBC_SID_STRING_BUFLEN];
+ wbcSidToStringBuf(&sids[i], str, sizeof(str));
d_printf("%s\n", str);
- wbcFreeMemory(str);
}
wbcFreeMemory(sids);
wbc_status = wbcStringToSid(user_sid_str, &user_sid);
if (!WBC_ERROR_IS_OK(wbc_status)) {
- d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
+ d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
wbcErrorString(wbc_status));
return false;
}
}
for (i = 0; i < num_sids; i++) {
- char *str = NULL;
- wbc_status = wbcSidToString(&sids[i], &str);
- if (!WBC_ERROR_IS_OK(wbc_status)) {
- d_fprintf(stderr, "failed to call wbcSidToString: "
- "%s\n", wbcErrorString(wbc_status));
- wbcFreeMemory(sids);
- return false;
- }
+ char str[WBC_SID_STRING_BUFLEN];
+ wbcSidToStringBuf(&sids[i], str, sizeof(str));
d_printf("%s\n", str);
- wbcFreeMemory(str);
}
wbcFreeMemory(sids);
struct wbcDomainSid user_sid;
uint32_t *alias_rids = NULL;
uint32_t num_alias_rids;
- char *domain_sid_str = NULL;
+ char domain_sid_str[WBC_SID_STRING_BUFLEN];
/* Send request */
if ((domain == NULL) || (strequal(domain, ".")) ||
goto done;
}
- wbc_status = wbcSidToString(&dinfo->sid, &domain_sid_str);
- if (!WBC_ERROR_IS_OK(wbc_status)) {
- goto done;
- }
+ wbcSidToStringBuf(&dinfo->sid, domain_sid_str, sizeof(domain_sid_str));
for (i = 0; i < num_alias_rids; i++) {
d_printf("%s-%d\n", domain_sid_str, alias_rids[i]);
wbcFreeMemory(alias_rids);
done:
- if (domain_sid_str) {
- wbcFreeMemory(domain_sid_str);
- }
- if (dinfo) {
- wbcFreeMemory(dinfo);
- }
+ wbcFreeMemory(dinfo);
return (WBC_ERR_SUCCESS == wbc_status);
}
d_printf("\n");
}
+ wbcFreeMemory(domain_list);
+
return true;
}
is_offline ? "offline" : "online" );
}
+ wbcFreeMemory(domain_list);
+
return true;
}
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
struct wbcDomainInfo *dinfo = NULL;
- char *sid_str = NULL;
+ char sid_str[WBC_SID_STRING_BUFLEN];
if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
domain = get_winbind_domain();
return false;
}
- wbc_status = wbcSidToString(&dinfo->sid, &sid_str);
- if (!WBC_ERROR_IS_OK(wbc_status)) {
- d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
- wbcErrorString(wbc_status));
- wbcFreeMemory(dinfo);
- return false;
- }
+ wbcSidToStringBuf(&dinfo->sid, sid_str, sizeof(sid_str));
/* Display response */
(dinfo->domain_flags & WBC_DOMINFO_DOMAIN_PRIMARY) ?
"Yes" : "No");
- wbcFreeMemory(sid_str);
wbcFreeMemory(dinfo);
return true;
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
struct wbcDomainSid sid;
- char *sid_str = NULL;
+ char sid_str[WBC_SID_STRING_BUFLEN];
/* Send request */
return false;
}
- wbc_status = wbcSidToString(&sid, &sid_str);
- if (!WBC_ERROR_IS_OK(wbc_status)) {
- d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
- wbcErrorString(wbc_status));
- return false;
- }
+ wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
/* Display response */
d_printf("%s\n", sid_str);
- wbcFreeMemory(sid_str);
-
return true;
}
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
struct wbcDomainSid sid;
- char *sid_str = NULL;
+ char sid_str[WBC_SID_STRING_BUFLEN];
/* Send request */
return false;
}
- wbc_status = wbcSidToString(&sid, &sid_str);
- if (!WBC_ERROR_IS_OK(wbc_status)) {
- d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
- wbcErrorString(wbc_status));
- return false;
- }
+ wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
/* Display response */
d_printf("%s\n", sid_str);
- wbcFreeMemory(sid_str);
-
return true;
}
return true;
}
+static bool wbinfo_set_uid_mapping(uid_t uid, const char *sid_str)
+{
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+ struct wbcDomainSid sid;
+
+ /* Send request */
+
+ wbc_status = wbcStringToSid(sid_str, &sid);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
+ wbcErrorString(wbc_status));
+ return false;
+ }
+
+ wbc_status = wbcSetUidMapping(uid, &sid);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ d_fprintf(stderr, "failed to call wbcSetUidMapping: %s\n",
+ wbcErrorString(wbc_status));
+ return false;
+ }
+
+ /* Display response */
+
+ d_printf("uid %u now mapped to sid %s\n",
+ (unsigned int)uid, sid_str);
+
+ return true;
+}
+
+static bool wbinfo_set_gid_mapping(gid_t gid, const char *sid_str)
+{
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+ struct wbcDomainSid sid;
+
+ /* Send request */
+
+ wbc_status = wbcStringToSid(sid_str, &sid);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
+ wbcErrorString(wbc_status));
+ return false;
+ }
+
+ wbc_status = wbcSetGidMapping(gid, &sid);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ d_fprintf(stderr, "failed to call wbcSetGidMapping: %s\n",
+ wbcErrorString(wbc_status));
+ return false;
+ }
+
+ /* Display response */
+
+ d_printf("gid %u now mapped to sid %s\n",
+ (unsigned int)gid, sid_str);
+
+ return true;
+}
+
+static bool wbinfo_remove_uid_mapping(uid_t uid, const char *sid_str)
+{
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+ struct wbcDomainSid sid;
+
+ /* Send request */
+
+ wbc_status = wbcStringToSid(sid_str, &sid);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
+ wbcErrorString(wbc_status));
+ return false;
+ }
+
+ wbc_status = wbcRemoveUidMapping(uid, &sid);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ d_fprintf(stderr, "failed to call wbcRemoveUidMapping: %s\n",
+ wbcErrorString(wbc_status));
+ return false;
+ }
+
+ /* Display response */
+
+ d_printf("Removed uid %u to sid %s mapping\n",
+ (unsigned int)uid, sid_str);
+
+ return true;
+}
+
+static bool wbinfo_remove_gid_mapping(gid_t gid, const char *sid_str)
+{
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+ struct wbcDomainSid sid;
+
+ /* Send request */
+
+ wbc_status = wbcStringToSid(sid_str, &sid);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
+ wbcErrorString(wbc_status));
+ return false;
+ }
+
+ wbc_status = wbcRemoveGidMapping(gid, &sid);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ d_fprintf(stderr, "failed to call wbcRemoveGidMapping: %s\n",
+ wbcErrorString(wbc_status));
+ return false;
+ }
+
+ /* Display response */
+
+ d_printf("Removed gid %u to sid %s mapping\n",
+ (unsigned int)gid, sid_str);
+
+ return true;
+}
+
/* Convert sid to string */
static bool wbinfo_lookupsid(const char *sid_str)
ret = true;
done:
- if (dinfo) {
- wbcFreeMemory(dinfo);
- }
- if (domain_name) {
- wbcFreeMemory(domain_name);
- }
- if (names) {
- wbcFreeMemory(names);
- }
- if (types) {
- wbcFreeMemory(types);
- }
+ wbcFreeMemory(dinfo);
+ wbcFreeMemory(domain_name);
+ wbcFreeMemory(names);
+ wbcFreeMemory(types);
TALLOC_FREE(mem_ctx);
return ret;
}
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
struct wbcDomainSid sid;
- char *sid_str;
+ char sid_str[WBC_SID_STRING_BUFLEN];
enum wbcSidType type;
fstring domain_name;
fstring account_name;
return false;
}
- wbc_status = wbcSidToString(&sid, &sid_str);
- if (!WBC_ERROR_IS_OK(wbc_status)) {
- d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
- wbcErrorString(wbc_status));
- return false;
- }
+ wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
/* Display response */
d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type);
- wbcFreeMemory(sid_str);
-
return true;
}
OPT_USERSIDS,
OPT_ALLOCATE_UID,
OPT_ALLOCATE_GID,
+ OPT_SET_UID_MAPPING,
+ OPT_SET_GID_MAPPING,
+ OPT_REMOVE_UID_MAPPING,
+ OPT_REMOVE_GID_MAPPING,
OPT_SEPARATOR,
OPT_LIST_ALL_DOMAINS,
OPT_LIST_OWN_DOMAIN,
"Get a new UID out of idmap" },
{ "allocate-gid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_GID,
"Get a new GID out of idmap" },
+ { "set-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_UID_MAPPING, "Create or modify uid to sid mapping in idmap", "UID,SID" },
+ { "set-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_GID_MAPPING, "Create or modify gid to sid mapping in idmap", "GID,SID" },
+ { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" },
+ { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" },
{ "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
{ "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" },
{ "ping-dc", 'P', POPT_ARG_NONE, 0, 'P',
goto done;
}
break;
+ case OPT_SET_UID_MAPPING:
+ if (!parse_mapping_arg(string_arg, &int_subarg,
+ &string_subarg) ||
+ !wbinfo_set_uid_mapping(int_subarg, string_subarg))
+ {
+ d_fprintf(stderr, "Could not create or modify "
+ "uid to sid mapping\n");
+ goto done;
+ }
+ break;
+ case OPT_SET_GID_MAPPING:
+ if (!parse_mapping_arg(string_arg, &int_subarg,
+ &string_subarg) ||
+ !wbinfo_set_gid_mapping(int_subarg, string_subarg))
+ {
+ d_fprintf(stderr, "Could not create or modify "
+ "gid to sid mapping\n");
+ goto done;
+ }
+ break;
+ case OPT_REMOVE_UID_MAPPING:
+ if (!parse_mapping_arg(string_arg, &int_subarg,
+ &string_subarg) ||
+ !wbinfo_remove_uid_mapping(int_subarg,
+ string_subarg))
+ {
+ d_fprintf(stderr, "Could not remove uid to sid "
+ "mapping\n");
+ goto done;
+ }
+ break;
+ case OPT_REMOVE_GID_MAPPING:
+ if (!parse_mapping_arg(string_arg, &int_subarg,
+ &string_subarg) ||
+ !wbinfo_remove_gid_mapping(int_subarg,
+ string_subarg))
+ {
+ d_fprintf(stderr, "Could not remove gid to sid "
+ "mapping\n");
+ goto done;
+ }
+ break;
case 't':
if (!wbinfo_check_secret(opt_domain_name)) {
d_fprintf(stderr, "Could not check secret\n");