diff options
Diffstat (limited to 'source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c')
-rw-r--r-- | source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 9dc2a18138..73b14d4d87 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -24,6 +24,7 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> +#include <netdb.h> #include <gtk/gtk.h> #include <glib/gprintf.h> @@ -439,7 +440,7 @@ static void callback_do_join(GtkWidget *widget, state->password, unjoin_flags); if (status != 0) { - err_str = libnetapi_errstr(status); + err_str = libnetapi_get_error_string(state->ctx, status); g_print("callback_do_join: failed to unjoin (%s)\n", err_str); @@ -463,7 +464,7 @@ static void callback_do_join(GtkWidget *widget, state->password, join_flags); if (status != 0) { - err_str = libnetapi_errstr(status); + err_str = libnetapi_get_error_string(state->ctx, status); g_print("callback_do_join: failed to join (%s)\n", err_str); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), @@ -1263,37 +1264,56 @@ static int initialize_join_state(struct join_state *state, { char my_hostname[HOST_NAME_MAX]; const char *p = NULL; + struct hostent *hp = NULL; + if (gethostname(my_hostname, sizeof(my_hostname)) == -1) { return -1; } - state->my_fqdn = strdup(my_hostname); + p = strchr(my_hostname, '.'); + if (p) { + my_hostname[strlen(my_hostname)-strlen(p)] = '\0'; + } + state->my_hostname = strdup(my_hostname); + if (!state->my_hostname) { + return -1; + } + debug("state->my_hostname: %s\n", state->my_hostname); + + hp = gethostbyname(my_hostname); + if (!hp || !hp->h_name || !*hp->h_name) { + return -1; + } + + state->my_fqdn = strdup(hp->h_name); if (!state->my_fqdn) { return -1; } + debug("state->my_fqdn: %s\n", state->my_fqdn); - p = strchr(my_hostname, '.'); + p = strchr(state->my_fqdn, '.'); if (p) { - my_hostname[strlen(my_hostname) - strlen(p)] = '\0'; - state->my_hostname = strdup(my_hostname); - if (!state->my_hostname) { - return -1; - } p++; state->my_dnsdomain = strdup(p); - if (!state->my_dnsdomain) { - return -1; - } + } else { + state->my_dnsdomain = strdup(""); + } + if (!state->my_dnsdomain) { + return -1; } + debug("state->my_dnsdomain: %s\n", state->my_dnsdomain); } { const char *buffer = NULL; uint16_t type = 0; status = NetGetJoinInformation(NULL, &buffer, &type); - if (status) { + if (status != 0) { + printf("NetGetJoinInformation failed with: %s\n", + libnetapi_get_error_string(state->ctx, status)); return status; } + debug("NetGetJoinInformation gave: %s and %d\n", buffer, type); state->name_buffer_initial = strdup(buffer); if (!state->name_buffer_initial) { return -1; @@ -1307,7 +1327,9 @@ static int initialize_join_state(struct join_state *state, uint8_t *buffer = NULL; status = NetServerGetInfo(NULL, 1005, &buffer); - if (status) { + if (status != 0) { + printf("NetServerGetInfo failed with: %s\n", + libnetapi_get_error_string(state->ctx, status)); return status; } |