[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[firstboot] Get UID_MIN from /etc/login.defs (#717113)
- From: Martin Gracik <mgracik redhat com>
- To: anaconda-devel-list redhat com
- Subject: [firstboot] Get UID_MIN from /etc/login.defs (#717113)
- Date: Tue, 28 Jun 2011 13:21:34 +0200
Get the UID_MIN value from /etc/login.defs and use it to
determine proper user id number, instead of hardcoded 500.
Use 500 if the /etc/login.defs parsing fails.
---
modules/create_user.py | 28 +++++++++++++++++++++++++++-
1 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/modules/create_user.py b/modules/create_user.py
index a5e1f78..7e87dd6 100644
--- a/modules/create_user.py
+++ b/modules/create_user.py
@@ -23,6 +23,7 @@ import os, string, sys, time
import os.path
import pwd
import unicodedata
+import re
from firstboot.config import *
from firstboot.constants import *
@@ -134,7 +135,32 @@ class moduleClass(Module):
user = self.admin.lookupUserByName(username)
- if user != None and user.get(libuser.UIDNUMBER)[0] < 500:
+ # get UID_MIN from /etc/login.defs
+ __ld_line = re.compile(r'^[ \t]*' # Initial whitespace
+ r'([^ \t]+)' # Variable name
+ r'[ \t][ \t"]*' # Separator - yes, may have multiple "s
+ r'(([^"]*)".*' # Value, case 1 - terminated by "
+ r'|([^"]*\S)?\s*' # Value, case 2 - only drop trailing \s
+ r')$')
+
+ res = {}
+ with open('/etc/login.defs') as f:
+ for line in f:
+ match = __ld_line.match(line)
+ if match is not None:
+ name = match.group(1)
+ if name.startswith('#'):
+ continue
+ value = match.group(3)
+ if value is None:
+ value = match.group(4)
+ if value is None:
+ value = ''
+ res[name] = value # Override previous definition
+
+ uid_min = res.get('UID_MIN', 500)
+
+ if user != None and user.get(libuser.UIDNUMBER)[0] < uid_min:
self._showErrorMessage(_("The username '%s' is a reserved system "
"account. Please specify another username."
% username))
--
1.7.3.2
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]