]> saetta.ns0.it Git - zakauthe/plugins/smbldap/commitdiff
Loaded users and groups in ui.
authorAndrea Zagli <azagli@libero.it>
Wed, 11 Aug 2010 17:04:06 +0000 (19:04 +0200)
committerAndrea Zagli <azagli@libero.it>
Wed, 11 Aug 2010 17:04:06 +0000 (19:04 +0200)
Makefile.am
configure.ac
data/libaute-smbldap/gui/autesmbldap.gui
doc/Makefile.am [new file with mode: 0644]
doc/libaute-smbldap/Makefile.am [new file with mode: 0644]
doc/libaute-smbldap/examples/Makefile.am [new file with mode: 0644]
doc/libaute-smbldap/examples/libaute-smbldap.conf [new file with mode: 0644]
src/aute_smbldap.c

index 9768a98a9e0b6edd6c03c1806a1a9a6e3462fcaf..d79362d8faf85ecc12d697b86769d5c715064599 100644 (file)
@@ -1 +1 @@
-SUBDIRS = src data
+SUBDIRS = src data doc
index f2d09355a03dc8b5747536084f0777d526426ec3..a8fcd4aab160c2383a86fd180af757464bdb33e2 100644 (file)
@@ -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
index bc8a74f2572f1e622b4e4d1c39963a24a8a4d972..acda08fec88ef23c8facaa35665585e3daea8587 100644 (file)
       <action-widget response="-5">okbutton1</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkListStore" id="lstore_groups">
+    <columns>
+      <!-- column-name cn -->
+      <column type="gchararray"/>
+      <!-- column-name gid -->
+      <column type="guint"/>
+    </columns>
+  </object>
+  <object class="GtkListStore" id="lstore_users">
+    <columns>
+      <!-- column-name status -->
+      <column type="gchararray"/>
+      <!-- column-name cn -->
+      <column type="gchararray"/>
+      <!-- column-name display_name -->
+      <column type="gchararray"/>
+      <!-- column-name uid -->
+      <column type="guint"/>
+    </columns>
+  </object>
   <object class="GtkWindow" id="w_users_list">
     <child>
       <object class="GtkVBox" id="vbx_users_list">
     <property name="title" translatable="yes">User</property>
     <property name="modal">True</property>
     <property name="window_position">center-on-parent</property>
+    <property name="default_width">300</property>
     <property name="destroy_with_parent">True</property>
     <child>
       <object class="GtkVBox" id="vbox1">
       </object>
     </child>
   </object>
-  <object class="GtkListStore" id="lstore_groups">
-    <columns>
-      <!-- column-name cn -->
-      <column type="gchararray"/>
-      <!-- column-name gid -->
-      <column type="guint"/>
-    </columns>
-  </object>
-  <object class="GtkListStore" id="lstore_users">
-    <columns>
-      <!-- column-name status -->
-      <column type="gchararray"/>
-      <!-- column-name cn -->
-      <column type="gchararray"/>
-      <!-- column-name display_name -->
-      <column type="gchararray"/>
-      <!-- column-name uid -->
-      <column type="guint"/>
-    </columns>
-  </object>
   <object class="GtkWindow" id="w_group">
     <property name="title" translatable="yes">Group</property>
     <property name="modal">True</property>
         <child>
           <object class="GtkTable" id="table4">
             <property name="visible">True</property>
+            <property name="n_rows">3</property>
             <property name="n_columns">2</property>
             <property name="column_spacing">5</property>
             <property name="row_spacing">5</property>
                 <property name="y_options">GTK_FILL</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkLabel" id="label16">
+                <property name="label" translatable="yes">lbl_cn_key</property>
+              </object>
+              <packing>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
+                <property name="x_options">GTK_FILL</property>
+                <property name="y_options">GTK_FILL</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label17">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">GID</property>
+              </object>
+              <packing>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+                <property name="x_options">GTK_FILL</property>
+                <property name="y_options">GTK_FILL</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label18">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">lbl_gid</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+                <property name="y_options">GTK_FILL</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="position">0</property>
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644 (file)
index 0000000..5909f74
--- /dev/null
@@ -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 (file)
index 0000000..aee2d7b
--- /dev/null
@@ -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 (file)
index 0000000..97551eb
--- /dev/null
@@ -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 (file)
index 0000000..e5b6c99
--- /dev/null
@@ -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
index c63d2b87f6ef4432d50012cae4729ae1fa89dd9c..0297c66ef949c4ffb53dfd284da4786a0ab50f0c 100644 (file)
@@ -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;
 }