/* Prototypes from common.h - only needed #if TNG */
-NSS_STATUS winbindd_request(int req_type,
+enum nss_status winbindd_request(int req_type,
struct winbindd_request *request,
struct winbindd_response *response);
+static BOOL wbinfo_get_usergroups(char *user)
+{
+ struct winbindd_request request;
+ struct winbindd_response response;
+ int result, i;
+
+ ZERO_STRUCT(response);
+
+ /* Send request */
+
+ fstrcpy(request.data.username, user);
+
+ result = winbindd_request(WINBINDD_INITGROUPS, &request, &response);
+
+ if (result != NSS_STATUS_SUCCESS) {
+ return False;
+ }
+
+ for (i = 0; i < response.data.num_entries; i++) {
+ printf("%d\n", ((gid_t *)response.extra_data)[i]);
+ }
+
+ return True;
+}
+
/* List trusted domains */
static BOOL wbinfo_list_domains(void)
/* Send request */
- if (winbindd_request(WINBINDD_LIST_TRUSTDOM, NULL, &response) !=
- NSS_STATUS_SUCCESS) {
+ if (winbindd_request(WINBINDD_LIST_TRUSTDOM, NULL, &response) ==
+ WINBINDD_ERROR) {
return False;
}
static BOOL wbinfo_check_secret(void)
{
- struct winbindd_response response;
- BOOL result;
-
- ZERO_STRUCT(response);
-
- result = winbindd_request(WINBINDD_CHECK_MACHACC, NULL, &response) ==
- NSS_STATUS_SUCCESS;
-
- if (result) {
-
- if (response.data.num_entries) {
- printf("Secret is good\n");
- } else {
- printf("Secret is bad\n");
- }
-
- return True;
- }
-
return False;
}
/* Send request */
request.data.uid = uid;
- if (winbindd_request(WINBINDD_UID_TO_SID, &request, &response) !=
- NSS_STATUS_SUCCESS) {
+ if (winbindd_request(WINBINDD_UID_TO_SID, &request, &response) ==
+ WINBINDD_ERROR) {
return False;
}
/* Send request */
request.data.gid = gid;
- if (winbindd_request(WINBINDD_GID_TO_SID, &request, &response) !=
- NSS_STATUS_SUCCESS) {
+ if (winbindd_request(WINBINDD_GID_TO_SID, &request, &response) ==
+ WINBINDD_ERROR) {
return False;
}
/* Send request */
fstrcpy(request.data.sid, sid);
- if (winbindd_request(WINBINDD_SID_TO_UID, &request, &response) !=
- NSS_STATUS_SUCCESS) {
+ if (winbindd_request(WINBINDD_SID_TO_UID, &request, &response) ==
+ WINBINDD_ERROR) {
return False;
}
/* Send request */
fstrcpy(request.data.sid, sid);
- if (winbindd_request(WINBINDD_SID_TO_GID, &request, &response) !=
- NSS_STATUS_SUCCESS) {
+ if (winbindd_request(WINBINDD_SID_TO_GID, &request, &response) ==
+ WINBINDD_ERROR) {
return False;
}
/* Send off request */
fstrcpy(request.data.sid, sid);
- if (winbindd_request(WINBINDD_LOOKUPSID, &request, &response) !=
- NSS_STATUS_SUCCESS) {
+ if (winbindd_request(WINBINDD_LOOKUPSID, &request, &response) ==
+ WINBINDD_ERROR) {
return False;
}
ZERO_STRUCT(response);
fstrcpy(request.data.name, name);
- if (winbindd_request(WINBINDD_LOOKUPNAME, &request, &response) !=
- NSS_STATUS_SUCCESS) {
+ if (winbindd_request(WINBINDD_LOOKUPNAME, &request, &response) ==
+ WINBINDD_ERROR) {
return False;
}
/* Print domain users */
-static BOOL wbinfo_list_users(void)
+static BOOL print_domain_users(void)
{
struct winbindd_response response;
fstring name;
ZERO_STRUCT(response);
- if (winbindd_request(WINBINDD_LIST_USERS, NULL, &response) !=
- NSS_STATUS_SUCCESS) {
+ if (winbindd_request(WINBINDD_LIST_USERS, NULL, &response) ==
+ WINBINDD_ERROR) {
return False;
}
/* Look through extra data */
if (!response.extra_data) {
- return True;
+ return False;
}
while(next_token((char **)&response.extra_data, name, ",",
/* Print domain groups */
-static BOOL wbinfo_list_groups(void)
+static BOOL print_domain_groups(void)
{
struct winbindd_response response;
fstring name;
ZERO_STRUCT(response);
- if (winbindd_request(WINBINDD_LIST_GROUPS, NULL, &response) !=
- NSS_STATUS_SUCCESS) {
+ if (winbindd_request(WINBINDD_LIST_GROUPS, NULL, &response) ==
+ WINBINDD_ERROR) {
return False;
}
/* Look through extra data */
if (!response.extra_data) {
- return True;
+ return False;
}
while(next_token((char **)&response.extra_data, name, ",",
printf("\t-Y sid\tconverts sid to gid\n");
printf("\t-t\tcheck shared secret\n");
printf("\t-m\tlist trusted domains\n");
+ printf("\t-r user\tget user groups\n");
}
/* Main program */
return 1;
}
- while ((opt = getopt(argc, argv, "ugs:n:U:G:S:Y:tm")) != EOF) {
+ while ((opt = getopt(argc, argv, "ugs:n:U:G:S:Y:tmr:")) != EOF) {
switch (opt) {
case 'u':
- if (!wbinfo_list_users()) {
+ if (!print_domain_users()) {
printf("Error looking up domain users\n");
return 1;
}
break;
case 'g':
- if (!wbinfo_list_groups()) {
+ if (!print_domain_groups()) {
printf("Error looking up domain groups\n");
return 1;
}
return 1;
}
break;
+ case 'r':
+ if (!wbinfo_get_usergroups(optarg)) {
+ printf("Could not get groups for user %s\n",
+ optarg);
+ return 1;
+ }
+ break;
/* Invalid option */