diff options
author | Jim McDonough <jmcd@samba.org> | 2002-03-29 21:09:44 +0000 |
---|---|---|
committer | Jim McDonough <jmcd@samba.org> | 2002-03-29 21:09:44 +0000 |
commit | b94791f1d4a34d8c845dcfc7d1689e4131acab8e (patch) | |
tree | 84937096b06a1b77646d7bafc7f088114ce4f2f9 /source3/utils | |
parent | 2ed1dfcf4e467a2816f3b768c8b37f2cdf3c7758 (diff) | |
download | samba-b94791f1d4a34d8c845dcfc7d1689e4131acab8e.tar.gz samba-b94791f1d4a34d8c845dcfc7d1689e4131acab8e.tar.bz2 samba-b94791f1d4a34d8c845dcfc7d1689e4131acab8e.zip |
Re-implemented net ads user and net ads group to use the new
ads_process_results function. Also made sure net rap user and net ads
user display the same thing, to make auto-transport-detection smoother.
(This used to be commit 4cf42c07ec5deb14921fabfbd52a8a3345a730c9)
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net_ads.c | 64 | ||||
-rw-r--r-- | source3/utils/net_rap.c | 12 |
2 files changed, 54 insertions, 22 deletions
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 7981bedb7e..76036b1b1e 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -121,24 +121,54 @@ retry: return ads; } +static void usergrp_display(char *field, void **values, void *data_area) +{ + char **disp_fields = (char **) data_area; + + if (!field) { /* must be end of record */ + if (disp_fields[1]) + printf("%-21.21s %-50.50s\n", + disp_fields[0], disp_fields[1]); + else + printf("%s\n", disp_fields[0]); + SAFE_FREE(disp_fields[0]); + SAFE_FREE(disp_fields[1]); + return; + } + if (StrCaseCmp(field, "sAMAccountName") == 0) { + disp_fields[0] = strdup(((struct berval *) values[0])->bv_val); + } + if (StrCaseCmp(field, "description") == 0) + disp_fields[1] = strdup(((struct berval *) values[0])->bv_val); +} + static int net_ads_user(int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS rc; void *res; - const char *attrs[] = {"sAMAccountName", "name", "objectSid", NULL}; + const char *shortattrs[] = {"sAMAccountName", NULL}; + const char *longattrs[] = {"sAMAccountName", "description", NULL}; + extern int opt_long_list_entries; + char *disp_fields[2] = {NULL, NULL}; if (!(ads = ads_startup())) return -1; - rc = ads_do_search_all(ads, ads->bind_path, - LDAP_SCOPE_SUBTREE, - "(objectclass=user)", attrs, &res); + rc = ads_do_search_all(ads, ads->bind_path, LDAP_SCOPE_SUBTREE, + "(objectclass=user)", opt_long_list_entries ? + longattrs : shortattrs, &res); if (!ADS_ERR_OK(rc)) { d_printf("ads_search: %s\n", ads_errstr(rc)); return -1; } - ads_dump(ads, res); + + if (opt_long_list_entries) + d_printf("\nUser name Comment"\ + "\n-----------------------------\n"); + ads_process_results(ads, res, usergrp_display, disp_fields); + ads_msgfree(ads, res); + ads_destroy(&ads); return 0; } @@ -148,19 +178,28 @@ static int net_ads_group(int argc, const char **argv) ADS_STRUCT *ads; ADS_STATUS rc; void *res; - const char *attrs[] = {"sAMAccountName", "name", "objectSid", NULL}; + const char *shortattrs[] = {"sAMAccountName", NULL}; + const char *longattrs[] = {"sAMAccountName", "description", NULL}; + extern int opt_long_list_entries; + char *disp_fields[2] = {NULL, NULL}; if (!(ads = ads_startup())) return -1; - rc = ads_do_search_all(ads, ads->bind_path, - LDAP_SCOPE_SUBTREE, - "(objectclass=group)", attrs, &res); + rc = ads_do_search_all(ads, ads->bind_path, LDAP_SCOPE_SUBTREE, + "(objectclass=group)", opt_long_list_entries ? + longattrs : shortattrs, &res); + if (!ADS_ERR_OK(rc)) { d_printf("ads_search: %s\n", ads_errstr(rc)); return -1; } - ads_dump(ads, res); + if (opt_long_list_entries) + d_printf("\nGroup name Comment"\ + "\n-----------------------------\n"); + ads_process_results(ads, res, usergrp_display, disp_fields); + ads_msgfree(ads, res); + ads_destroy(&ads); return 0; } @@ -353,10 +392,7 @@ static int net_ads_printer_info(int argc, const char **argv) } ads_dump(ads, res); - /* I wanted to do this ads_msgfree, but it coredumps...why? - the ads_dump routine doesn't free it, or does it partially - free it as it walks through the result? - ads_msgfree(ads, res); */ + ads_msgfree(ads, res); return 0; } diff --git a/source3/utils/net_rap.c b/source3/utils/net_rap.c index d1cc8271f7..f9bb7300d8 100644 --- a/source3/utils/net_rap.c +++ b/source3/utils/net_rap.c @@ -632,8 +632,8 @@ static void long_user_fn(const char *user_name, const char *comment, const char * home_dir, const char * logon_script, void *state) { - d_printf("%-21.21s %-47.47s %-35.35s %35.35s\n", - user_name, comment, home_dir, logon_script); + d_printf("%-21.21s %-50.50s\n", + user_name, comment); } static void group_member_fn(const char *user_name, void *state) @@ -721,12 +721,8 @@ int net_rap_user(int argc, const char **argv) if (!(cli = net_make_ipc_connection(0))) return -1; if (opt_long_list_entries) { - d_printf( - "\nListing users on remote server:\n\n"\ - "\nUser name Description "\ - "Home Directory Profile Directory"\ - "\n--------- ----------- "\ - "-------------- -----------------\n"); + d_printf("\nUser name Comment"\ + "\n-----------------------------\n"); ret = cli_RNetUserEnum(cli, long_user_fn, NULL); cli_shutdown(cli); return ret; |