[accounts-dialog] Use the same name validation as shadow-utils
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [accounts-dialog] Use the same name validation as shadow-utils
- Date: Fri, 26 Mar 2010 05:52:36 +0000 (UTC)
commit 2422b851eaef0edbc789d42c79f46af5cd517b1d
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Mar 26 01:48:42 2010 -0400
Use the same name validation as shadow-utils
Allow names up to 31 characters, containing upper- and lowercase
characters, digits, and .-_.
src/um-account-dialog.c | 35 ++++++++++++++++++++++-------------
1 files changed, 22 insertions(+), 13 deletions(-)
---
diff --git a/src/um-account-dialog.c b/src/um-account-dialog.c
index 53fcfb6..93be534 100644
--- a/src/um-account-dialog.c
+++ b/src/um-account-dialog.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <pwd.h>
+#include <utmp.h>
#include <glib.h>
#include <glib/gi18n.h>
@@ -33,6 +34,8 @@
#include "um-user-manager.h"
#include "um-utils.h"
+#define MAXNAMELEN (UT_NAMESIZE - 1)
+
struct _UmAccountDialog {
GtkWidget *dialog;
GtkWidget *shortname_combo;
@@ -135,6 +138,7 @@ shortname_changed (GtkComboBox *combo,
gboolean in_use;
gboolean empty;
gboolean valid;
+ gboolean toolong;
const gchar *shortname;
const gchar *c;
gchar *tip;
@@ -143,38 +147,43 @@ shortname_changed (GtkComboBox *combo,
shortname = gtk_combo_box_get_active_text (combo);
in_use = is_shortname_used (shortname);
- empty = strlen (shortname) == 0;
+ empty = shortname[0] == 0;
+ toolong = strlen (shortname) > MAXNAMELEN;
valid = TRUE;
- if (!in_use && !empty) {
+ if (!in_use && !empty && !toolong) {
/* First char must be a letter, and it must only composed
* of ASCII letters, digits, and a '.', '-', '_'
*/
for (c = shortname; *c; c++) {
- if ((c == shortname && !g_ascii_islower (*c)) ||
- !(g_ascii_isdigit (*c) || g_ascii_islower (*c) ||
- *c == '.' || *c == '-' || *c == '_' )) {
- valid = FALSE;
- }
+ if (! ((*c >= 'a' && *c <= 'z') ||
+ (*c >= 'A' && *c <= 'Z') ||
+ (*c >= '0' && *c <= '9') ||
+ (*c == '_') || (*c == '.') ||
+ (*c == '-' && c != shortname)))
+ valid = FALSE;
}
}
- um->valid_shortname = !empty && !in_use && valid;
+ um->valid_shortname = !empty && !in_use && !toolong && valid;
gtk_widget_set_sensitive (um->ok_button, um->valid_name && um->valid_shortname);
entry = gtk_bin_get_child (GTK_BIN (combo));
- if (!empty && (in_use || !valid)) {
+ if (!empty && (in_use || toolong || !valid)) {
if (in_use) {
- tip = g_strdup_printf (_("A user with the short name '%s' already exists."),
+ tip = g_strdup_printf (_("A user with the short name '%s' already exists"),
shortname);
}
- else if (!g_ascii_islower (shortname[0])) {
- tip = g_strdup (_("The short name must start with a lowercase letter."));
+ else if (toolong) {
+ tip = g_strdup_printf (_("The short name is too long"));
+ }
+ else if (shortname[0] == '-') {
+ tip = g_strdup (_("The short name cannot start with a '-'"));
}
else {
tip = g_strdup (_("The short name must consist of:\n"
- " \xe2\x9e\xa3 lowercase letters from the English alphabet\n"
+ " \xe2\x9e\xa3 letters from the English alphabet\n"
" \xe2\x9e\xa3 digits\n"
" \xe2\x9e\xa3 any of the characters '.', '-' and '_'"));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]