From 6b0dd468556c047a7f67ba8314cf166b7475b7b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnther=20Deschner?= Date: Tue, 2 Sep 2008 16:14:14 +0200 Subject: [PATCH] netdomjoin-gui: test all NetServerGetInfo levels until we get comment. (cherry picked from commit 56d353b406ef77808b9cb968fcba387f301cf2de) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 65 ++++++++++++++++------ 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 9afdb8b58ca..def56ae0b62 100644 --- a/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -1585,6 +1585,51 @@ static int init_join_state(struct join_state **state) return 0; } +static NET_API_STATUS get_server_comment(struct join_state *state) +{ + struct SERVER_INFO_101 *info101 = NULL; + struct SERVER_INFO_1005 *info1005 = NULL; + NET_API_STATUS status; + + status = NetServerGetInfo(state->target_hostname, + 101, + (uint8_t **)&info101); + if (status == 0) { + state->comment = strdup(info101->sv101_comment); + if (!state->comment) { + return -1; + } + NetApiBufferFree(info101); + return NET_API_STATUS_SUCCESS; + } + + switch (status) { + case 124: /* WERR_UNKNOWN_LEVEL */ + case 50: /* WERR_NOT_SUPPORTED */ + break; + default: + goto failed; + } + + status = NetServerGetInfo(state->target_hostname, + 1005, + (uint8_t **)&info1005); + if (status == 0) { + state->comment = strdup(info1005->sv1005_comment); + if (!state->comment) { + return -1; + } + NetApiBufferFree(info1005); + return NET_API_STATUS_SUCCESS; + } + + failed: + printf("NetServerGetInfo failed with: %s\n", + libnetapi_get_error_string(state->ctx, status)); + + return status; +} + static int initialize_join_state(struct join_state *state, const char *debug_level, const char *target_hostname, @@ -1689,23 +1734,9 @@ static int initialize_join_state(struct join_state *state, NetApiBufferFree((void *)buffer); } - { - struct SERVER_INFO_101 *info101 = NULL; - - status = NetServerGetInfo(state->target_hostname, - 101, - (uint8_t **)&info101); - if (status != 0) { - printf("NetServerGetInfo failed with: %s\n", - libnetapi_get_error_string(state->ctx, status)); - /* return status; */ - } else { - state->comment = strdup(info101->sv101_comment); - if (!state->comment) { - return -1; - } - } - NetApiBufferFree(info101); + status = get_server_comment(state); + if (status != 0) { + return -1; } state->ctx = ctx; -- 2.11.4.GIT