r21296: remove the session specific encryption from the attributes
[metze/samba/wip.git] / source4 / gtk / common / select.c
index 46a914083167f5a7cf08a1b342756b3326c0c1a6..5a0480ab28cd778a5dea10e038f529a704b6e130 100644 (file)
 */
 
 #include "includes.h"
-#include "librpc/gen_ndr/ndr_samr.h"
+#include "librpc/gen_ndr/ndr_samr_c.h"
 #include "gtk/common/select.h"
 #include "gtk/common/gtk-smb.h"
+#include "auth/credentials/credentials.h"
 
 /* GtkSelectDomainDialog */
 
@@ -31,7 +32,7 @@ const char *gtk_select_domain_dialog_get_domain(GtkSelectDomainDialog *d)
        return gtk_entry_get_text(GTK_ENTRY(d->entry_domain));
 }
 
-void gtk_select_domain_dialog_init (GtkSelectDomainDialog *select_domain_dialog)
+static void gtk_select_domain_dialog_init (GtkSelectDomainDialog *select_domain_dialog)
 {
        GtkWidget *dialog_vbox1;
        GtkWidget *hbox1;
@@ -123,7 +124,7 @@ GType gtk_select_domain_dialog_get_type (void)
                                                                                                                              
 GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_pipe *sam_pipe)
 {
-       GtkSelectDomainDialog *d = gtk_type_new (gtk_select_domain_dialog_get_type ());
+       GtkSelectDomainDialog *d = g_object_new(gtk_select_domain_dialog_get_type (), NULL);
        NTSTATUS status;
        struct samr_EnumDomains r;
        struct samr_Connect cr;
@@ -136,13 +137,13 @@ GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_pipe *sam_pipe)
        d->sam_pipe = sam_pipe;
 
        cr.in.system_name = 0;
-       cr.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
+       cr.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
        cr.out.connect_handle = &handle;
 
        status = dcerpc_samr_Connect(sam_pipe, mem_ctx, &cr);
        if (!NT_STATUS_IS_OK(status)) {
-               gtk_show_ntstatus(NULL, status);
-               talloc_destroy(mem_ctx);
+               gtk_show_ntstatus(NULL, "Running Connect on SAMR", status);
+               talloc_free(mem_ctx);
                return GTK_WIDGET(d);
        }
 
@@ -153,7 +154,7 @@ GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_pipe *sam_pipe)
 
        status = dcerpc_samr_EnumDomains(sam_pipe, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
-               gtk_show_ntstatus(NULL, status);
+               gtk_show_ntstatus(NULL, "Enumerating domains", status);
        } else if (r.out.sam) {
                for (i=0;i<r.out.sam->count;i++) {
                        GtkTreeIter iter;
@@ -167,12 +168,12 @@ GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_pipe *sam_pipe)
 
        status = dcerpc_samr_Close(sam_pipe, mem_ctx, &dr);
        if (!NT_STATUS_IS_OK(status)) {
-               gtk_show_ntstatus(NULL, status);
-               talloc_destroy(mem_ctx);
+               gtk_show_ntstatus(NULL, "Closing SAMR connection", status);
+               talloc_free(mem_ctx);
                return GTK_WIDGET ( d );
        }
 
-       talloc_destroy(mem_ctx);
+       talloc_free(mem_ctx);
 
        return GTK_WIDGET ( d );
 }
@@ -184,7 +185,7 @@ const char *gtk_select_host_dialog_get_host (GtkSelectHostDialog *d)
        return gtk_entry_get_text(GTK_ENTRY(d->entry_host));
 }
 
-void gtk_select_host_dialog_init (GtkSelectHostDialog *select_host_dialog)
+static void gtk_select_host_dialog_init (GtkSelectHostDialog *select_host_dialog)
 {
        GtkWidget *dialog_vbox2;
        GtkWidget *hbox2;
@@ -256,7 +257,49 @@ GType gtk_select_host_dialog_get_type (void)
        return mytype;
 }
                                                                                                                              
-GtkWidget *gtk_select_host_dialog_new (struct sam_pipe *sam_pipe, BOOL nocredentials)
+GtkWidget *gtk_select_host_dialog_new (struct dcerpc_pipe *sam_pipe)
 {
-        return GTK_WIDGET ( gtk_type_new (gtk_select_host_dialog_get_type ()));
+        return GTK_WIDGET ( g_object_new (gtk_select_host_dialog_get_type (), NULL ));
+}
+
+/**
+ * Connect to a specific interface, but ask the user 
+ * for information not specified
+ */
+struct dcerpc_pipe *gtk_connect_rpc_interface(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *table)
+{
+       GtkRpcBindingDialog *d;
+       NTSTATUS status;
+       struct dcerpc_pipe *pipe;
+       struct cli_credentials *cred;
+       gint result;
+
+       d = GTK_RPC_BINDING_DIALOG(gtk_rpc_binding_dialog_new(NULL));
+       result = gtk_dialog_run(GTK_DIALOG(d));
+
+       if (result != GTK_RESPONSE_ACCEPT) {
+               gtk_widget_destroy(GTK_WIDGET(d));
+               return NULL;
+       }
+
+       cred = cli_credentials_init(mem_ctx);
+       cli_credentials_guess(cred);
+       cli_credentials_set_gtk_callbacks(cred);
+
+       status = dcerpc_pipe_connect_b(mem_ctx, &pipe,
+                                      gtk_rpc_binding_dialog_get_binding(d, mem_ctx),
+                                      table, cred, NULL);
+
+       if(!NT_STATUS_IS_OK(status)) {
+               gtk_show_ntstatus(NULL, "While connecting to interface", status);
+               gtk_widget_destroy(GTK_WIDGET(d));
+               talloc_free(cred);
+               return NULL;
+       }
+
+       gtk_widget_destroy(GTK_WIDGET(d));
+       
+       talloc_free(cred);
+
+       return pipe;
 }