diff options
author | Günther Deschner <gd@samba.org> | 2008-01-18 02:30:09 +0100 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2008-01-18 02:54:36 +0100 |
commit | bb97b272a975e4af7738c58e7af4b8e3047d4b77 (patch) | |
tree | 495ac773d0634047ac254744f27c5f6a8a9a0c8f /source3/lib | |
parent | c2ff6c94f2f9ddc2c4b03f7907f7d6e0de951c24 (diff) | |
download | samba-bb97b272a975e4af7738c58e7af4b8e3047d4b77.tar.gz samba-bb97b272a975e4af7738c58e7af4b8e3047d4b77.tar.bz2 samba-bb97b272a975e4af7738c58e7af4b8e3047d4b77.zip |
Fix local hostname detection in netdomjoin-gui.
Guenther
(This used to be commit 30458116b389889cad845eb96b54c3edc833e722)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 37 |
1 files changed, 27 insertions, 10 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..6e958b4c73 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> @@ -1263,28 +1264,44 @@ 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); } { |