From: Andrea Zagli Date: Wed, 11 Aug 2010 17:04:06 +0000 (+0200) Subject: Loaded users and groups in ui. X-Git-Tag: v0.1.1~12 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=7bec544b901b2cfc6d5c96e6156f6a2243e8b005;p=zakauthe%2Fplugins%2Fsmbldap Loaded users and groups in ui. --- diff --git a/Makefile.am b/Makefile.am index 9768a98..d79362d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1 +1 @@ -SUBDIRS = src data +SUBDIRS = src data doc diff --git a/configure.ac b/configure.ac index f2d0935..a8fcd4a 100644 --- a/configure.ac +++ b/configure.ac @@ -67,5 +67,8 @@ AC_CONFIG_FILES([ data/libaute-smbldap/Makefile data/libaute-smbldap/form/Makefile data/libaute-smbldap/gui/Makefile + doc/Makefile + doc/libaute-smbldap/Makefile + doc/libaute-smbldap/examples/Makefile ]) AC_OUTPUT diff --git a/data/libaute-smbldap/gui/autesmbldap.gui b/data/libaute-smbldap/gui/autesmbldap.gui index bc8a74f..acda08f 100644 --- a/data/libaute-smbldap/gui/autesmbldap.gui +++ b/data/libaute-smbldap/gui/autesmbldap.gui @@ -205,6 +205,26 @@ okbutton1 + + + + + + + + + + + + + + + + + + + + @@ -421,6 +441,7 @@ User True center-on-parent + 300 True @@ -667,26 +688,6 @@ - - - - - - - - - - - - - - - - - - - - Group True @@ -701,6 +702,7 @@ True + 3 2 5 5 @@ -728,6 +730,47 @@ GTK_FILL + + + lbl_cn_key + + + 2 + 3 + GTK_FILL + GTK_FILL + + + + + + + + True + 0 + GID + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + 0 + lbl_gid + + + 1 + 2 + 1 + 2 + GTK_FILL + + 0 diff --git a/doc/Makefile.am b/doc/Makefile.am new file mode 100644 index 0000000..5909f74 --- /dev/null +++ b/doc/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = libaute-smbldap + +EXTRA_DIST = diff --git a/doc/libaute-smbldap/Makefile.am b/doc/libaute-smbldap/Makefile.am new file mode 100644 index 0000000..aee2d7b --- /dev/null +++ b/doc/libaute-smbldap/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = examples diff --git a/doc/libaute-smbldap/examples/Makefile.am b/doc/libaute-smbldap/examples/Makefile.am new file mode 100644 index 0000000..97551eb --- /dev/null +++ b/doc/libaute-smbldap/examples/Makefile.am @@ -0,0 +1,7 @@ +libautesmbldap_examplesdir = $(docdir)/examples + +libautesmbldap_examples_DATA = \ + libaute-smbldap.conf + +EXTRA_DIST = $(libautesmbldap_examples_DATA) + diff --git a/doc/libaute-smbldap/examples/libaute-smbldap.conf b/doc/libaute-smbldap/examples/libaute-smbldap.conf new file mode 100644 index 0000000..e5b6c99 --- /dev/null +++ b/doc/libaute-smbldap/examples/libaute-smbldap.conf @@ -0,0 +1,7 @@ +[AUTE] +plugin=/usr/local/lib/libaute/plugins/libaute-smbldap +host=ldap://10.0.0.102/ +base_dn=dc=nodomain +users_ou=ou=Users +groups_ou=ou=Groups +user_field=uid diff --git a/src/aute_smbldap.c b/src/aute_smbldap.c index c63d2b8..0297c66 100644 --- a/src/aute_smbldap.c +++ b/src/aute_smbldap.c @@ -36,6 +36,11 @@ static GtkBuilder *gtkbuilder; static gchar *guifile; static gchar *formdir; +static LDAP *ldap; +static gchar *base_dn; +static gchar *users_ou; +static gchar *groups_ou; + static GtkWidget *txt_utente; static GtkWidget *txt_password; static GtkWidget *exp_cambio; @@ -48,12 +53,22 @@ static GtkTreeView *trv_users; static GtkListStore *lstore_users; static GtkTreeSelection *sel_users; +static GtkTreeView *trv_groups; +static GtkListStore *lstore_groups; +static GtkTreeSelection *sel_groups; + enum { - COL_STATUS, - COL_CODE, - COL_NAME, - COL_PASSWORD_EXPIRATION + COL_USERS_STATUS, + COL_USERS_CN, + COL_USERS_NAME, + COL_USERS_UID +}; + +enum +{ + COL_GROUPS_CN, + COL_GROUPS_GID }; /* PRIVATE */ @@ -65,17 +80,25 @@ get_connection_parameters_from_confi (Confi *confi, gchar **host, gchar **base_d *host = confi_path_get_value (confi, "aute/aute-smbldap/ldap/host"); *base_dn = confi_path_get_value (confi, "aute/aute-smbldap/ldap/base_dn"); + users_ou = confi_path_get_value (confi, "aute/aute-smbldap/ldap/users_ou"); + groups_ou = confi_path_get_value (confi, "aute/aute-smbldap/ldap/groups_ou"); *user_field = confi_path_get_value (confi, "aute/aute-smbldap/ldap/user_field"); if (*host == NULL || strcmp (g_strstrip (*host), "") == 0 || base_dn == NULL || strcmp (g_strstrip (*base_dn), "") == 0 + || users_ou == NULL + || strcmp (g_strstrip (users_ou), "") == 0 + || groups_ou == NULL + || strcmp (g_strstrip (groups_ou), "") == 0 || user_field == NULL || strcmp (g_strstrip (*user_field), "") == 0) { *host = NULL; *base_dn = NULL; + users_ou = NULL; + groups_ou = NULL; *user_field = NULL; ret = FALSE; @@ -116,10 +139,8 @@ static gchar gchar *password_nuova; gchar *host; - gchar *base_dn; gchar *user_field; - LDAP *ldap; int version; int retldap; @@ -130,6 +151,8 @@ static gchar host = NULL; base_dn = NULL; + users_ou = NULL; + groups_ou = NULL; user_field = NULL; #ifdef HAVE_LIBCONFI @@ -141,6 +164,8 @@ static gchar { host = NULL; base_dn = NULL; + users_ou = NULL; + groups_ou = NULL; user_field = NULL; } } @@ -175,11 +200,37 @@ static gchar param = g_slist_next (param); if (param != NULL && param->data != NULL) { - user_field = g_strdup ((gchar *)param->data); - user_field = g_strstrip (user_field); - if (g_strcmp0 (user_field, "") == 0) + users_ou = g_strdup ((gchar *)param->data); + users_ou = g_strstrip (users_ou); + if (g_strcmp0 (users_ou, "") == 0) + { + users_ou = NULL; + } + else { - user_field = NULL; + param = g_slist_next (param); + if (param != NULL && param->data != NULL) + { + groups_ou = g_strdup ((gchar *)param->data); + groups_ou = g_strstrip (groups_ou); + if (g_strcmp0 (groups_ou, "") == 0) + { + groups_ou = NULL; + } + else + { + param = g_slist_next (param); + if (param != NULL && param->data != NULL) + { + user_field = g_strdup ((gchar *)param->data); + user_field = g_strstrip (user_field); + if (g_strcmp0 (user_field, "") == 0) + { + user_field = NULL; + } + } + } + } } } } @@ -190,6 +241,8 @@ static gchar if (host == NULL || base_dn == NULL + || users_ou == NULL + || groups_ou == NULL || user_field == NULL) { return NULL; @@ -200,31 +253,31 @@ static gchar retldap = ldap_initialize (&ldap, host); if (retldap != LDAP_SUCCESS) { - g_warning ("Errore nell'inizializzazione.\n%s\n", ldap_err2string (retldap)); + g_warning ("Errore nell'inizializzazione: %s", ldap_err2string (retldap)); return NULL; } retldap = ldap_set_option (ldap, LDAP_OPT_PROTOCOL_VERSION, &version); if (retldap != LDAP_OPT_SUCCESS) { - g_warning ("Errore nell'impostazione della versione del protocollo.\n%s\n", ldap_err2string (retldap)); + g_warning ("Errore nell'impostazione della versione del protocollo: %s", ldap_err2string (retldap)); return NULL; } - user_dn = g_strdup_printf ("%s=%s,%s", user_field, utente, base_dn); + user_dn = g_strdup_printf ("%s=%s,%s,%s", user_field, utente, users_ou, base_dn); retldap = ldap_simple_bind_s (ldap, user_dn, password); if (retldap != LDAP_SUCCESS) { - g_warning ("Errore nel bind.\n%s\n", ldap_err2string (retldap)); + g_warning ("Errore nel bind: %s", ldap_err2string (retldap)); return NULL; } - retldap = ldap_unbind (ldap); + /*retldap = ldap_unbind (ldap); if (retldap != LDAP_SUCCESS) { - g_warning ("Errore nell'unbind.\n%s\n", ldap_err2string (retldap)); + g_warning ("Errore nell'unbind: %s", ldap_err2string (retldap)); return NULL; - } + }*/ return user_dn; } @@ -232,39 +285,147 @@ static gchar static void autesmbldap_load_users_list () { - /*gchar *sql; - GdaDataModel *dm; + int retldap; + LDAPMessage *result; + LDAPMessage *entry; + BerElement *ber; + gchar *attr; + struct berval **vals; + + guint i; + + gchar *attrs[] = {"cn", "displayName", "uidNumber"}; - guint rows; - guint row; GtkTreeIter iter; gtk_list_store_clear (lstore_users); - sql = g_strdup_printf ("SELECT * FROM users WHERE status <> 'E' ORDER BY surname, name, code"); - dm = gdaex_query (gdaex, sql); - if (dm != NULL) + retldap = ldap_search_ext_s (ldap, g_strdup_printf ("%s,%s", users_ou, base_dn), LDAP_SCOPE_ONELEVEL, + NULL, attrs, 0, NULL, NULL, LDAP_NO_LIMIT, + LDAP_NO_LIMIT, &result); + if (retldap != LDAP_SUCCESS) { - rows = gda_data_model_get_n_rows (dm); - for (row = 0; row < rows; row++) + g_warning ("Errore nel search: %s", ldap_err2string (retldap)); + return; + } + entry = ldap_first_entry (ldap, result); + while (entry != NULL) + { + gtk_list_store_append (lstore_users, &iter); + + for (attr = ldap_first_attribute (ldap, entry, &ber); + attr != NULL; attr = ldap_next_attribute (ldap, entry, ber)) { - gtk_list_store_append (lstore_users, &iter); - gtk_list_store_set (lstore_users, &iter, - COL_STATUS, gdaex_data_model_get_field_value_boolean_at (dm, row, "enabled") ? "" : "Disabled", - COL_CODE, gdaex_data_model_get_field_value_stringify_at (dm, row, "code"), - COL_NAME, g_strdup_printf ("%s %s", - gdaex_data_model_get_field_value_stringify_at (dm, row, "surname"), - gdaex_data_model_get_field_value_stringify_at (dm, row, "name")), - COL_PASSWORD_EXPIRATION, gtk_form_field_datetime_get_str_from_tm (gdaex_data_model_get_field_value_tm_at (dm, row, "password_expiration"), "%d/%m/%Y %H.%M.%S"), - -1); + vals = ldap_get_values_len (ldap, entry, attr); + if (vals != NULL) + { + if (vals[0] != NULL) + { + if (g_strcmp0 (attr, "cn") == 0) + { + gtk_list_store_set (lstore_users, &iter, + COL_USERS_CN, vals[0]->bv_val, + -1); + } + else if (g_strcmp0 (attr, "displayName") == 0) + { + gtk_list_store_set (lstore_users, &iter, + COL_USERS_NAME, vals[0]->bv_val, + -1); + } + else if (g_strcmp0 (attr, "uidNumber") == 0) + { + gtk_list_store_set (lstore_users, &iter, + COL_USERS_UID, strtol (vals[0]->bv_val, NULL, 10), + -1); + } + } + ldap_value_free_len (vals); + } + ldap_memfree (attr); } - }*/ + if (ber != NULL) + { + ber_free (ber, 0); + } + entry = ldap_next_entry (ldap, entry); + } +} + +static void +autesmbldap_load_groups_list () +{ + int retldap; + LDAPMessage *result; + LDAPMessage *entry; + BerElement *ber; + gchar *attr; + struct berval **vals; + + guint i; + + gchar *attrs[] = {"cn", "gidNumber"}; + + GtkTreeIter iter; + + gtk_list_store_clear (lstore_groups); + + retldap = ldap_search_ext_s (ldap, g_strdup_printf ("%s,%s", groups_ou, base_dn), LDAP_SCOPE_ONELEVEL, + NULL, attrs, 0, NULL, NULL, LDAP_NO_LIMIT, + LDAP_NO_LIMIT, &result); + if (retldap != LDAP_SUCCESS) + { + g_warning ("Errore nel search: %s", ldap_err2string (retldap)); + return; + } + entry = ldap_first_entry (ldap, result); + while (entry != NULL) + { + gtk_list_store_append (lstore_groups, &iter); + + for (attr = ldap_first_attribute (ldap, entry, &ber); + attr != NULL; attr = ldap_next_attribute (ldap, entry, ber)) + { + vals = ldap_get_values_len (ldap, entry, attr); + if (vals != NULL) + { + if (vals[0] != NULL) + { + if (g_strcmp0 (attr, "cn") == 0) + { + gtk_list_store_set (lstore_groups, &iter, + COL_GROUPS_CN, vals[0]->bv_val, + -1); + } + else if (g_strcmp0 (attr, "gidNumber") == 0) + { + gtk_list_store_set (lstore_groups, &iter, + COL_GROUPS_GID, strtol (vals[0]->bv_val, NULL, 10), + -1); + } + } + ldap_value_free_len (vals); + } + ldap_memfree (attr); + } + if (ber != NULL) + { + ber_free (ber, 0); + } + entry = ldap_next_entry (ldap, entry); + } } static void autesmbldap_on_user_aggiornato (gpointer instance, gpointer user_data) { -/* autesmbldap_load_users_list ();*/ + autesmbldap_load_users_list (); +} + +static void +autesmbldap_on_group_aggiornato (gpointer instance, gpointer user_data) +{ + autesmbldap_load_groups_list (); } static void @@ -322,7 +483,7 @@ static void autesmbldap_on_btn_edit_clicked (GtkButton *button, gpointer user_data) { -/* autesmbldap_edit_user ();*/ + autesmbldap_edit_user (); } static void @@ -374,7 +535,16 @@ autesmbldap_on_trv_users_row_activated (GtkTreeView *tree_view, GtkTreeViewColumn *column, gpointer user_data) { -/* autesmbldap_edit_user ();*/ + autesmbldap_edit_user (); +} + +static void +autesmbldap_on_trv_groups_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data) +{ + autesmbldap_edit_user (); } static void @@ -480,7 +650,7 @@ GtkWidget #endif if (!gtk_builder_add_objects_from_file (gtkbuilder, g_build_filename (GUIDIR, "autesmbldap.gui", NULL), - g_strsplit ("lstore_users|vbx_users_list", "|", -1), + g_strsplit ("lstore_users|lstore_groups|vbx_users_list", "|", -1), &error)) { g_error ("Impossibile trovare il file di definizione dell'interfaccia utente."); @@ -498,8 +668,14 @@ GtkWidget lstore_users = GTK_LIST_STORE (gtk_builder_get_object (gtkbuilder, "lstore_users")); sel_users = gtk_tree_view_get_selection (trv_users); + trv_groups = GTK_TREE_VIEW (gtk_builder_get_object (gtkbuilder, "treeview2")); + lstore_groups = GTK_LIST_STORE (gtk_builder_get_object (gtkbuilder, "lstore_groups")); + sel_groups = gtk_tree_view_get_selection (trv_groups); + g_signal_connect (gtk_builder_get_object (gtkbuilder, "treeview1"), "row-activated", G_CALLBACK (autesmbldap_on_trv_users_row_activated), NULL); + g_signal_connect (gtk_builder_get_object (gtkbuilder, "treeview2"), + "row-activated", G_CALLBACK (autesmbldap_on_trv_groups_row_activated), NULL); g_signal_connect (G_OBJECT (gtk_builder_get_object (gtkbuilder, "button1")), "clicked", G_CALLBACK (autesmbldap_on_btn_new_clicked), NULL); @@ -511,6 +687,7 @@ GtkWidget G_CALLBACK (autesmbldap_on_btn_find_clicked), NULL); autesmbldap_load_users_list (); + autesmbldap_load_groups_list (); return w_users; }