<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>
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;
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 */
*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;
gchar *password_nuova;
gchar *host;
- gchar *base_dn;
gchar *user_field;
- LDAP *ldap;
int version;
int retldap;
host = NULL;
base_dn = NULL;
+ users_ou = NULL;
+ groups_ou = NULL;
user_field = NULL;
#ifdef HAVE_LIBCONFI
{
host = NULL;
base_dn = NULL;
+ users_ou = NULL;
+ groups_ou = NULL;
user_field = NULL;
}
}
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;
+ }
+ }
+ }
+ }
}
}
}
if (host == NULL
|| base_dn == NULL
+ || users_ou == NULL
+ || groups_ou == NULL
|| user_field == NULL)
{
return NULL;
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;
}
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
autesmbldap_on_btn_edit_clicked (GtkButton *button,
gpointer user_data)
{
-/* autesmbldap_edit_user ();*/
+ autesmbldap_edit_user ();
}
static void
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
#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.");
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);
G_CALLBACK (autesmbldap_on_btn_find_clicked), NULL);
autesmbldap_load_users_list ();
+ autesmbldap_load_groups_list ();
return w_users;
}