[glom/glom-1-20] Limit user and group name lengths.



commit 3895e782e9936a9ce7bb8290c766d346b1cd782b
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Feb 1 15:15:18 2012 +0100

    Limit user and group name lengths.
    
    * glom/libglom/privs.[h|cc]: Add a MAX_ROLE_SIZE enum constants.
    I cannot find any PostgreSQL documentation of this 63 character limit.
    * glom/mode_design/users/dialog_new_group.cc:
    * glom/mode_design/users/dialog_user.cc: Use it to set maximum characters
    for the entry boxes.
    * tests/test_selfhosting_new_empty_then_users.cc: Show that the problem
    found so far was caused by too-long names, not spaces.
    I still need to check parsing of table permissions.
    
    Conflicts:
    
    	tests/test_selfhosting_new_empty_then_users.cc

 ChangeLog                                  |   13 +++++++++++++
 glom/libglom/privs.cc                      |    2 ++
 glom/libglom/privs.h                       |   10 ++++++++++
 glom/mode_design/users/dialog_new_group.cc |    1 +
 glom/mode_design/users/dialog_user.cc      |    4 ++++
 5 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4e9be92..461c4ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2012-02-01  Murray Cumming  <murrayc murrayc com>
+
+	Limit user and group name lengths.
+
+	* glom/libglom/privs.[h|cc]: Add a MAX_ROLE_SIZE enum constants.
+	I cannot find any PostgreSQL documentation of this 63 character limit.
+	* glom/mode_design/users/dialog_new_group.cc:
+	* glom/mode_design/users/dialog_user.cc: Use it to set maximum characters
+	for the entry boxes.
+	* tests/test_selfhosting_new_empty_then_users.cc: Show that the problem
+	found so far was caused by too-long names, not spaces.
+	I still need to check parsing of table permissions.
+
 2012-01-30  Murray Cumming  <murrayc murrayc com>
 
 	test_selfhosting_new_empty: Simplify the cleanup code.
diff --git a/glom/libglom/privs.cc b/glom/libglom/privs.cc
index f29f6cc..4e4081c 100644
--- a/glom/libglom/privs.cc
+++ b/glom/libglom/privs.cc
@@ -133,6 +133,7 @@ Privs::type_vec_strings Privs::get_database_users(const Glib::ustring& group_nam
       builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
         builder->add_field_id("groname", "pg_group"),
         builder->add_expr(group_name)));
+    //TODO: Show SQL.
     Glib::RefPtr<Gnome::Gda::DataModel> data_model = DbUtils::query_execute_select(builder);
     if(data_model && data_model->get_n_rows())
     {
@@ -162,6 +163,7 @@ Privs::type_vec_strings Privs::get_database_users(const Glib::ustring& group_nam
           if(data_model && data_model->get_n_rows() && data_model->get_n_columns())
           {
             const Gnome::Gda::Value value = data_model->get_value_at(0, 0);
+            //std::cout << G_STRFUNC << "DEBUG:  username=" << value.get_string() << std::endl; 
             result.push_back(value.get_string());
           }
           else
diff --git a/glom/libglom/privs.h b/glom/libglom/privs.h
index d84c185..5fec4c8 100644
--- a/glom/libglom/privs.h
+++ b/glom/libglom/privs.h
@@ -32,6 +32,16 @@ class Privs : public GlomPostgres
 {
 public:
 
+  /** This is apparently undocumented in PostgreSQL,
+   * but if we try to create a user or group
+   * with more characters (or bytes?) than this then
+   * a truncated version of it will be read back.
+   */
+  enum constant
+  {
+     MAX_ROLE_SIZE = 63
+  };
+
   /** Get the groups with access to the database.
    */
   static type_vec_strings get_database_groups();
diff --git a/glom/mode_design/users/dialog_new_group.cc b/glom/mode_design/users/dialog_new_group.cc
index 497ff93..664646a 100644
--- a/glom/mode_design/users/dialog_new_group.cc
+++ b/glom/mode_design/users/dialog_new_group.cc
@@ -31,6 +31,7 @@ Dialog_NewGroup::Dialog_NewGroup(BaseObjectType* cobject, const Glib::RefPtr<Gtk
   m_entry_name(0)
 {
   builder->get_widget("entry_group_name", m_entry_name);
+  m_entry_name.set_max_length(Privs::MAX_ROLE_SIZE);
 
   //m_entry_name->signal_changed().connect( sigc::mem_fun(*this, &Dialog_NewGroup::on_entry_name_changed) );
 }
diff --git a/glom/mode_design/users/dialog_user.cc b/glom/mode_design/users/dialog_user.cc
index e7978d8..52674d9 100644
--- a/glom/mode_design/users/dialog_user.cc
+++ b/glom/mode_design/users/dialog_user.cc
@@ -35,9 +35,13 @@ Dialog_User::Dialog_User(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builde
   //builder->get_widget("label_table_name", m_label_table_name);
 
   builder->get_widget("entry_user", m_entry_user);
+  m_entry_name.set_max_length(Privs::MAX_ROLE_SIZE);
   builder->get_widget_derived("combobox_group", m_combo_group);
+
   builder->get_widget("entry_password", m_entry_password);
+  m_entry_password.set_max_length(Privs::MAX_ROLE_SIZE); //Let's assume that this has a similar (undocumented in PostgreSQL) max size as the user.
   builder->get_widget("entry_password_confirm", m_entry_password_confirm);
+  m_entry_password_confirm.set_max_length(Privs::MAX_ROLE_SIZE);
 
   show_all_children();
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]