Bug 6294 - Provided ntlogon script does only recognize primary user group
Provided ntlogon script does only recognize primary user group
Status: NEW
Product: Samba 3.2
Classification: Unclassified
Component: Client tools
3.2.5
All Linux
: P3 enhancement
: ---
Assigned To: Guenther Deschner
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-04-27 10:33 UTC by Markus Kuhnla
Modified: 2009-06-18 10:55 UTC (History)
0 users

See Also:


Attachments
Patch for ntlogon python script (3.52 KB, patch)
2009-06-18 10:55 UTC, Markus Kuhnla
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Kuhnla 2009-04-27 10:33:38 UTC
Hello Samba developers,

i found the ntlogon script very useful but had some difficulties to get it working in a way one expects.

There are "Group" sections available in the config file and one expects, that the script recognizes the groups a user belongs to and includes the appropriate sections. But the python script does only include the group-section for the primary user-group which is handed over with the "-g" argument. So I changed the script and in my version it recognizes all the groups the user belongs to. This way, the "-g" option is somewhat obsolete.

I woould like to suggest to include this version in the main distribution.

Kind regards

Markus

Here is the patch:
--- ntlogon.orig	2009-04-24 13:30:40.000000000 +0200
+++ ntlogon	2009-04-27 17:28:01.000000000 +0200
@@ -50,8 +50,7 @@
 
 # End configuration file
 
-usage: ntlogon [-g | --group=groupname] 
-               [-u | --user=username]
+usage: ntlogon [-u | --user=username]
                [-o | --os=osname]
                [-m | --machine=netbiosname]
                [-f | --templatefile=filename]
@@ -72,10 +71,24 @@
 import re
 import string
 import os
+import grp
 
-version = "ntlogon.py v0.8"
+version = "ntlogon.py v0.9"
 
-def buildScript(buf, sections, group, user, ostype, machine, debug, pause):
+def findusergroups(user):
+    """
+    Iterate through the group-database and find all groups the
+    user is a member of.
+    The list of groups is returned as a list.
+    """
+    groups=[]
+    for name,pwd,gid,members in grp.getgrall():
+        if user in members:
+            groups.append(name)
+    return groups
+
+
+def buildScript(buf, sections, user, ostype, machine, debug, pause):
     """
     buildScript() Takes the contents of the template file and builds
     a DOS batch file to be executed as an NT logon script. It does this
@@ -103,7 +116,6 @@
     # 
     macros = {
         		'U': user,
-                'G': group,
                 'a': ostype,
                 'm': machine
              }
@@ -111,6 +123,14 @@
     #
     # Process each section defined in the list sections
     #
+    if len(user) > 0:
+	grouplist=findusergroups(user)
+        groupre=r'('
+        for nextgroup in grouplist:
+            groupre=groupre+r'('+nextgroup+r')' + r'||'
+            
+        groupre=groupre[:-2] + r')' #remove the last '||'
+
     for s in sections:
         # print 'searching for: ' + s
 
@@ -127,7 +147,7 @@
             if s == 'Global':
                 hdrstring = '\[ *' + s + ' *\]'
             elif s == 'Group':
-                hdrstring = '\[ *' + s + ' *- *' + group + ' *\]'
+                hdrstring = '\[ *' + s + ' *- *' + groupre + ' *\]'
             elif s == 'User':
                 hdrstring = '\[ *' + s + ' *- *' + user + ' *\]'
             elif s == 'OS':
@@ -221,7 +241,8 @@
                         break   # if we have reached the end of the file
                                 # stop processing.
 
-            idx = idx + 1   # increment the line counter
+            else:
+                idx = idx + 1   # increment the line counter
 
         if debug:
             print ''
@@ -253,9 +274,8 @@
                                                     # configuration file 
                                                     # sections
 
-    options, args = getopt.getopt(sys.argv[1:], 'd:f:g:ho:u:m:v', 
+    options, args = getopt.getopt(sys.argv[1:], 'd:f:ho:u:m:v', 
                                  ['templatefile=', 
-                                  'group=',
                                   'help',
                                   'os=',
                                   'user=',
@@ -274,10 +294,6 @@
             configfile = i[1]
             # print 'configfile = ' + configfile
 
-        # define the group to be used
-        elif (i[0] == '-g') or (i[0] == '--group'):
-            group = i[1]
-            # print 'group = ' + group
 
         # define the os type
         elif (i[0] == '-o') or (i[0] == '--os'):
@@ -344,7 +360,7 @@
     #
     # call the script building routine
     #
-    script = buildScript(buf, sections, group, user, ostype, machine, debug, pause)
+    script = buildScript(buf, sections, user, ostype, machine, debug, pause)
 
     #
     # write out the script file
Comment 1 Guenther Deschner 2009-06-18 10:35:32 UTC
Markus, can you please upload that patch as an attachment ?
Comment 2 Markus Kuhnla 2009-06-18 10:55:09 UTC
Created attachment 4308 [details]
Patch for ntlogon python script

Sorry for not attaching the patch.