From 77a2e13cb1950cfd591f31b6a12eae66c342e632 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 21 Dec 2007 17:05:55 +0100 Subject: Move libnetapi examples into subdirs. Guenther (This used to be commit 0c3de6f3458419e57daaa71f1dad679897388f5a) --- source3/lib/netapi/examples/netdomjoin-gui/logo.png | Bin 0 -> 9329 bytes source3/lib/netapi/examples/netdomjoin-gui/samba.ico | Bin 0 -> 1406 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 source3/lib/netapi/examples/netdomjoin-gui/logo.png create mode 100755 source3/lib/netapi/examples/netdomjoin-gui/samba.ico (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/logo.png b/source3/lib/netapi/examples/netdomjoin-gui/logo.png new file mode 100644 index 0000000000..6df4ace659 Binary files /dev/null and b/source3/lib/netapi/examples/netdomjoin-gui/logo.png differ diff --git a/source3/lib/netapi/examples/netdomjoin-gui/samba.ico b/source3/lib/netapi/examples/netdomjoin-gui/samba.ico new file mode 100755 index 0000000000..b70c9590de Binary files /dev/null and b/source3/lib/netapi/examples/netdomjoin-gui/samba.ico differ -- cgit From 657afffaae0ce25d0417095b67adbe1441835301 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 21 Dec 2007 17:29:15 +0100 Subject: Move gtk app to the correct location. Thanks obnox! Guenther (This used to be commit 740a2b080db56d504c4edd58bf41d72edb3d32ee) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 1347 ++++++++++++++++++++ 1 file changed, 1347 insertions(+) create mode 100644 source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c new file mode 100644 index 0000000000..8ca6897cab --- /dev/null +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -0,0 +1,1347 @@ +/* + * Unix SMB/CIFS implementation. + * Join Support (gtk + netapi) + * Copyright (C) Guenther Deschner 2007 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define MAX_CRED_LEN 256 +#define MAX_NETBIOS_NAME_LEN 15 + +#define SAMBA_ICON_PATH "/usr/share/pixmaps/samba/samba.ico" +#define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" + +#define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) +#define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) +#define WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE ( 0x00000002 ) +#define WKSSVC_JOIN_FLAGS_JOIN_TYPE ( 0x00000001 ) + +#define NetSetupWorkgroupName ( 2 ) +#define NetSetupDomainName ( 3 ) + +#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) + +struct srvsvc_NetSrvInfo1005 { + const char *comment;/* [unique,charset(UTF16)] */ +}; + +static gboolean verbose = FALSE; + +typedef struct join_state { + struct libnetapi_ctx *ctx; + GtkWidget *window_main; + GtkWidget *window_parent; + GtkWidget *window_do_change; + GtkWidget *window_creds_prompt; + GtkWidget *entry_account; + GtkWidget *entry_password; + GtkWidget *entry_domain; + GtkWidget *entry_workgroup; + GtkWidget *button_ok; + GtkWidget *button_apply; + GtkWidget *button_ok_creds; + GtkWidget *label_reboot; + GtkWidget *label_current_name_buffer; + GtkWidget *label_current_name_type; + GtkWidget *label_full_computer_name; + uint16_t name_type_initial; + uint16_t name_type_new; + char *name_buffer_initial; + char *name_buffer_new; + char *password; + char *account; + char *comment; + char *comment_new; + char *my_fqdn; + char *my_dnsdomain; + char *my_hostname; + uint16_t server_role; + gboolean settings_changed; + gboolean hostname_changed; +} join_state; + +static void debug(const char *format, ...) +{ + va_list args; + + if (!verbose) { + return; + } + + va_start(args, format); + g_vprintf(format, args); + va_end(args); +} + +static gboolean callback_delete_event(GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + gtk_main_quit(); + return FALSE; +} + +static void callback_do_close(GtkWidget *widget, + gpointer data) +{ + debug("Closing now...\n"); + gtk_widget_destroy(data); +} + +static void free_join_state(struct join_state *s) +{ + SAFE_FREE(s->name_buffer_initial); + SAFE_FREE(s->name_buffer_new); + SAFE_FREE(s->password); + SAFE_FREE(s->account); + SAFE_FREE(s->comment); + SAFE_FREE(s->comment_new); + SAFE_FREE(s->my_fqdn); + SAFE_FREE(s->my_dnsdomain); + SAFE_FREE(s->my_hostname); + +} + +static void do_cleanup(struct join_state *state) +{ + libnetapi_free(state->ctx); + free_join_state(state); +} + +static void callback_apply_description_change(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + NET_API_STATUS status = 0; + uint32_t parm_err = 0; + struct srvsvc_NetSrvInfo1005 info1005; + GtkWidget *dialog; + + info1005.comment = state->comment_new; + + status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); + if (status) { + debug("NetServerSetInfo failed with: %s\n", + libnetapi_errstr(state->ctx, status)); + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "Failed to change computer description: %s.", + libnetapi_errstr(state->ctx, status)); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + return; + } + + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); +} + +static void callback_do_exit(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + gint result; + struct join_state *state = (struct join_state *)data; + + if (!state->settings_changed) { + callback_delete_event(NULL, NULL, NULL); + return; + } + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + "You must restart your computer before the new settings will take effect."); + result = gtk_dialog_run(GTK_DIALOG(dialog)); + switch (result) { + case GTK_RESPONSE_YES: + g_print("would reboot here\n"); + break; + case GTK_RESPONSE_NO: + default: + break; + } + gtk_widget_destroy(dialog); + gtk_widget_destroy(state->window_main); + do_cleanup(state); + exit(0); +} + + +static void callback_do_reboot(GtkWidget *widget, + gpointer data, + gpointer data2) +{ + GtkWidget *dialog; + struct join_state *state = (struct join_state *)data2; + + debug("callback_do_reboot\n"); + + state->settings_changed = TRUE; + dialog = gtk_message_dialog_new(GTK_WINDOW(data), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "You must restart this computer for the changes to take effect."); +#if 0 + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + debug("showing dialog\n"); + gtk_widget_show(dialog); +#else + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); +#endif + + gtk_label_set_text(GTK_LABEL(state->label_reboot), "Changes will take effect after you restart this computer"); + + debug("destroying do_change window\n"); + gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); + + { + uint32_t status; + const char *buffer; + uint16_t type; + + status = NetGetJoinInformation(NULL, &buffer, &type); + if (status != 0) { + g_print("failed to query status\n"); + return; + } + + debug("got new status: %s\n", buffer); +#if 0 + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(buffer); + SAFE_FREE(buffer); + state->name_type_new = type; +#endif + gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), state->name_buffer_new); + if (state->name_type_new == 3) { + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Domain:"); + } else { + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Workgroup:"); + } + } +} + +static void callback_return_username(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_return_username: %s\n", entry_text); + SAFE_FREE(state->account); + state->account = strdup(entry_text); +} + +static void callback_return_username_and_enter(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_return_username: %s\n", entry_text); + SAFE_FREE(state->account); + state->account = strdup(entry_text); + g_signal_emit_by_name(state->button_ok_creds, "clicked"); +} + +static void callback_return_password(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); +#ifdef DEBUG_PASSWORD + debug("callback_return_password: %s\n", entry_text); +#else + debug("callback_return_password: (not printed)\n"); +#endif + SAFE_FREE(state->password); + state->password = strdup(entry_text); +} + +static void callback_return_password_and_enter(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text; + struct join_state *state = (struct join_state *)data; + if (!widget) { + return; + } + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); +#ifdef DEBUG_PASSWORD + debug("callback_return_password: %s\n", entry_text); +#else + debug("callback_return_password: (not printed)\n"); +#endif + SAFE_FREE(state->password); + state->password = strdup(entry_text); + g_signal_emit_by_name(state->button_ok_creds, "clicked"); +} + +static void callback_do_hostname_change(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + const char *str = NULL; + + struct join_state *state = (struct join_state *)data; + + switch (state->name_type_initial) { + case NetSetupDomainName: + str = "To be implemented: call NetRenameMachineInDomain\n"; + break; + case NetSetupWorkgroupName: + str = "To be implemented: call SetComputerNameEx\n"; + break; + default: + break; + } + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + gtk_widget_show(dialog); +} + +static void callback_do_join(GtkWidget *widget, + gpointer data) +{ + GtkWidget *dialog; + + NET_API_STATUS status; + const char *err_str = NULL; + uint32_t join_flags = 0; + uint32_t unjoin_flags = 0; + gboolean domain_join = FALSE; + gboolean try_unjoin = FALSE; + const char *domain_or_workgroup = NULL; + + struct join_state *state = (struct join_state *)data; + + callback_return_username(state->entry_account, state); + callback_return_password(state->entry_password, state); + + if (state->window_creds_prompt) { + gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + } + + if (state->name_type_new == NetSetupDomainName) { + domain_join = TRUE; + join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | + WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | + WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ + domain_or_workgroup = "domain"; + } else { + domain_or_workgroup = "workgroup"; + } + + if ((state->name_type_initial == NetSetupDomainName) && + (state->name_type_new == NetSetupWorkgroupName)) { + try_unjoin = TRUE; + unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | + WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; + } + + debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", + domain_or_workgroup, + state->name_buffer_new, + join_flags); + if (domain_join) { + debug("as %s ", state->account); +#ifdef DEBUG_PASSWORD + debug("with %s ", state->password); +#endif + } + debug("\n"); + if (try_unjoin) { + + debug("callback_do_join: Unjoining\n"); + + status = NetUnjoinDomain(NULL, + state->account, + state->password, + unjoin_flags); + if (status != 0) { + err_str = libnetapi_errstr(state->ctx, status); + g_print("callback_do_join: failed to unjoin (%s)\n", + err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "The following error occured attempting to unjoin the %s: \"%s\": %s", + domain_or_workgroup, + state->name_buffer_new, + err_str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + + } + status = NetJoinDomain(NULL, + state->name_buffer_new, + NULL, + state->account, + state->password, + join_flags); + if (status != 0) { + err_str = libnetapi_errstr(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), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "The following error occured attempting to join the %s: \"%s\": %s", + domain_or_workgroup, + state->name_buffer_new, + err_str); + + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + + debug("callback_do_join: Successfully joined %s\n", + domain_or_workgroup); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "Welcome to the %s %s.", + state->name_buffer_new, + domain_or_workgroup); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + callback_do_reboot(NULL, state->window_parent, state); +} + +static void callback_creds_prompt(GtkWidget *widget, + gpointer data) +{ + GtkWidget *window; + GtkWidget *box1; + GtkWidget *bbox; + GtkWidget *button; + GtkWidget *label; + + struct join_state *state = (struct join_state *)data; + + debug("callback_creds_prompt:\n"); + + state->window_parent = state->window_do_change; + + if (state->hostname_changed) { + return callback_do_hostname_change(NULL, state); + } + + if ((state->name_type_initial != NetSetupDomainName) && + (state->name_type_new != NetSetupDomainName)) { + return callback_do_join(NULL, state); + } + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); + gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); +/* gtk_window_set_icon_name(GTK_WIDGET(window), GTK_STOCK_DIALOG_AUTHENTICATION); */ + state->window_creds_prompt = window; + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_do_close), window); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + box1 = gtk_vbox_new(FALSE, 0); + + gtk_container_add(GTK_CONTAINER(window), box1); + + if ((state->name_type_initial == NetSetupDomainName) && + (state->name_type_new == NetSetupWorkgroupName)) { + label = gtk_label_new("Enter the name and password of an account with permission to leave the domain.\n"); + } else { + label = gtk_label_new("Enter the name and password of an account with permission to join the domain.\n"); + } + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + + gtk_widget_show(label); + + /* USER NAME */ + label = gtk_label_new("User name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_account = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_account), MAX_CRED_LEN); + g_signal_connect(G_OBJECT(state->entry_account), "activate", + G_CALLBACK(callback_return_username_and_enter), + (gpointer)state); + gtk_editable_select_region(GTK_EDITABLE(state->entry_account), + 0, GTK_ENTRY(state->entry_account)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_account, TRUE, TRUE, 0); + gtk_widget_show(state->entry_account); + + /* PASSWORD */ + label = gtk_label_new("Password:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_password = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_password), MAX_CRED_LEN); + gtk_entry_set_visibility(GTK_ENTRY(state->entry_password), FALSE); + g_signal_connect(G_OBJECT(state->entry_password), "activate", + G_CALLBACK(callback_return_password_and_enter), + (gpointer)state); + gtk_editable_set_editable(GTK_EDITABLE(state->entry_password), TRUE); + gtk_editable_select_region(GTK_EDITABLE(state->entry_password), + 0, GTK_ENTRY(state->entry_password)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_password, TRUE, TRUE, 0); + gtk_widget_show(state->entry_password); + + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(box1), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + state->button_ok_creds = gtk_button_new_from_stock(GTK_STOCK_OK); + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok_creds)); + gtk_container_add(GTK_CONTAINER(bbox), state->button_ok_creds); + g_signal_connect(G_OBJECT(state->button_ok_creds), "clicked", + G_CALLBACK(callback_do_join), + (gpointer)state); + gtk_widget_show(state->button_ok_creds); + + button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox), button); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_close), (gpointer) window); + gtk_widget_show_all(window); +} + +static void callback_enter_hostname_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + char *str = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_hostname_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + state->hostname_changed = FALSE; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->my_hostname, entry_text) == 0) { + state->hostname_changed = FALSE; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + state->hostname_changed = TRUE; + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + } else { + asprintf(&str, "%s.", entry_text); + } + gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); + free(str); + + if (state->hostname_changed && str && str[0] != 0 && str[0] != '.') { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + } +} + +static void callback_enter_computer_description_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + int string_unchanged = 0; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_computer_description_and_unlock: %s\n", + entry_text); +#if 0 + if (!entry_text || entry_text[0] == 0) { + string_unchanged = 1; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), + FALSE); + return; + } +#endif + if (entry_text && strcasecmp(state->comment, entry_text) == 0) { + string_unchanged = 1; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), + FALSE); + return; + } + + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), TRUE); + SAFE_FREE(state->comment_new); + state->comment_new = strdup(entry_text); + +} + + +static void callback_enter_workgroup_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_workgroup_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(entry_text); + state->name_type_new = NetSetupWorkgroupName; +} + +static void callback_enter_domain_and_unlock(GtkWidget *widget, + gpointer data) +{ + const gchar *entry_text = NULL; + struct join_state *state = (struct join_state *)data; + + entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + debug("callback_enter_domain_and_unlock: %s\n", entry_text); + if (!entry_text || entry_text[0] == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + if (strcasecmp(state->name_buffer_initial, entry_text) == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); + return; + } + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + SAFE_FREE(state->name_buffer_new); + state->name_buffer_new = strdup(entry_text); + state->name_type_new = NetSetupDomainName; +} + +static void callback_continue(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok)); + g_signal_emit_by_name(state->button_ok, "clicked"); +} + +static void callback_apply_continue(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + gtk_widget_grab_focus(GTK_WIDGET(state->button_apply)); + g_signal_emit_by_name(state->button_apply, "clicked"); +} + +static void callback_do_join_workgroup(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + debug("callback_do_join_workgroup choosen\n"); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); + gtk_widget_grab_focus(GTK_WIDGET(state->entry_workgroup)); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); + callback_enter_workgroup_and_unlock(state->entry_workgroup, state); /* TEST */ +} + +static void callback_do_join_domain(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + debug("callback_do_join_domain choosen\n"); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), TRUE); + gtk_widget_grab_focus(GTK_WIDGET(state->entry_domain)); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), FALSE); + callback_enter_domain_and_unlock(state->entry_domain, state); /* TEST */ +} + +static void callback_do_change(GtkWidget *widget, + gpointer data) +{ + GtkWidget *window; + GtkWidget *box1; + GtkWidget *bbox; + GtkWidget *button_workgroup; + GtkWidget *button_domain; + GtkWidget *button; + GtkWidget *label; + GtkWidget *frame_horz; + GtkWidget *vbox; + GtkWidget *entry; + GSList *group; + + struct join_state *state = (struct join_state *)data; + + debug("callback_do_change called\n"); + + if (state->server_role == 3) { + GtkWidget *dialog; + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "Domain controller cannot be moved from one domain to another, they must first be demoted. Renaming this domain controller may cause it to become temporarily unavailable to users and computers. For information on renaming domain controllers, including alternate renaming methods, see Help and Support. To continue renaming this domain controller, click OK."); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + return; + } + + state->button_ok = gtk_button_new_from_stock(GTK_STOCK_OK); + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); /* breite * höhe */ + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_do_close), window); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + box1 = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(window), box1); + + label = gtk_label_new("You can change the name and membership of this computer. Changes may affect access to network ressources."); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + /* COMPUTER NAME */ + label = gtk_label_new("Computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + state->label_full_computer_name = gtk_label_new(NULL); + { + entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(entry), MAX_NETBIOS_NAME_LEN); + g_signal_connect(G_OBJECT(entry), "changed", + G_CALLBACK(callback_enter_hostname_and_unlock), + (gpointer)state); + gtk_entry_set_text(GTK_ENTRY(entry), state->my_hostname); + gtk_editable_select_region(GTK_EDITABLE(entry), + 0, GTK_ENTRY(entry)->text_length); + + gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ + gtk_box_pack_start(GTK_BOX(box1), entry, TRUE, TRUE, 0); + gtk_widget_show(entry); + } + + /* FULL COMPUTER NAME */ + label = gtk_label_new("Full computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + { + const gchar *entry_text; + char *str = NULL; + entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + } else { + asprintf(&str, "%s.", entry_text); + } + gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); + free(str); + gtk_misc_set_alignment(GTK_MISC(state->label_full_computer_name), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), state->label_full_computer_name, TRUE, TRUE, 0); + gtk_widget_show(state->label_full_computer_name); + } + + /* BOX */ + frame_horz = gtk_frame_new ("Member Of"); + gtk_box_pack_start(GTK_BOX(box1), frame_horz, TRUE, TRUE, 10); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + gtk_container_add(GTK_CONTAINER(frame_horz), vbox); + + /* TWO ENTRIES */ + state->entry_workgroup = gtk_entry_new(); + state->entry_domain = gtk_entry_new(); + + /* DOMAIN */ + button_domain = gtk_radio_button_new_with_label(NULL, "Domain"); + if (state->name_type_initial == NetSetupDomainName) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_domain), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), button_domain, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button_domain), "clicked", + G_CALLBACK(callback_do_join_domain), + (gpointer)state); + + { + gtk_entry_set_max_length(GTK_ENTRY(state->entry_domain), 50); + g_signal_connect(G_OBJECT(state->entry_domain), "changed", + G_CALLBACK(callback_enter_domain_and_unlock), + (gpointer)state); + g_signal_connect(G_OBJECT(state->entry_domain), "activate", + G_CALLBACK(callback_continue), + (gpointer)state); + if (state->name_type_initial == NetSetupDomainName) { + gtk_entry_set_text(GTK_ENTRY(state->entry_domain), state->name_buffer_initial); + gtk_widget_set_sensitive(state->entry_workgroup, FALSE); + gtk_widget_set_sensitive(state->entry_domain, TRUE); + } + gtk_editable_set_editable(GTK_EDITABLE(state->entry_domain), TRUE); + gtk_box_pack_start(GTK_BOX(vbox), state->entry_domain, TRUE, TRUE, 0); + gtk_widget_show(state->entry_domain); + } + gtk_widget_show(button_domain); + + /* WORKGROUP */ + group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button_domain)); + button_workgroup = gtk_radio_button_new_with_label(group, "Workgroup"); + if (state->name_type_initial == NetSetupWorkgroupName) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_workgroup), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), button_workgroup, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button_workgroup), "clicked", + G_CALLBACK(callback_do_join_workgroup), + (gpointer)state); + { + gtk_entry_set_max_length(GTK_ENTRY(state->entry_workgroup), MAX_NETBIOS_NAME_LEN); + g_signal_connect(G_OBJECT(state->entry_workgroup), "changed", + G_CALLBACK(callback_enter_workgroup_and_unlock), + (gpointer)state); + g_signal_connect(G_OBJECT(state->entry_workgroup), "activate", + G_CALLBACK(callback_continue), + (gpointer)state); + + if (state->name_type_initial == NetSetupWorkgroupName) { + gtk_entry_set_text(GTK_ENTRY(state->entry_workgroup), state->name_buffer_initial); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); + } + gtk_box_pack_start(GTK_BOX(vbox), state->entry_workgroup, TRUE, TRUE, 0); + gtk_widget_show(state->entry_workgroup); + } + gtk_widget_show(button_workgroup); + + /* BUTTONS */ + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(box1), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + state->window_do_change = window; + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); /* !!! */ + gtk_container_add(GTK_CONTAINER(bbox), state->button_ok); + g_signal_connect(G_OBJECT(state->button_ok), "clicked", + G_CALLBACK(callback_creds_prompt), + (gpointer)state); + + button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox), button); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_close), + (gpointer)window); + + gtk_widget_show_all(window); + +} + +static void callback_do_about(GtkWidget *widget, + gpointer data) +{ + GdkPixbuf *logo; + GError *error = NULL; + + debug("callback_do_about called\n"); + + logo = gdk_pixbuf_new_from_file(SAMBA_IMAGE_PATH, + &error); + if (logo == NULL) { + g_print("failed to load logo from %s: %s\n", + SAMBA_IMAGE_PATH, error->message); + } + + gtk_show_about_dialog(data, + "name", "Samba", + "version", "3.2.0pre2-GIT-904a90-test", + "copyright", "Copyright Andrew Tridgell and the Samba Team 1992-2007", + "website", "http://www.samba.org", + "license", "GPLv3", + "logo", logo, + "comments", "Samba gtk domain join utility", + NULL); +} + +static int draw_main_window(struct join_state *state) +{ + GtkWidget *window; + GtkWidget *button; + GtkWidget *label; + GtkWidget *main_vbox; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *bbox; + GtkWidget *image; + GtkWidget *table; + GtkWidget *entry; + GdkPixbuf *icon; + GError *error = NULL; + + icon = gdk_pixbuf_new_from_file(SAMBA_ICON_PATH, + &error); + if (icon == NULL) { + g_print("failed to load logo from %s : %s\n", + SAMBA_ICON_PATH, error->message); + } + +#if 1 + image = gtk_image_new_from_file(SAMBA_IMAGE_PATH); +#else + image = gtk_image_new_from_file("/usr/share/pixmaps/redhat-system_settings.png"); +#endif + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + state->window_main = window; + + gtk_window_set_title(GTK_WINDOW(window), "Samba - Join Domain dialogue"); + gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); /* breite * höhe */ + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_delete_event), NULL); + + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + main_vbox = gtk_vbox_new(FALSE, 10); + gtk_container_add(GTK_CONTAINER(window), main_vbox); + +#if 0 + gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); + gtk_widget_show(image); +#endif + /* Hbox */ + hbox = gtk_hbox_new(FALSE, 10); + gtk_container_add(GTK_CONTAINER(main_vbox), hbox); + + { +/* gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); */ + gtk_misc_set_alignment(GTK_MISC(image), 0, 0); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 10); + gtk_widget_show(image); + + /* Label */ + label = gtk_label_new("Samba uses the following information to identify your computer on the network."); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_widget_set_size_request(GTK_WIDGET(label), 500, 40); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + gtk_widget_show(label); + } + + gtk_widget_show(hbox); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + gtk_container_add(GTK_CONTAINER(main_vbox), vbox); + + /* Table */ + table = gtk_table_new(6, 3, TRUE); + gtk_table_set_row_spacings(GTK_TABLE(table), 5); + gtk_table_set_col_spacings(GTK_TABLE(table), 5); + gtk_container_add(GTK_CONTAINER(vbox), table); + + { + /* Label */ + label = gtk_label_new("Computer description:"); +/* gtk_misc_set_alignment(GTK_MISC(label), 0, 0); */ + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); + gtk_widget_show(label); + + state->button_apply = gtk_button_new_from_stock(GTK_STOCK_APPLY); + + /* Entry */ + entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(entry), 256); + g_signal_connect(G_OBJECT(entry), "changed", + G_CALLBACK(callback_enter_computer_description_and_unlock), + state); + g_signal_connect(G_OBJECT(entry), "activate", + G_CALLBACK(callback_apply_continue), + (gpointer)state); + + gtk_entry_set_text(GTK_ENTRY(entry), (char *)state->comment); + gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); /* ! */ + gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 3, 0, 1); + gtk_widget_show(entry); + } + + /* Label */ + label = gtk_label_new("For example: \"Samba \%v\"."); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 1, 2); + gtk_widget_show(label); + + /* Label */ + label = gtk_label_new("Full computer name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); + gtk_widget_show(label); + + { + /* Label */ + char *str = NULL; + if (state->name_type_initial == NetSetupDomainName) { + asprintf(&str, "%s.%s", state->my_hostname, + state->my_dnsdomain); + } else { + asprintf(&str, "%s.", state->my_hostname); + } + + label = gtk_label_new(str); + SAFE_FREE(str); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 2, 3); + gtk_widget_show(label); + } + + /* Label */ + if (state->name_type_initial == NetSetupDomainName) { + label = gtk_label_new("Domain:"); + } else { + label = gtk_label_new("Workgroup:"); + } + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); + gtk_widget_show(label); + state->label_current_name_type = label; + + /* Label */ + label = gtk_label_new(state->name_buffer_initial); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 3, 3, 4); + gtk_widget_show(label); + state->label_current_name_buffer = label; + + { + hbox = gtk_hbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(vbox), hbox); + label = gtk_label_new("To rename this computer or join a domain, click Change."); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + + + } + + /* bbox */ + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(hbox), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + button = gtk_button_new_with_mnemonic("Ch_ange"); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_change), + (gpointer)state); + gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0); + gtk_widget_show(button); + + /* Label (hidden) */ + state->label_reboot = gtk_label_new(NULL); + gtk_label_set_line_wrap(GTK_LABEL(state->label_reboot), TRUE); + gtk_misc_set_alignment(GTK_MISC(state->label_reboot), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), state->label_reboot, TRUE, TRUE, 0); + gtk_widget_show(state->label_reboot); + +#if 0 + gtk_box_pack_start(GTK_BOX(vbox), + create_bbox(window, TRUE, NULL, 10, 85, 20, GTK_BUTTONBOX_END), + TRUE, TRUE, 5); +#endif + { + + GtkWidget *frame; + GtkWidget *bbox2; + GtkWidget *button2; + + frame = gtk_frame_new(NULL); + bbox2 = gtk_hbutton_box_new(); + + gtk_container_set_border_width(GTK_CONTAINER(bbox2), 5); + gtk_container_add(GTK_CONTAINER(frame), bbox2); + + /* Set the appearance of the Button Box */ + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox2), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox2), 10); + /*gtk_button_box_set_child_size(GTK_BUTTON_BOX(bbox2), child_w, child_h);*/ + + button2 = gtk_button_new_from_stock(GTK_STOCK_OK); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_exit), state); + + button2 = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", + G_CALLBACK(callback_delete_event), + window); + + gtk_container_add(GTK_CONTAINER(bbox2), state->button_apply); + g_signal_connect(G_OBJECT(state->button_apply), "clicked", + G_CALLBACK(callback_apply_description_change), + state); + gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); + + button2 = gtk_button_new_from_stock(GTK_STOCK_ABOUT); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", + G_CALLBACK(callback_do_about), + window); + + gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 5); + } + + gtk_widget_show_all(window); + + return 0; +} + +static int init_join_state(struct join_state **state) +{ + struct join_state *s; + + s = malloc(sizeof(struct join_state)); + if (!s) { + return -1; + } + + memset(s, '\0', sizeof(struct join_state)); + + *state = s; + + return 0; +} + +static int initialize_join_state(struct join_state *state, + const char *debug_level) +{ + struct libnetapi_ctx *ctx = NULL; + NET_API_STATUS status = 0; + + status = libnetapi_init(&ctx); + if (status) { + return status; + } + + if (debug_level) { + libnetapi_set_debuglevel(ctx, debug_level); + } + + { + char my_hostname[HOST_NAME_MAX]; + const char *p = NULL; + if (gethostname(my_hostname, sizeof(my_hostname)) == -1) { + return -1; + } + + state->my_fqdn = strdup(my_hostname); + if (!state->my_fqdn) { + return -1; + } + + 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; + } + p++; + state->my_dnsdomain = strdup(p); + if (!state->my_dnsdomain) { + return -1; + } + } + } + + { + const char *buffer = NULL; + uint16_t type = 0; + status = NetGetJoinInformation(NULL, &buffer, &type); + if (status) { + return status; + } + state->name_buffer_initial = (char *)buffer; + state->name_type_initial = type; + } + + { + struct srvsvc_NetSrvInfo1005 *info1005 = NULL; + uint8_t *buffer = NULL; + + status = NetServerGetInfo(NULL, 1005, &buffer); + if (status) { + return status; + } + + info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; + + state->comment = strdup(info1005->comment); + if (!state->comment) { + return -1; + } + } +#if 0 + { + struct srvsvc_NetSrvInfo100 *info100 = NULL; + uint8_t *buffer = NULL; + + status = NetServerGetInfo(NULL, 100, &buffer); + if (status) { + return status; + } + + info100 = (struct srvsvc_NetSrvInfo100 *)buffer; + + state->comment = strdup(info100->comment); + if (!state->comment) { + return -1; + } + } +#endif + + state->ctx = ctx; + + return 0; +} + +int main(int argc, char **argv) +{ + GOptionContext *context = NULL; + static const char *debug_level = NULL; + struct join_state *state = NULL; + GError *error = NULL; + int ret = 0; + + static GOptionEntry entries[] = { + { "debug", 'd', 0, G_OPTION_ARG_STRING, &debug_level, "Debug level (for samba)", "N" }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output", 0 }, + { NULL } + }; + + context = g_option_context_new("- Samba domain join utility"); + g_option_context_add_main_entries(context, entries, NULL); +/* g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); */ + g_option_context_add_group(context, gtk_get_option_group(TRUE)); + g_option_context_parse(context, &argc, &argv, &error); + + gtk_init(&argc, &argv); + g_set_application_name("Samba"); + + ret = init_join_state(&state); + if (ret) { + return ret; + } + + ret = initialize_join_state(state, debug_level); + if (ret) { + return ret; + } + + draw_main_window(state); + + gtk_main(); + + do_cleanup(state); + + return 0; +} -- cgit From 86dfb55ffb99abf6fc61a91e58477790395abe38 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sat, 22 Dec 2007 00:02:45 +0100 Subject: Correct netapi header filename. Thanks Jeremy. Guenther (This used to be commit f192737ec8140aa6570bfb49a165b31890d63b16) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 8ca6897cab..beb12be8b1 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -28,7 +28,7 @@ #include #include -#include +#include #define MAX_CRED_LEN 256 #define MAX_NETBIOS_NAME_LEN 15 -- cgit From cf6e59de2b475e14660a9b71daad2ab5699d53a7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 4 Jan 2008 11:54:38 +0100 Subject: Fix some error strings in netdomjoin-gui. Guenther (This used to be commit aaea8f1ed744e9662f92a3840d86ad1aff943d18) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 43 ++++++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index beb12be8b1..3abf6fd5dc 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -1,7 +1,7 @@ /* * Unix SMB/CIFS implementation. * Join Support (gtk + netapi) - * Copyright (C) Guenther Deschner 2007 + * Copyright (C) Guenther Deschner 2007-2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -124,7 +124,6 @@ static void free_join_state(struct join_state *s) SAFE_FREE(s->my_fqdn); SAFE_FREE(s->my_dnsdomain); SAFE_FREE(s->my_hostname); - } static void do_cleanup(struct join_state *state) @@ -365,7 +364,8 @@ static void callback_do_join(GtkWidget *widget, uint32_t unjoin_flags = 0; gboolean domain_join = FALSE; gboolean try_unjoin = FALSE; - const char *domain_or_workgroup = NULL; + const char *new_workgroup_type = NULL; + const char *initial_workgroup_type = NULL; struct join_state *state = (struct join_state *)data; @@ -376,14 +376,33 @@ static void callback_do_join(GtkWidget *widget, gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); } + switch (state->name_type_initial) { + case NetSetupWorkgroupName: + initial_workgroup_type = "workgroup"; + break; + case NetSetupDomainName: + initial_workgroup_type = "domain"; + break; + default: + break; + } + + switch (state->name_type_new) { + case NetSetupWorkgroupName: + new_workgroup_type = "workgroup"; + break; + case NetSetupDomainName: + new_workgroup_type = "domain"; + break; + default: + break; + } + if (state->name_type_new == NetSetupDomainName) { domain_join = TRUE; join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ - domain_or_workgroup = "domain"; - } else { - domain_or_workgroup = "workgroup"; } if ((state->name_type_initial == NetSetupDomainName) && @@ -394,7 +413,7 @@ static void callback_do_join(GtkWidget *widget, } debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", - domain_or_workgroup, + new_workgroup_type, state->name_buffer_new, join_flags); if (domain_join) { @@ -422,8 +441,8 @@ static void callback_do_join(GtkWidget *widget, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "The following error occured attempting to unjoin the %s: \"%s\": %s", - domain_or_workgroup, - state->name_buffer_new, + initial_workgroup_type, + state->name_buffer_initial, err_str); g_signal_connect_swapped(dialog, "response", @@ -451,7 +470,7 @@ static void callback_do_join(GtkWidget *widget, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "The following error occured attempting to join the %s: \"%s\": %s", - domain_or_workgroup, + new_workgroup_type, state->name_buffer_new, err_str); @@ -465,7 +484,7 @@ static void callback_do_join(GtkWidget *widget, } debug("callback_do_join: Successfully joined %s\n", - domain_or_workgroup); + new_workgroup_type); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), GTK_DIALOG_DESTROY_WITH_PARENT, @@ -473,7 +492,7 @@ static void callback_do_join(GtkWidget *widget, GTK_BUTTONS_OK, "Welcome to the %s %s.", state->name_buffer_new, - domain_or_workgroup); + new_workgroup_type); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); -- cgit From 564a54aa168a0866dbd8fb3ef512b1836be11442 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 4 Jan 2008 15:08:28 +0100 Subject: Minor cosmetic cleanup for netdomjoin-gui. Guenther (This used to be commit 02e3887f3962b469c965110b6141a6655f2347af) --- .../netapi/examples/netdomjoin-gui/logo-small.png | Bin 0 -> 4485 bytes .../examples/netdomjoin-gui/netdomjoin-gui.c | 55 ++++++++++++++------- 2 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 source3/lib/netapi/examples/netdomjoin-gui/logo-small.png (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/logo-small.png b/source3/lib/netapi/examples/netdomjoin-gui/logo-small.png new file mode 100644 index 0000000000..f041198002 Binary files /dev/null and b/source3/lib/netapi/examples/netdomjoin-gui/logo-small.png differ diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 3abf6fd5dc..d12e66bb26 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -35,6 +35,7 @@ #define SAMBA_ICON_PATH "/usr/share/pixmaps/samba/samba.ico" #define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" +#define SAMBA_IMAGE_PATH_SMALL "/usr/share/pixmaps/samba/logo-small.png" #define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) #define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) @@ -224,7 +225,8 @@ static void callback_do_reboot(GtkWidget *widget, gtk_widget_destroy(dialog); #endif - gtk_label_set_text(GTK_LABEL(state->label_reboot), "Changes will take effect after you restart this computer"); + gtk_label_set_text(GTK_LABEL(state->label_reboot), + "Changes will take effect after you restart this computer"); debug("destroying do_change window\n"); gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); @@ -247,11 +249,14 @@ static void callback_do_reboot(GtkWidget *widget, SAFE_FREE(buffer); state->name_type_new = type; #endif - gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), state->name_buffer_new); - if (state->name_type_new == 3) { - gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Domain:"); + gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), + state->name_buffer_new); + if (state->name_type_new == NetSetupDomainName) { + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), + "Domain:"); } else { - gtk_label_set_text(GTK_LABEL(state->label_current_name_type), "Workgroup:"); + gtk_label_set_text(GTK_LABEL(state->label_current_name_type), + "Workgroup:"); } } } @@ -779,6 +784,8 @@ static void callback_do_change(GtkWidget *widget, debug("callback_do_change called\n"); +#if 0 + /* FIXME: add proper warnings for Samba as a DC */ if (state->server_role == 3) { GtkWidget *dialog; dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), @@ -793,13 +800,14 @@ static void callback_do_change(GtkWidget *widget, gtk_widget_show(dialog); return; } +#endif state->button_ok = gtk_button_new_from_stock(GTK_STOCK_OK); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); /* breite * höhe */ + gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); g_signal_connect(G_OBJECT(window), "delete_event", @@ -849,14 +857,17 @@ static void callback_do_change(GtkWidget *widget, char *str = NULL; entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + asprintf(&str, "%s.%s", entry_text, + state->my_dnsdomain); } else { asprintf(&str, "%s.", entry_text); } - gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); + gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), + str); free(str); gtk_misc_set_alignment(GTK_MISC(state->label_full_computer_name), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), state->label_full_computer_name, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(box1), + state->label_full_computer_name, TRUE, TRUE, 0); gtk_widget_show(state->label_full_computer_name); } @@ -891,7 +902,8 @@ static void callback_do_change(GtkWidget *widget, G_CALLBACK(callback_continue), (gpointer)state); if (state->name_type_initial == NetSetupDomainName) { - gtk_entry_set_text(GTK_ENTRY(state->entry_domain), state->name_buffer_initial); + gtk_entry_set_text(GTK_ENTRY(state->entry_domain), + state->name_buffer_initial); gtk_widget_set_sensitive(state->entry_workgroup, FALSE); gtk_widget_set_sensitive(state->entry_domain, TRUE); } @@ -912,7 +924,8 @@ static void callback_do_change(GtkWidget *widget, G_CALLBACK(callback_do_join_workgroup), (gpointer)state); { - gtk_entry_set_max_length(GTK_ENTRY(state->entry_workgroup), MAX_NETBIOS_NAME_LEN); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_workgroup), + MAX_NETBIOS_NAME_LEN); g_signal_connect(G_OBJECT(state->entry_workgroup), "changed", G_CALLBACK(callback_enter_workgroup_and_unlock), (gpointer)state); @@ -921,7 +934,8 @@ static void callback_do_change(GtkWidget *widget, (gpointer)state); if (state->name_type_initial == NetSetupWorkgroupName) { - gtk_entry_set_text(GTK_ENTRY(state->entry_workgroup), state->name_buffer_initial); + gtk_entry_set_text(GTK_ENTRY(state->entry_workgroup), + state->name_buffer_initial); gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); } @@ -998,21 +1012,25 @@ static int draw_main_window(struct join_state *state) icon = gdk_pixbuf_new_from_file(SAMBA_ICON_PATH, &error); if (icon == NULL) { - g_print("failed to load logo from %s : %s\n", + g_print("failed to load icon from %s : %s\n", SAMBA_ICON_PATH, error->message); } #if 1 - image = gtk_image_new_from_file(SAMBA_IMAGE_PATH); + image = gtk_image_new_from_file(SAMBA_IMAGE_PATH_SMALL); #else image = gtk_image_new_from_file("/usr/share/pixmaps/redhat-system_settings.png"); #endif + if (image == NULL) { + g_print("failed to load logo from %s : %s\n", + SAMBA_IMAGE_PATH_SMALL, error->message); + } window = gtk_window_new(GTK_WINDOW_TOPLEVEL); state->window_main = window; gtk_window_set_title(GTK_WINDOW(window), "Samba - Join Domain dialogue"); - gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); /* breite * höhe */ + gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); @@ -1034,14 +1052,15 @@ static int draw_main_window(struct join_state *state) { /* gtk_box_pack_start(GTK_BOX(main_vbox), image, TRUE, TRUE, 10); */ - gtk_misc_set_alignment(GTK_MISC(image), 0, 0); +/* gtk_misc_set_alignment(GTK_MISC(image), 0, 0); */ + gtk_widget_set_size_request(GTK_WIDGET(image), 150, 40); gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 10); gtk_widget_show(image); /* Label */ label = gtk_label_new("Samba uses the following information to identify your computer on the network."); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_widget_set_size_request(GTK_WIDGET(label), 500, 40); +/* gtk_misc_set_alignment(GTK_MISC(label), 0, 0); */ + gtk_widget_set_size_request(GTK_WIDGET(label), 400, 40); gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); gtk_widget_show(label); -- cgit From e6c3ac59c5adb433d6269cae7141e575da7fdc8d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 7 Jan 2008 12:19:56 +0100 Subject: Failure while unjoining a domain is non-critical. Just continue joining to the workgroup in that case. Guenther (This used to be commit bf9ce2a928e3136d3bfe368f75d5b99273c5b04f) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index d12e66bb26..1e1681ba37 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -449,14 +449,8 @@ static void callback_do_join(GtkWidget *widget, initial_workgroup_type, state->name_buffer_initial, err_str); - - g_signal_connect_swapped(dialog, "response", - G_CALLBACK(gtk_widget_destroy), - dialog); - - gtk_widget_show(dialog); - - return; + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); } } -- cgit From 67f2afe3c4cfd46aa20b7a7c568ac6b5ab16acb8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Jan 2008 11:55:45 +0100 Subject: Correctly free buffers in netdomjoin-gui. Guenther (This used to be commit 04d78d4d9a8cffe44c927036038aef1d6d6b44b2) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 1e1681ba37..4a3588e9ab 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -249,6 +249,8 @@ static void callback_do_reboot(GtkWidget *widget, SAFE_FREE(buffer); state->name_type_new = type; #endif + NetApiBufferFree((void *)buffer); + gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), state->name_buffer_new); if (state->name_type_new == NetSetupDomainName) { @@ -1292,8 +1294,12 @@ static int initialize_join_state(struct join_state *state, if (status) { return status; } - state->name_buffer_initial = (char *)buffer; + state->name_buffer_initial = strdup(buffer); + if (!state->name_buffer_initial) { + return -1; + } state->name_type_initial = type; + NetApiBufferFree((void *)buffer); } { @@ -1311,6 +1317,7 @@ static int initialize_join_state(struct join_state *state, if (!state->comment) { return -1; } + NetApiBufferFree(buffer); } #if 0 { -- cgit From efcf285e27e3f52cd6188f678d52977584c78972 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 11 Jan 2008 15:28:24 +0100 Subject: Fix libnetapi error string callers. Guenther (This used to be commit 1ad7a0a361edfa5ac738f011db1d6a9db256ac2c) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 4a3588e9ab..9dc2a18138 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -147,13 +147,13 @@ static void callback_apply_description_change(GtkWidget *widget, status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); if (status) { debug("NetServerSetInfo failed with: %s\n", - libnetapi_errstr(state->ctx, status)); + libnetapi_errstr(status)); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Failed to change computer description: %s.", - libnetapi_errstr(state->ctx, status)); + libnetapi_errstr(status)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -439,7 +439,7 @@ static void callback_do_join(GtkWidget *widget, state->password, unjoin_flags); if (status != 0) { - err_str = libnetapi_errstr(state->ctx, status); + err_str = libnetapi_errstr(status); g_print("callback_do_join: failed to unjoin (%s)\n", err_str); @@ -463,7 +463,7 @@ static void callback_do_join(GtkWidget *widget, state->password, join_flags); if (status != 0) { - err_str = libnetapi_errstr(state->ctx, status); + err_str = libnetapi_errstr(status); g_print("callback_do_join: failed to join (%s)\n", err_str); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), -- cgit From bb97b272a975e4af7738c58e7af4b8e3047d4b77 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jan 2008 02:30:09 +0100 Subject: Fix local hostname detection in netdomjoin-gui. Guenther (This used to be commit 30458116b389889cad845eb96b54c3edc833e722) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 37 ++++++++++++++++------ 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') 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 #include #include +#include #include #include @@ -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); } { -- cgit From cfb7e254662dd957da7e193010f87544b96c2f17 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jan 2008 02:30:53 +0100 Subject: Add some more debugging into netdomjoin-gui. Guenther (This used to be commit d4c5b323229c6f43c824e3559084c98e370730a5) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 6e958b4c73..73b14d4d87 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -440,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); @@ -464,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), @@ -1308,9 +1308,12 @@ static int initialize_join_state(struct join_state *state, 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; @@ -1324,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; } -- cgit From 65b0235ee394f90e7a4938cfa5bc5d2d951e9d82 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 5 Mar 2008 15:21:43 +0100 Subject: Give a better error message why NetServerSetInfo() may fail in the gui. Guenther (This used to be commit 1bbbebb7767b8a25532e8be3dbd274c211e34bbd) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 73b14d4d87..a3719c7442 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -154,7 +154,7 @@ static void callback_apply_description_change(GtkWidget *widget, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Failed to change computer description: %s.", - libnetapi_errstr(status)); + libnetapi_get_error_string(state->ctx, status)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); -- cgit From 68bfa9682b0b9bf859e382d90688e48a8d6b8479 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 2 Apr 2008 11:18:10 +0200 Subject: Some fixes for netdomjoin-gui and support for browsing/joining OUs. Guenther (This used to be commit 4714bae0dbbb2ad010c2929f83de6bca84cfac46) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 547 +++++++++++++++------ 1 file changed, 390 insertions(+), 157 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index a3719c7442..a4daf4fea7 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -63,14 +63,17 @@ typedef struct join_state { GtkWidget *entry_account; GtkWidget *entry_password; GtkWidget *entry_domain; + GtkWidget *entry_ou_list; GtkWidget *entry_workgroup; GtkWidget *button_ok; GtkWidget *button_apply; GtkWidget *button_ok_creds; + GtkWidget *button_get_ous; GtkWidget *label_reboot; GtkWidget *label_current_name_buffer; GtkWidget *label_current_name_type; GtkWidget *label_full_computer_name; + GtkWidget *label_winbind; uint16_t name_type_initial; uint16_t name_type_new; char *name_buffer_initial; @@ -111,10 +114,40 @@ static gboolean callback_delete_event(GtkWidget *widget, static void callback_do_close(GtkWidget *widget, gpointer data) { - debug("Closing now...\n"); + debug("callback_do_close called\n"); + gtk_widget_destroy(data); } +static void callback_do_freeauth(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + debug("callback_do_freeauth called\n"); + + SAFE_FREE(state->account); + SAFE_FREE(state->password); + + if (state->window_creds_prompt) { + gtk_widget_destroy(state->window_creds_prompt); + } +} + +static void callback_do_freeauth_and_close(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + debug("callback_do_freeauth_and_close called\n"); + + SAFE_FREE(state->account); + SAFE_FREE(state->password); + + gtk_widget_destroy(state->window_creds_prompt); + gtk_widget_destroy(state->window_do_change); +} + static void free_join_state(struct join_state *s) { SAFE_FREE(s->name_buffer_initial); @@ -155,6 +188,8 @@ static void callback_apply_description_change(GtkWidget *widget, GTK_BUTTONS_OK, "Failed to change computer description: %s.", libnetapi_get_error_string(state->ctx, status)); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -183,6 +218,7 @@ static void callback_do_exit(GtkWidget *widget, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "You must restart your computer before the new settings will take effect."); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); result = gtk_dialog_run(GTK_DIALOG(dialog)); switch (result) { case GTK_RESPONSE_YES: @@ -214,6 +250,7 @@ static void callback_do_reboot(GtkWidget *widget, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "You must restart this computer for the changes to take effect."); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); #if 0 g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), @@ -269,10 +306,14 @@ static void callback_return_username(GtkWidget *widget, { const gchar *entry_text; struct join_state *state = (struct join_state *)data; + debug("callback_return_username called\n"); if (!widget) { return; } entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + if (!entry_text) { + return; + } debug("callback_return_username: %s\n", entry_text); SAFE_FREE(state->account); state->account = strdup(entry_text); @@ -287,7 +328,10 @@ static void callback_return_username_and_enter(GtkWidget *widget, return; } entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); - debug("callback_return_username: %s\n", entry_text); + if (!entry_text) { + return; + } + debug("callback_return_username_and_enter: %s\n", entry_text); SAFE_FREE(state->account); state->account = strdup(entry_text); g_signal_emit_by_name(state->button_ok_creds, "clicked"); @@ -298,10 +342,14 @@ static void callback_return_password(GtkWidget *widget, { const gchar *entry_text; struct join_state *state = (struct join_state *)data; + debug("callback_return_password called\n"); if (!widget) { return; } entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + if (!entry_text) { + return; + } #ifdef DEBUG_PASSWORD debug("callback_return_password: %s\n", entry_text); #else @@ -320,16 +368,59 @@ static void callback_return_password_and_enter(GtkWidget *widget, return; } entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); + if (!entry_text) { + return; + } #ifdef DEBUG_PASSWORD - debug("callback_return_password: %s\n", entry_text); + debug("callback_return_password_and_enter: %s\n", entry_text); #else - debug("callback_return_password: (not printed)\n"); + debug("callback_return_password_and_enter: (not printed)\n"); #endif SAFE_FREE(state->password); state->password = strdup(entry_text); g_signal_emit_by_name(state->button_ok_creds, "clicked"); } +static void callback_do_storeauth(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + debug("callback_do_storeauth called\n"); + + SAFE_FREE(state->account); + SAFE_FREE(state->password); + + callback_return_username(state->entry_account, state); + callback_return_password(state->entry_password, state); + + gtk_widget_destroy(state->window_creds_prompt); +} + +static void callback_continue(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok)); + g_signal_emit_by_name(state->button_ok, "clicked"); +} + +static void callback_do_storeauth_and_continue(GtkWidget *widget, + gpointer data) +{ + callback_do_storeauth(widget, data); + callback_continue(NULL, data); +} + +static void callback_do_storeauth_and_scan(GtkWidget *widget, + gpointer data) +{ + struct join_state *state = (struct join_state *)data; + callback_do_storeauth(widget, data); + g_signal_emit_by_name(state->button_get_ous, "clicked"); +} + static void callback_do_hostname_change(GtkWidget *widget, gpointer data) { @@ -355,12 +446,112 @@ static void callback_do_hostname_change(GtkWidget *widget, GTK_BUTTONS_CLOSE, str); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); gtk_widget_show(dialog); } +static void callback_creds_prompt(GtkWidget *widget, + gpointer data, + const char *label_string, + gpointer cont_fn) +{ + GtkWidget *window; + GtkWidget *box1; + GtkWidget *bbox; + GtkWidget *button; + GtkWidget *label; + + struct join_state *state = (struct join_state *)data; + + debug("callback_creds_prompt\n"); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_modal(GTK_WINDOW(window), TRUE); + + gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); + gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); + gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + + g_signal_connect(G_OBJECT(window), "delete_event", + G_CALLBACK(callback_do_close), window); + + state->window_creds_prompt = window; + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + box1 = gtk_vbox_new(FALSE, 0); + + gtk_container_add(GTK_CONTAINER(window), box1); + + label = gtk_label_new(label_string); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + + gtk_widget_show(label); + + /* USER NAME */ + label = gtk_label_new("User name:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_account = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_account), MAX_CRED_LEN); + g_signal_connect(G_OBJECT(state->entry_account), "activate", + G_CALLBACK(callback_return_username_and_enter), + (gpointer)state); + gtk_editable_select_region(GTK_EDITABLE(state->entry_account), + 0, GTK_ENTRY(state->entry_account)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_account, TRUE, TRUE, 0); + gtk_widget_show(state->entry_account); + + /* PASSWORD */ + label = gtk_label_new("Password:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + state->entry_password = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(state->entry_password), MAX_CRED_LEN); + gtk_entry_set_visibility(GTK_ENTRY(state->entry_password), FALSE); + g_signal_connect(G_OBJECT(state->entry_password), "activate", + G_CALLBACK(callback_return_password_and_enter), + (gpointer)state); + gtk_editable_set_editable(GTK_EDITABLE(state->entry_password), TRUE); + gtk_editable_select_region(GTK_EDITABLE(state->entry_password), + 0, GTK_ENTRY(state->entry_password)->text_length); + gtk_box_pack_start(GTK_BOX(box1), state->entry_password, TRUE, TRUE, 0); + gtk_widget_show(state->entry_password); + + /* BUTTONS */ + bbox = gtk_hbutton_box_new(); + gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); + gtk_container_add(GTK_CONTAINER(box1), bbox); + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(bbox), 10); + + state->button_ok_creds = gtk_button_new_from_stock(GTK_STOCK_OK); + gtk_widget_grab_focus(GTK_WIDGET(state->button_ok_creds)); + gtk_container_add(GTK_CONTAINER(bbox), state->button_ok_creds); + g_signal_connect(G_OBJECT(state->button_ok_creds), "clicked", + G_CALLBACK(cont_fn), + (gpointer)state); + gtk_widget_show(state->button_ok_creds); + + button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_container_add(GTK_CONTAINER(bbox), button); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(callback_do_freeauth), + (gpointer)state); + gtk_widget_show_all(window); +} + static void callback_do_join(GtkWidget *widget, gpointer data) { @@ -372,16 +563,17 @@ static void callback_do_join(GtkWidget *widget, uint32_t unjoin_flags = 0; gboolean domain_join = FALSE; gboolean try_unjoin = FALSE; + gboolean join_creds_required = TRUE; + gboolean unjoin_creds_required = TRUE; const char *new_workgroup_type = NULL; const char *initial_workgroup_type = NULL; + const char *account_ou = NULL; struct join_state *state = (struct join_state *)data; - callback_return_username(state->entry_account, state); - callback_return_password(state->entry_password, state); - - if (state->window_creds_prompt) { - gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + if (state->hostname_changed) { + callback_do_hostname_change(NULL, state); + return; } switch (state->name_type_initial) { @@ -406,8 +598,20 @@ static void callback_do_join(GtkWidget *widget, break; } + account_ou = gtk_combo_box_get_active_text(GTK_COMBO_BOX(state->entry_ou_list)); + if (account_ou && strlen(account_ou) == 0) { + account_ou = NULL; + } + + if ((state->name_type_initial != NetSetupDomainName) && + (state->name_type_new != NetSetupDomainName)) { + join_creds_required = FALSE; + unjoin_creds_required = FALSE; + } + if (state->name_type_new == NetSetupDomainName) { domain_join = TRUE; + join_creds_required = TRUE; join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ @@ -416,30 +620,36 @@ static void callback_do_join(GtkWidget *widget, if ((state->name_type_initial == NetSetupDomainName) && (state->name_type_new == NetSetupWorkgroupName)) { try_unjoin = TRUE; + unjoin_creds_required = TRUE; + join_creds_required = FALSE; unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; } - debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", - new_workgroup_type, - state->name_buffer_new, - join_flags); - if (domain_join) { - debug("as %s ", state->account); -#ifdef DEBUG_PASSWORD - debug("with %s ", state->password); -#endif - } - debug("\n"); if (try_unjoin) { debug("callback_do_join: Unjoining\n"); + if (unjoin_creds_required) { + if (!state->account || !state->password) { + debug("callback_do_join: no creds yet\n"); + callback_creds_prompt(NULL, state, + "Enter the name and password of an account with permission to leave the domain.", + callback_do_storeauth_and_continue); + } + + if (!state->account || !state->password) { + debug("callback_do_join: still no creds???\n"); + return; + } + } + status = NetUnjoinDomain(NULL, state->account, state->password, unjoin_flags); if (status != 0) { + callback_do_freeauth(NULL, state); err_str = libnetapi_get_error_string(state->ctx, status); g_print("callback_do_join: failed to unjoin (%s)\n", err_str); @@ -452,18 +662,47 @@ static void callback_do_join(GtkWidget *widget, initial_workgroup_type, state->name_buffer_initial, err_str); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } } + + if (join_creds_required) { + if (!state->account || !state->password) { + debug("callback_do_join: no creds yet\n"); + callback_creds_prompt(NULL, state, + "Enter the name and password of an account with permission to leave the domain.", + callback_do_storeauth_and_continue); + } + + if (!state->account || !state->password) { + debug("callback_do_join: still no creds???\n"); + return; + } + } + + debug("callback_do_join: Joining a %s named %s using join_flags 0x%08x ", + new_workgroup_type, + state->name_buffer_new, + join_flags); + if (domain_join) { + debug("as %s ", state->account); +#ifdef DEBUG_PASSWORD + debug("with %s ", state->password); +#endif + } + debug("\n"); + status = NetJoinDomain(NULL, state->name_buffer_new, - NULL, + account_ou, state->account, state->password, join_flags); if (status != 0) { + callback_do_freeauth(NULL, state); err_str = libnetapi_get_error_string(state->ctx, status); g_print("callback_do_join: failed to join (%s)\n", err_str); @@ -476,6 +715,7 @@ static void callback_do_join(GtkWidget *widget, state->name_buffer_new, err_str); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -488,6 +728,7 @@ static void callback_do_join(GtkWidget *widget, debug("callback_do_join: Successfully joined %s\n", new_workgroup_type); + callback_do_freeauth(NULL, state); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, @@ -496,123 +737,13 @@ static void callback_do_join(GtkWidget *widget, state->name_buffer_new, new_workgroup_type); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); callback_do_reboot(NULL, state->window_parent, state); } -static void callback_creds_prompt(GtkWidget *widget, - gpointer data) -{ - GtkWidget *window; - GtkWidget *box1; - GtkWidget *bbox; - GtkWidget *button; - GtkWidget *label; - - struct join_state *state = (struct join_state *)data; - - debug("callback_creds_prompt:\n"); - - state->window_parent = state->window_do_change; - - if (state->hostname_changed) { - return callback_do_hostname_change(NULL, state); - } - - if ((state->name_type_initial != NetSetupDomainName) && - (state->name_type_new != NetSetupDomainName)) { - return callback_do_join(NULL, state); - } - - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); - gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); - gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); -/* gtk_window_set_icon_name(GTK_WIDGET(window), GTK_STOCK_DIALOG_AUTHENTICATION); */ - state->window_creds_prompt = window; - - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close), window); - - gtk_container_set_border_width(GTK_CONTAINER(window), 10); - - box1 = gtk_vbox_new(FALSE, 0); - - gtk_container_add(GTK_CONTAINER(window), box1); - - if ((state->name_type_initial == NetSetupDomainName) && - (state->name_type_new == NetSetupWorkgroupName)) { - label = gtk_label_new("Enter the name and password of an account with permission to leave the domain.\n"); - } else { - label = gtk_label_new("Enter the name and password of an account with permission to join the domain.\n"); - } - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); - - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - - gtk_widget_show(label); - - /* USER NAME */ - label = gtk_label_new("User name:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - gtk_widget_show(label); - - state->entry_account = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(state->entry_account), MAX_CRED_LEN); - g_signal_connect(G_OBJECT(state->entry_account), "activate", - G_CALLBACK(callback_return_username_and_enter), - (gpointer)state); - gtk_editable_select_region(GTK_EDITABLE(state->entry_account), - 0, GTK_ENTRY(state->entry_account)->text_length); - gtk_box_pack_start(GTK_BOX(box1), state->entry_account, TRUE, TRUE, 0); - gtk_widget_show(state->entry_account); - - /* PASSWORD */ - label = gtk_label_new("Password:"); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_box_pack_start(GTK_BOX(box1), label, FALSE, FALSE, 0); - gtk_widget_show(label); - - state->entry_password = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY(state->entry_password), MAX_CRED_LEN); - gtk_entry_set_visibility(GTK_ENTRY(state->entry_password), FALSE); - g_signal_connect(G_OBJECT(state->entry_password), "activate", - G_CALLBACK(callback_return_password_and_enter), - (gpointer)state); - gtk_editable_set_editable(GTK_EDITABLE(state->entry_password), TRUE); - gtk_editable_select_region(GTK_EDITABLE(state->entry_password), - 0, GTK_ENTRY(state->entry_password)->text_length); - gtk_box_pack_start(GTK_BOX(box1), state->entry_password, TRUE, TRUE, 0); - gtk_widget_show(state->entry_password); - - bbox = gtk_hbutton_box_new(); - gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); - gtk_container_add(GTK_CONTAINER(box1), bbox); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing(GTK_BOX(bbox), 10); - - state->button_ok_creds = gtk_button_new_from_stock(GTK_STOCK_OK); - gtk_widget_grab_focus(GTK_WIDGET(state->button_ok_creds)); - gtk_container_add(GTK_CONTAINER(bbox), state->button_ok_creds); - g_signal_connect(G_OBJECT(state->button_ok_creds), "clicked", - G_CALLBACK(callback_do_join), - (gpointer)state); - gtk_widget_show(state->button_ok_creds); - - button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_container_add(GTK_CONTAINER(bbox), button); - g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(callback_do_close), (gpointer) window); - gtk_widget_show_all(window); -} - static void callback_enter_hostname_and_unlock(GtkWidget *widget, gpointer data) { @@ -717,20 +848,13 @@ static void callback_enter_domain_and_unlock(GtkWidget *widget, return; } gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_ou_list), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(state->button_get_ous), TRUE); SAFE_FREE(state->name_buffer_new); state->name_buffer_new = strdup(entry_text); state->name_type_new = NetSetupDomainName; } -static void callback_continue(GtkWidget *widget, - gpointer data) -{ - struct join_state *state = (struct join_state *)data; - - gtk_widget_grab_focus(GTK_WIDGET(state->button_ok)); - g_signal_emit_by_name(state->button_ok, "clicked"); -} - static void callback_apply_continue(GtkWidget *widget, gpointer data) { @@ -748,6 +872,8 @@ static void callback_do_join_workgroup(GtkWidget *widget, gtk_widget_set_sensitive(GTK_WIDGET(state->entry_workgroup), TRUE); gtk_widget_grab_focus(GTK_WIDGET(state->entry_workgroup)); gtk_widget_set_sensitive(GTK_WIDGET(state->entry_domain), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(state->entry_ou_list), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(state->button_get_ous), FALSE); callback_enter_workgroup_and_unlock(state->entry_workgroup, state); /* TEST */ } @@ -762,6 +888,62 @@ static void callback_do_join_domain(GtkWidget *widget, callback_enter_domain_and_unlock(state->entry_domain, state); /* TEST */ } +static void callback_do_getous(GtkWidget *widget, + gpointer data) +{ + NET_API_STATUS status; + uint32_t num_ous = 0; + const char **ous = NULL; + int i; + const char *domain = NULL; + + struct join_state *state = (struct join_state *)data; + + debug("callback_do_getous called\n"); + + domain = state->name_buffer_new ? state->name_buffer_new : state->name_buffer_initial; + + if (!state->account || !state->password) { + debug("callback_do_getous: no creds yet\n"); + callback_creds_prompt(NULL, state, + "Enter the name and password of an account with permission to join the domain.", + callback_do_storeauth_and_scan); + } + + if (!state->account || !state->password) { + debug("callback_do_getous: still no creds ???\n"); + return; + } + + status = NetGetJoinableOUs(NULL, domain, + state->account, + state->password, + &num_ous, &ous); + if (status != NET_API_STATUS_SUCCESS) { + GtkWidget *dialog; + callback_do_freeauth(NULL, state); + debug("failed to call NetGetJoinableOUs: %s\n", + libnetapi_get_error_string(state->ctx, status)); + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "Failed to query joinable OUs: %s", + libnetapi_get_error_string(state->ctx, status)); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + return; + } + + for (i=0; ientry_ou_list), + ous[i]); + } + NetApiBufferFree(ous); + gtk_combo_box_set_active(GTK_COMBO_BOX(state->entry_ou_list), num_ous-1); +} + static void callback_do_change(GtkWidget *widget, gpointer data) { @@ -785,11 +967,13 @@ static void callback_do_change(GtkWidget *widget, /* FIXME: add proper warnings for Samba as a DC */ if (state->server_role == 3) { GtkWidget *dialog; + callback_do_freeauth(NULL, state); dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Domain controller cannot be moved from one domain to another, they must first be demoted. Renaming this domain controller may cause it to become temporarily unavailable to users and computers. For information on renaming domain controllers, including alternate renaming methods, see Help and Support. To continue renaming this domain controller, click OK."); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -800,11 +984,13 @@ static void callback_do_change(GtkWidget *widget, #endif state->button_ok = gtk_button_new_from_stock(GTK_STOCK_OK); + state->button_get_ous = gtk_button_new_with_label("Scan for joinable OUs"); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_modal(GTK_WINDOW(window), TRUE); gtk_window_set_title(GTK_WINDOW(window), "Computer Name Changes"); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_widget_set_size_request(GTK_WIDGET(window), 480, 500); + gtk_widget_set_size_request(GTK_WIDGET(window), 480, 650); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); g_signal_connect(G_OBJECT(window), "delete_event", @@ -941,6 +1127,37 @@ static void callback_do_change(GtkWidget *widget, } gtk_widget_show(button_workgroup); + /* Advanced Options */ + frame_horz = gtk_frame_new("Advanced Options"); + gtk_box_pack_start(GTK_BOX(box1), frame_horz, TRUE, TRUE, 10); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + gtk_container_add(GTK_CONTAINER(frame_horz), vbox); + + /* OUs */ + gtk_container_add(GTK_CONTAINER(vbox), state->button_get_ous); + gtk_widget_set_sensitive(GTK_WIDGET(state->button_get_ous), FALSE); + g_signal_connect(G_OBJECT(state->button_get_ous), "clicked", + G_CALLBACK(callback_do_getous), + (gpointer)state); + + state->entry_ou_list = gtk_combo_box_entry_new_text(); + gtk_widget_set_sensitive(state->entry_ou_list, FALSE); + if (state->name_type_initial == NetSetupWorkgroupName) { + gtk_widget_set_sensitive(state->entry_ou_list, FALSE); + gtk_widget_set_sensitive(state->button_get_ous, FALSE); + } + gtk_box_pack_start(GTK_BOX(vbox), state->entry_ou_list, TRUE, TRUE, 0); + gtk_widget_show(state->entry_ou_list); + + { + state->label_winbind = gtk_check_button_new_with_label("Modify winbind configuration"); + gtk_box_pack_start(GTK_BOX(vbox), state->label_winbind, TRUE, TRUE, 0); + gtk_widget_set_sensitive(state->label_winbind, FALSE); + } + + /* BUTTONS */ bbox = gtk_hbutton_box_new(); gtk_container_set_border_width(GTK_CONTAINER(bbox), 5); @@ -949,20 +1166,19 @@ static void callback_do_change(GtkWidget *widget, gtk_box_set_spacing(GTK_BOX(bbox), 10); state->window_do_change = window; - gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); /* !!! */ + gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); gtk_container_add(GTK_CONTAINER(bbox), state->button_ok); g_signal_connect(G_OBJECT(state->button_ok), "clicked", - G_CALLBACK(callback_creds_prompt), + G_CALLBACK(callback_do_join), (gpointer)state); button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); gtk_container_add(GTK_CONTAINER(bbox), button); g_signal_connect(G_OBJECT(button), "clicked", - G_CALLBACK(callback_do_close), - (gpointer)window); + G_CALLBACK(callback_do_freeauth_and_close), + (gpointer)state); gtk_widget_show_all(window); - } static void callback_do_about(GtkWidget *widget, @@ -970,6 +1186,7 @@ static void callback_do_about(GtkWidget *widget, { GdkPixbuf *logo; GError *error = NULL; + GtkWidget *about; debug("callback_do_about called\n"); @@ -980,15 +1197,25 @@ static void callback_do_about(GtkWidget *widget, SAMBA_IMAGE_PATH, error->message); } - gtk_show_about_dialog(data, - "name", "Samba", - "version", "3.2.0pre2-GIT-904a90-test", - "copyright", "Copyright Andrew Tridgell and the Samba Team 1992-2007", - "website", "http://www.samba.org", - "license", "GPLv3", - "logo", logo, - "comments", "Samba gtk domain join utility", - NULL); + about = gtk_about_dialog_new(); + gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), "Samba"); + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), "3.2.0pre3"); + gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), + "Copyright Andrew Tridgell and the Samba Team 1992-2008\n" + "Copyright Günther Deschner 2007-2008"); + gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(about), "GPLv3"); + gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about), "http://www.samba.org"); + gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(about), "http://www.samba.org"); + if (logo) { + gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(about), logo); + } + gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about), "Samba gtk domain join utility"); + gtk_window_set_modal(GTK_WINDOW(about), TRUE); + g_signal_connect_swapped(about, "response", + G_CALLBACK(gtk_widget_destroy), + about); + + gtk_widget_show(about); } static int draw_main_window(struct join_state *state) @@ -1221,7 +1448,13 @@ static int draw_main_window(struct join_state *state) g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_about), window); - +#if 0 + button2 = gtk_button_new_from_stock(GTK_STOCK_HELP); + gtk_container_add(GTK_CONTAINER(bbox2), button2); + g_signal_connect(G_OBJECT(button2), "clicked", + G_CALLBACK(callback_do_about), + window); +#endif gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 5); } -- cgit From 1a8a8b776961c9220fa686cb60b7ab82a7c76a3d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 10 Apr 2008 21:31:12 +0200 Subject: Use SERVER_INFO_1005 in libnetapi. Guenther (This used to be commit 5f8793dd1d8a3694afb7f2d882cfb9990eb40b75) --- .../lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index a4daf4fea7..fa1bafd5ae 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -48,10 +48,6 @@ #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) -struct srvsvc_NetSrvInfo1005 { - const char *comment;/* [unique,charset(UTF16)] */ -}; - static gboolean verbose = FALSE; typedef struct join_state { @@ -173,10 +169,10 @@ static void callback_apply_description_change(GtkWidget *widget, struct join_state *state = (struct join_state *)data; NET_API_STATUS status = 0; uint32_t parm_err = 0; - struct srvsvc_NetSrvInfo1005 info1005; + struct SERVER_INFO_1005 info1005; GtkWidget *dialog; - info1005.comment = state->comment_new; + info1005.sv1005_comment = state->comment_new; status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); if (status) { @@ -1556,7 +1552,7 @@ static int initialize_join_state(struct join_state *state, } { - struct srvsvc_NetSrvInfo1005 *info1005 = NULL; + struct SERVER_INFO_1005 *info1005 = NULL; uint8_t *buffer = NULL; status = NetServerGetInfo(NULL, 1005, &buffer); @@ -1566,9 +1562,9 @@ static int initialize_join_state(struct join_state *state, return status; } - info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer; + info1005 = (struct SERVER_INFO_1005 *)buffer; - state->comment = strdup(info1005->comment); + state->comment = strdup(info1005->sv1005_comment); if (!state->comment) { return -1; } -- cgit From a75421b0190763e5e482db215d8b1e6052bdcc19 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sat, 12 Apr 2008 23:12:53 +0200 Subject: Fix ou handling in netdomjoin-gui. The ou list was concatenated again and again... Guenther (This used to be commit 84608e165e24c68c12d40086f81684ef37f69159) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index fa1bafd5ae..a7b2079f95 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -84,6 +84,7 @@ typedef struct join_state { uint16_t server_role; gboolean settings_changed; gboolean hostname_changed; + uint32_t stored_num_ous; } join_state; static void debug(const char *format, ...) @@ -932,11 +933,15 @@ static void callback_do_getous(GtkWidget *widget, return; } + for (i=0; istored_num_ous; i++) { + gtk_combo_box_remove_text(GTK_COMBO_BOX(state->entry_ou_list), 0); + } for (i=0; ientry_ou_list), ous[i]); } NetApiBufferFree(ous); + state->stored_num_ous = num_ous; gtk_combo_box_set_active(GTK_COMBO_BOX(state->entry_ou_list), num_ous-1); } -- cgit From 73754b98f4b58bd20eac5ffe8ed891313a8644b1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 17 Apr 2008 14:07:53 +0200 Subject: netdomjoin-gui: Fix label alignment showing up with lower screen-resolution. Guenther (This used to be commit e06a54aa7da857e006649469e7eb8d76711221c1) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index a7b2079f95..7c84d4d8c6 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -1306,7 +1306,7 @@ static int draw_main_window(struct join_state *state) { /* Label */ label = gtk_label_new("Computer description:"); -/* gtk_misc_set_alignment(GTK_MISC(label), 0, 0); */ + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); gtk_widget_show(label); -- cgit From 25c454cbba83b34b53752c11dcc80ae1a3d2e4ed Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 20 Apr 2008 22:58:52 +0200 Subject: netdomjoin-gui: Omit warning when unjoining a domain fails. Guenther (This used to be commit ba1d2e87614a98b4f811c75a0d9cfa8491f5cb4d) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 7c84d4d8c6..5ce4ca2c87 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -650,6 +650,9 @@ static void callback_do_join(GtkWidget *widget, err_str = libnetapi_get_error_string(state->ctx, status); g_print("callback_do_join: failed to unjoin (%s)\n", err_str); +#if 0 + + /* in fact we shouldn't annoy the user with an error message here */ dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), GTK_DIALOG_DESTROY_WITH_PARENT, @@ -662,6 +665,7 @@ static void callback_do_join(GtkWidget *widget, gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); +#endif } } -- cgit From d3dfdc2f598fae92f1d3d1e95754917ff5869fa7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 8 May 2008 01:07:10 +0200 Subject: netdomjoin-gui: before prompting for creds, ask dsgetdcname for a dc. Guenther (This used to be commit 47146effc1c2bca516d4fbccf221b5b0e02737bf) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 5ce4ca2c87..a11b0eb0a4 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -670,6 +670,41 @@ static void callback_do_join(GtkWidget *widget, } + /* before prompting for creds, make sure we can find a dc */ + + if (domain_join) { + + struct DOMAIN_CONTROLLER_INFO *dc_info = NULL; + + status = DsGetDcName(NULL, + state->name_buffer_new, + NULL, + NULL, + 0, + &dc_info); + if (status != 0) { + err_str = libnetapi_get_error_string(state->ctx, status); + g_print("callback_do_join: failed find dc (%s)\n", err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "Failed to find a domain controller for domain: \"%s\": %s", + state->name_buffer_new, + err_str); + + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + } + if (join_creds_required) { if (!state->account || !state->password) { debug("callback_do_join: no creds yet\n"); -- cgit From 0b25870b547efdd954ac343c1a753d853a75ba67 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 16 May 2008 12:11:43 +0200 Subject: netdomjoin-gui: before prompting for creds (for receiving joinable ous), find a dc. Guenther (This used to be commit ae60695a349bccd1128e6c439664b0607627ef23) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index a11b0eb0a4..df8193707c 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -932,6 +932,9 @@ static void callback_do_getous(GtkWidget *widget, const char **ous = NULL; int i; const char *domain = NULL; + struct DOMAIN_CONTROLLER_INFO *dc_info = NULL; + const char *err_str = NULL; + GtkWidget *dialog; struct join_state *state = (struct join_state *)data; @@ -939,6 +942,34 @@ static void callback_do_getous(GtkWidget *widget, domain = state->name_buffer_new ? state->name_buffer_new : state->name_buffer_initial; + status = DsGetDcName(NULL, + domain, + NULL, + NULL, + 0, + &dc_info); + if (status != 0) { + err_str = libnetapi_get_error_string(state->ctx, status); + g_print("callback_do_getous: failed find dc (%s)\n", err_str); + + dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "Failed to find a domain controller for domain: \"%s\": %s", + domain, + err_str); + + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), + dialog); + + gtk_widget_show(dialog); + + return; + } + if (!state->account || !state->password) { debug("callback_do_getous: no creds yet\n"); callback_creds_prompt(NULL, state, @@ -956,7 +987,6 @@ static void callback_do_getous(GtkWidget *widget, state->password, &num_ous, &ous); if (status != NET_API_STATUS_SUCCESS) { - GtkWidget *dialog; callback_do_freeauth(NULL, state); debug("failed to call NetGetJoinableOUs: %s\n", libnetapi_get_error_string(state->ctx, status)); -- cgit From 7d35e4e294a00288ba83d3f9c4f1ce9a23260311 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 3 Jun 2008 15:19:46 +0200 Subject: netdomjoin-gui: some minor fixes + hunting down typecast bugs. Guenther (This used to be commit 0fa6c8c6a3efd026154e8af54ba73b3d3de1affa) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 36 +++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index df8193707c..dd4e4ad394 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -113,7 +113,9 @@ static void callback_do_close(GtkWidget *widget, { debug("callback_do_close called\n"); - gtk_widget_destroy(data); + if (data) { + gtk_widget_destroy(GTK_WIDGET(data)); + } } static void callback_do_freeauth(GtkWidget *widget, @@ -127,7 +129,8 @@ static void callback_do_freeauth(GtkWidget *widget, SAFE_FREE(state->password); if (state->window_creds_prompt) { - gtk_widget_destroy(state->window_creds_prompt); + gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + state->window_creds_prompt = NULL; } } @@ -141,8 +144,13 @@ static void callback_do_freeauth_and_close(GtkWidget *widget, SAFE_FREE(state->account); SAFE_FREE(state->password); - gtk_widget_destroy(state->window_creds_prompt); - gtk_widget_destroy(state->window_do_change); + if (state->window_creds_prompt) { + gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + state->window_creds_prompt = NULL; + } + if (state->window_do_change) { + gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); + } } static void free_join_state(struct join_state *s) @@ -225,8 +233,12 @@ static void callback_do_exit(GtkWidget *widget, default: break; } - gtk_widget_destroy(dialog); - gtk_widget_destroy(state->window_main); + if (dialog) { + gtk_widget_destroy(GTK_WIDGET(dialog)); + } + if (state->window_main) { + gtk_widget_destroy(GTK_WIDGET(state->window_main)); + } do_cleanup(state); exit(0); } @@ -257,7 +269,7 @@ static void callback_do_reboot(GtkWidget *widget, gtk_widget_show(dialog); #else gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + gtk_widget_destroy(GTK_WIDGET(dialog)); #endif gtk_label_set_text(GTK_LABEL(state->label_reboot), @@ -388,10 +400,12 @@ static void callback_do_storeauth(GtkWidget *widget, SAFE_FREE(state->account); SAFE_FREE(state->password); - callback_return_username(state->entry_account, state); - callback_return_password(state->entry_password, state); + callback_return_username(state->entry_account, (gpointer)state); + callback_return_password(state->entry_password, (gpointer)state); - gtk_widget_destroy(state->window_creds_prompt); + if (state->window_creds_prompt) { + gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + } } static void callback_continue(GtkWidget *widget, @@ -1537,7 +1551,7 @@ static int init_join_state(struct join_state **state) { struct join_state *s; - s = malloc(sizeof(struct join_state)); + s = (struct join_state *)malloc(sizeof(struct join_state)); if (!s) { return -1; } -- cgit From 19e5ee0e094c563521e6515294f448f7136a928f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 5 Jun 2008 01:11:23 +0200 Subject: netdomjoin-gui: disable annoying "reboot now" dialog. Guenther (This used to be commit 8f0c5f1bedaae7a86ca671cdb2ba798079ec1d84) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index dd4e4ad394..bfd4fea87e 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -209,8 +209,10 @@ static void callback_apply_description_change(GtkWidget *widget, static void callback_do_exit(GtkWidget *widget, gpointer data) { +#if 0 GtkWidget *dialog; gint result; +#endif struct join_state *state = (struct join_state *)data; if (!state->settings_changed) { @@ -218,6 +220,7 @@ static void callback_do_exit(GtkWidget *widget, return; } +#if 0 dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_main), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, @@ -236,6 +239,7 @@ static void callback_do_exit(GtkWidget *widget, if (dialog) { gtk_widget_destroy(GTK_WIDGET(dialog)); } +#endif if (state->window_main) { gtk_widget_destroy(GTK_WIDGET(state->window_main)); } -- cgit From de89de4b58249aa6b73eae7399fe78e6b86e81f1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 5 Jun 2008 19:02:09 +0200 Subject: netdomjoin-gui: fix more gtk runtime warnings. Guenther (This used to be commit 521ea68719524eeef827875e018bb8cba2a92e87) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index bfd4fea87e..1da8169f63 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -115,6 +115,7 @@ static void callback_do_close(GtkWidget *widget, if (data) { gtk_widget_destroy(GTK_WIDGET(data)); + data = NULL; } } @@ -150,6 +151,7 @@ static void callback_do_freeauth_and_close(GtkWidget *widget, } if (state->window_do_change) { gtk_widget_destroy(GTK_WIDGET(state->window_do_change)); + state->window_do_change = NULL; } } @@ -242,6 +244,7 @@ static void callback_do_exit(GtkWidget *widget, #endif if (state->window_main) { gtk_widget_destroy(GTK_WIDGET(state->window_main)); + state->window_main = NULL; } do_cleanup(state); exit(0); @@ -409,6 +412,7 @@ static void callback_do_storeauth(GtkWidget *widget, if (state->window_creds_prompt) { gtk_widget_destroy(GTK_WIDGET(state->window_creds_prompt)); + state->window_creds_prompt = NULL; } } -- cgit From 66a5cbaf8be9de66d40660cfb57df553b651d75d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 5 Jun 2008 19:04:31 +0200 Subject: netdomjoin-gui: enable NetGetJoinInformation() call after successfull joining. Now that libnetjoin reloads configuration after joining, we can rely on the NetGetJoinInformation() output and use it for displaying the new domain name and type. Guenther (This used to be commit cc1b8de2632e87002cac86838f2a77ab9771ce2c) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 1da8169f63..418b9c8b8e 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -297,12 +297,12 @@ static void callback_do_reboot(GtkWidget *widget, } debug("got new status: %s\n", buffer); -#if 0 + SAFE_FREE(state->name_buffer_new); state->name_buffer_new = strdup(buffer); - SAFE_FREE(buffer); state->name_type_new = type; -#endif + state->name_buffer_initial = strdup(buffer); + state->name_type_initial = type; NetApiBufferFree((void *)buffer); gtk_label_set_text(GTK_LABEL(state->label_current_name_buffer), -- cgit From e710a871776eee47642ef828fd04cb0a46e43d2a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 12:52:23 +0200 Subject: netapi: use NETSETUP join flags in examples. Guenther (This used to be commit 2f6f888d9cf89abf55767dc43a9e3d5de68bbcfb) --- .../lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 418b9c8b8e..970f8cf9f2 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -38,11 +38,6 @@ #define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" #define SAMBA_IMAGE_PATH_SMALL "/usr/share/pixmaps/samba/logo-small.png" -#define WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED ( 0x00000020 ) -#define WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE ( 0x00000004 ) -#define WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE ( 0x00000002 ) -#define WKSSVC_JOIN_FLAGS_JOIN_TYPE ( 0x00000001 ) - #define NetSetupWorkgroupName ( 2 ) #define NetSetupDomainName ( 3 ) @@ -631,9 +626,9 @@ static void callback_do_join(GtkWidget *widget, if (state->name_type_new == NetSetupDomainName) { domain_join = TRUE; join_creds_required = TRUE; - join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | - WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE | - WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED; /* for testing */ + join_flags = NETSETUP_JOIN_DOMAIN | + NETSETUP_ACCT_CREATE | + NETSETUP_DOMAIN_JOIN_IF_JOINED; /* for testing */ } if ((state->name_type_initial == NetSetupDomainName) && @@ -641,8 +636,8 @@ static void callback_do_join(GtkWidget *widget, try_unjoin = TRUE; unjoin_creds_required = TRUE; join_creds_required = FALSE; - unjoin_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE | - WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE; + unjoin_flags = NETSETUP_JOIN_DOMAIN | + NETSETUP_ACCT_DELETE; } if (try_unjoin) { -- cgit From af1db71c1446c854385de691781e5bb48ec65936 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Aug 2008 12:59:56 +0200 Subject: netapi: fix some warnings in netdomjoin-gui. Guenther (This used to be commit e69eb09c1819eb4ea4bba7c3b3b0f8b6da789632) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 970f8cf9f2..4e0488ed59 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -818,9 +818,13 @@ static void callback_enter_hostname_and_unlock(GtkWidget *widget, } state->hostname_changed = TRUE; if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain); + if (asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain) == -1) { + return; + } } else { - asprintf(&str, "%s.", entry_text); + if (asprintf(&str, "%s.", entry_text) == -1) { + return; + } } gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); free(str); @@ -1127,10 +1131,14 @@ static void callback_do_change(GtkWidget *widget, char *str = NULL; entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", entry_text, - state->my_dnsdomain); + if (asprintf(&str, "%s.%s", entry_text, + state->my_dnsdomain) == -1) { + return; + } } else { - asprintf(&str, "%s.", entry_text); + if (asprintf(&str, "%s.", entry_text) == -1) { + return; + } } gtk_label_set_text(GTK_LABEL(state->label_full_computer_name), str); @@ -1431,10 +1439,14 @@ static int draw_main_window(struct join_state *state) /* Label */ char *str = NULL; if (state->name_type_initial == NetSetupDomainName) { - asprintf(&str, "%s.%s", state->my_hostname, - state->my_dnsdomain); + if (asprintf(&str, "%s.%s", state->my_hostname, + state->my_dnsdomain) == -1) { + return -1; + } } else { - asprintf(&str, "%s.", state->my_hostname); + if (asprintf(&str, "%s.", state->my_hostname) == -1) { + return -1; + } } label = gtk_label_new(str); -- cgit From cd8deeb6e06af53fe661c280569729f7ce77eea0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 1 Sep 2008 18:59:59 +0200 Subject: netdomjoin-gui: add support to remotely join/unjoin workstations. Guenther (This used to be commit 1760c4ce79ae15f9a2ea92293d823afe3af9b3ee) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 98 +++++++++++++--------- 1 file changed, 60 insertions(+), 38 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 4e0488ed59..9afdb8b58c 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -80,6 +80,7 @@ typedef struct join_state { gboolean settings_changed; gboolean hostname_changed; uint32_t stored_num_ous; + char *target_hostname; } join_state; static void debug(const char *format, ...) @@ -180,7 +181,10 @@ static void callback_apply_description_change(GtkWidget *widget, info1005.sv1005_comment = state->comment_new; - status = NetServerSetInfo(NULL, 1005, (uint8_t *)&info1005, &parm_err); + status = NetServerSetInfo(state->target_hostname, + 1005, + (uint8_t *)&info1005, + &parm_err); if (status) { debug("NetServerSetInfo failed with: %s\n", libnetapi_errstr(status)); @@ -285,7 +289,9 @@ static void callback_do_reboot(GtkWidget *widget, const char *buffer; uint16_t type; - status = NetGetJoinInformation(NULL, &buffer, &type); + status = NetGetJoinInformation(state->target_hostname, + &buffer, + &type); if (status != 0) { g_print("failed to query status\n"); return; @@ -658,7 +664,7 @@ static void callback_do_join(GtkWidget *widget, } } - status = NetUnjoinDomain(NULL, + status = NetUnjoinDomain(state->target_hostname, state->account, state->password, unjoin_flags); @@ -748,7 +754,7 @@ static void callback_do_join(GtkWidget *widget, } debug("\n"); - status = NetJoinDomain(NULL, + status = NetJoinDomain(state->target_hostname, state->name_buffer_new, account_ou, state->account, @@ -1003,7 +1009,8 @@ static void callback_do_getous(GtkWidget *widget, return; } - status = NetGetJoinableOUs(NULL, domain, + status = NetGetJoinableOUs(state->target_hostname, + domain, state->account, state->password, &num_ous, &ous); @@ -1579,7 +1586,9 @@ static int init_join_state(struct join_state **state) } static int initialize_join_state(struct join_state *state, - const char *debug_level) + const char *debug_level, + const char *target_hostname, + const char *target_username) { struct libnetapi_ctx *ctx = NULL; NET_API_STATUS status = 0; @@ -1593,6 +1602,30 @@ static int initialize_join_state(struct join_state *state, libnetapi_set_debuglevel(ctx, debug_level); } + if (target_hostname) { + state->target_hostname = strdup(target_hostname); + if (!state->target_hostname) { + return -1; + } + } + + if (target_username) { + char *puser = strdup(target_username); + char *p = NULL; + + if ((p = strchr(puser,'%'))) { + size_t len; + *p = 0; + libnetapi_set_username(ctx, puser); + libnetapi_set_password(ctx, p+1); + len = strlen(p+1); + memset(strchr(target_username,'%')+1,'X',len); + } else { + libnetapi_set_username(ctx, puser); + } + free(puser); + } + { char my_hostname[HOST_NAME_MAX]; const char *p = NULL; @@ -1639,7 +1672,9 @@ static int initialize_join_state(struct join_state *state, { const char *buffer = NULL; uint16_t type = 0; - status = NetGetJoinInformation(NULL, &buffer, &type); + status = NetGetJoinInformation(state->target_hostname, + &buffer, + &type); if (status != 0) { printf("NetGetJoinInformation failed with: %s\n", libnetapi_get_error_string(state->ctx, status)); @@ -1655,42 +1690,23 @@ static int initialize_join_state(struct join_state *state, } { - struct SERVER_INFO_1005 *info1005 = NULL; - uint8_t *buffer = NULL; + struct SERVER_INFO_101 *info101 = NULL; - status = NetServerGetInfo(NULL, 1005, &buffer); + 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; - } - - info1005 = (struct SERVER_INFO_1005 *)buffer; - - state->comment = strdup(info1005->sv1005_comment); - if (!state->comment) { - return -1; - } - NetApiBufferFree(buffer); - } -#if 0 - { - struct srvsvc_NetSrvInfo100 *info100 = NULL; - uint8_t *buffer = NULL; - - status = NetServerGetInfo(NULL, 100, &buffer); - if (status) { - return status; - } - - info100 = (struct srvsvc_NetSrvInfo100 *)buffer; - - state->comment = strdup(info100->comment); - if (!state->comment) { - return -1; + /* return status; */ + } else { + state->comment = strdup(info101->sv101_comment); + if (!state->comment) { + return -1; + } } + NetApiBufferFree(info101); } -#endif state->ctx = ctx; @@ -1701,6 +1717,8 @@ int main(int argc, char **argv) { GOptionContext *context = NULL; static const char *debug_level = NULL; + static const char *target_hostname = NULL; + static const char *target_username = NULL; struct join_state *state = NULL; GError *error = NULL; int ret = 0; @@ -1708,6 +1726,8 @@ int main(int argc, char **argv) static GOptionEntry entries[] = { { "debug", 'd', 0, G_OPTION_ARG_STRING, &debug_level, "Debug level (for samba)", "N" }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output", 0 }, + { "target", 'S', 0, G_OPTION_ARG_STRING, &target_hostname, "Target hostname", 0 }, + { "username", 'U', 0, G_OPTION_ARG_STRING, &target_username, "Target hostname", 0 }, { NULL } }; @@ -1725,7 +1745,9 @@ int main(int argc, char **argv) return ret; } - ret = initialize_join_state(state, debug_level); + ret = initialize_join_state(state, debug_level, + target_hostname, + target_username); if (ret) { return ret; } -- cgit From 6dff24790fd6344665a98a5557d97f7afecbfea9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 16:14:14 +0200 Subject: netdomjoin-gui: test all NetServerGetInfo levels until we get comment. (This used to be commit 56d353b406ef77808b9cb968fcba387f301cf2de) --- .../examples/netdomjoin-gui/netdomjoin-gui.c | 65 ++++++++++++++++------ 1 file changed, 48 insertions(+), 17 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 9afdb8b58c..def56ae0b6 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/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; -- cgit From 78ed824dab95209ea9d48d4478e3a5de24060b7d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 00:36:31 +0200 Subject: netdomjoin-gui: add gtk set_transient flags. Guenther (This used to be commit c979b96eb4b0df94e9d736a9473d00c28a52ed07) --- .../lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index def56ae0b6..45571e3f14 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -195,6 +195,7 @@ static void callback_apply_description_change(GtkWidget *widget, "Failed to change computer description: %s.", libnetapi_get_error_string(state->ctx, status)); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_main)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), @@ -266,6 +267,7 @@ static void callback_do_reboot(GtkWidget *widget, GTK_BUTTONS_OK, "You must restart this computer for the changes to take effect."); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); #if 0 g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), @@ -467,6 +469,7 @@ static void callback_do_hostname_change(GtkWidget *widget, str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_main)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -496,6 +499,7 @@ static void callback_creds_prompt(GtkWidget *widget, gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(state->window_do_change)); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_do_close), window); @@ -718,6 +722,7 @@ static void callback_do_join(GtkWidget *widget, err_str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -775,6 +780,7 @@ static void callback_do_join(GtkWidget *widget, err_str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -797,6 +803,7 @@ static void callback_do_join(GtkWidget *widget, new_workgroup_type); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); @@ -988,6 +995,7 @@ static void callback_do_getous(GtkWidget *widget, err_str); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); @@ -1025,6 +1033,7 @@ static void callback_do_getous(GtkWidget *widget, "Failed to query joinable OUs: %s", libnetapi_get_error_string(state->ctx, status)); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(state->window_do_change)); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; @@ -1090,6 +1099,7 @@ static void callback_do_change(GtkWidget *widget, gtk_window_set_resizable(GTK_WINDOW(window), FALSE); gtk_widget_set_size_request(GTK_WIDGET(window), 480, 650); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(state->window_main)); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_do_close), window); @@ -1290,6 +1300,8 @@ static void callback_do_about(GtkWidget *widget, GError *error = NULL; GtkWidget *about; + struct join_state *state = (struct join_state *)data; + debug("callback_do_about called\n"); logo = gdk_pixbuf_new_from_file(SAMBA_IMAGE_PATH, @@ -1313,6 +1325,7 @@ static void callback_do_about(GtkWidget *widget, } gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about), "Samba gtk domain join utility"); gtk_window_set_modal(GTK_WINDOW(about), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(about), GTK_WINDOW(state->window_main)); g_signal_connect_swapped(about, "response", G_CALLBACK(gtk_widget_destroy), about); @@ -1553,7 +1566,7 @@ static int draw_main_window(struct join_state *state) gtk_container_add(GTK_CONTAINER(bbox2), button2); g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(callback_do_about), - window); + state); #if 0 button2 = gtk_button_new_from_stock(GTK_STOCK_HELP); gtk_container_add(GTK_CONTAINER(bbox2), button2); -- cgit From b0ab216cd53acf119aaba88a3d07f01810a5dfa9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 00:49:33 +0200 Subject: netdomjoin-gui: fix some small errors in callbacks. Guenther (This used to be commit 74031b0b4ac1301cff6ca551c3264c4137a43294) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 45571e3f14..d5b60f1878 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -827,9 +827,11 @@ static void callback_enter_hostname_and_unlock(GtkWidget *widget, if (strcasecmp(state->my_hostname, entry_text) == 0) { state->hostname_changed = FALSE; gtk_widget_set_sensitive(GTK_WIDGET(state->button_ok), FALSE); - return; + /* return; */ + } else { + state->hostname_changed = TRUE; } - state->hostname_changed = TRUE; + if (state->name_type_initial == NetSetupDomainName) { if (asprintf(&str, "%s.%s", entry_text, state->my_dnsdomain) == -1) { return; @@ -852,7 +854,7 @@ static void callback_enter_computer_description_and_unlock(GtkWidget *widget, { const gchar *entry_text = NULL; struct join_state *state = (struct join_state *)data; - int string_unchanged = 0; + int string_unchanged = FALSE; entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); debug("callback_enter_computer_description_and_unlock: %s\n", @@ -865,8 +867,8 @@ static void callback_enter_computer_description_and_unlock(GtkWidget *widget, return; } #endif - if (entry_text && strcasecmp(state->comment, entry_text) == 0) { - string_unchanged = 1; + if (entry_text && state->comment && strcasecmp(state->comment, entry_text) == 0) { + string_unchanged = TRUE; gtk_widget_set_sensitive(GTK_WIDGET(state->button_apply), FALSE); return; -- cgit From 685f7e3419b27cd0e274b7a768d9fa23b7de5f85 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 01:06:25 +0200 Subject: netdomjoin-gui: always center new windows. Guenther (This used to be commit af25bd95d24de8e9fac8f86b18e03a09902b0b78) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index d5b60f1878..bf41ee430d 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -500,6 +500,7 @@ static void callback_creds_prompt(GtkWidget *widget, gtk_widget_set_size_request(GTK_WIDGET(window), 380, 280); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(state->window_do_change)); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_do_close), window); @@ -1102,6 +1103,7 @@ static void callback_do_change(GtkWidget *widget, gtk_widget_set_size_request(GTK_WIDGET(window), 480, 650); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(state->window_main)); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_do_close), window); @@ -1374,6 +1376,7 @@ static int draw_main_window(struct join_state *state) gtk_widget_set_size_request(GTK_WIDGET(window), 600, 600); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); gtk_window_set_icon_from_file(GTK_WINDOW(window), SAMBA_ICON_PATH, NULL); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(callback_delete_event), NULL); -- cgit From 231de7054a8f92990bc3b9da7dbddfa18cc44ff1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 02:02:20 +0200 Subject: netdomjoin-gui: fix some widget closing callbacks. Guenther (This used to be commit 8d541a3579637bb48c04ebb2b18844509c1f43e8) --- .../netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index bf41ee430d..98994b69f8 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -104,14 +104,23 @@ static gboolean callback_delete_event(GtkWidget *widget, return FALSE; } -static void callback_do_close(GtkWidget *widget, - gpointer data) +static void callback_do_close_data(GtkWidget *widget, + gpointer data) { - debug("callback_do_close called\n"); + debug("callback_do_close_data called\n"); if (data) { gtk_widget_destroy(GTK_WIDGET(data)); - data = NULL; + } +} + +static void callback_do_close_widget(GtkWidget *widget, + gpointer data) +{ + debug("callback_do_close_widget called\n"); + + if (widget) { + gtk_widget_destroy(widget); } } @@ -503,7 +512,7 @@ static void callback_creds_prompt(GtkWidget *widget, gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close), window); + G_CALLBACK(callback_do_close_widget), NULL); state->window_creds_prompt = window; gtk_container_set_border_width(GTK_CONTAINER(window), 10); @@ -1106,7 +1115,7 @@ static void callback_do_change(GtkWidget *widget, gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(callback_do_close), window); + G_CALLBACK(callback_do_close_widget), NULL); gtk_container_set_border_width(GTK_CONTAINER(window), 10); -- cgit From 150911f33e137d017e9f08f953bd96218401e04a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Sep 2008 14:35:58 +0200 Subject: netapi: remove NetSetup* flags from netdomjoin-gui. Guenther (This used to be commit 5851b4e40e5cc2b7ba973b274f9203aa6e6fb1d8) --- source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source3/lib/netapi/examples/netdomjoin-gui') diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c index 98994b69f8..40a6e415eb 100644 --- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c +++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c @@ -38,9 +38,6 @@ #define SAMBA_IMAGE_PATH "/usr/share/pixmaps/samba/logo.png" #define SAMBA_IMAGE_PATH_SMALL "/usr/share/pixmaps/samba/logo-small.png" -#define NetSetupWorkgroupName ( 2 ) -#define NetSetupDomainName ( 3 ) - #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) static gboolean verbose = FALSE; -- cgit