1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

Latest updates from author.

(This used to be commit bdf0d66577)
This commit is contained in:
John Terpstra 2002-11-20 00:30:56 +00:00
parent a32ffdd1ab
commit 69f3c8f304
2 changed files with 44 additions and 47 deletions

View File

@ -1,4 +1,4 @@
ntlogon.py v0.7b Copyright 2000 by Avalon Technology Group, Inc. ntlogon.py v0.8b Copyright 2002 by Timothy (rhacer) Grant
This programme is released under the terms of the GNU Public License This programme is released under the terms of the GNU Public License
This programme has NO WARRANTY of any kind, use at your own risk. This programme has NO WARRANTY of any kind, use at your own risk.
@ -42,7 +42,7 @@ I'd really love to know if even one person other than me and the other techs
here at Avalon have found it useful. here at Avalon have found it useful.
Thanks. Thanks.
rhacer (rhacer@exceptionalminds.com) rhacer (rhacer@craigelachie.org)
September 27, 2000 September 27, 2000
Thanks to those that did respond to my plea! I'd still love to hear from Thanks to those that did respond to my plea! I'd still love to hear from
@ -150,11 +150,10 @@ Nick Lopez <kimo_sabe@atdot.org> for the net bios name patch.
=================== ===================
CONTACT INFORMATION CONTACT INFORMATION
=================== ===================
Author : Timothy Grant (rhacer) Author : Timothy (rhacer) Grant
Company : Avalon Technology Group, Inc.
I can be reached at tjg@exceptionalminds.com I can be reached at tjg@craigelachie.org
ntlogon website www.exceptionalminds.com/rhacer/ntlogon ntlogon website www.craigelachie.org/rhacer/ntlogon
Please feel free to contact me with any suggestions, improvements, bugs you Please feel free to contact me with any suggestions, improvements, bugs you
might find. might find.

View File

@ -1,13 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
ntlogon.py written by Timothy Grant ntlogon.py written by Timothy (rhacer) Grant
Copyright 1999 by Avalon Technology Group, Inc. Copyright 1999 - 2002 by Timothy Grant
This programme is copyright 1999 by Avalon Technology Group, Inc. it
is distributed under the terms of the GNU Public License. is distributed under the terms of the GNU Public License.
The format for the configuration file is as follows: The format for the configuration file is as follows:
While there is some room for confusion, we attempt to process things in While there is some room for confusion, we attempt to process things in
@ -17,7 +15,7 @@ sense.
# Everything in the Global section applies to all users logging on to the # Everything in the Global section applies to all users logging on to the
# network # network
[Global [Global]
@ECHO "Welcome to our network!!!" @ECHO "Welcome to our network!!!"
NET TIME \\\\servername /SET /YES NET TIME \\\\servername /SET /YES
NET USE F: \\\\servername\\globalshare /YES NET USE F: \\\\servername\\globalshare /YES
@ -85,11 +83,11 @@ def buildScript(buf, sections, group, user, ostype, machine, debug, pause):
and creating a list object that contains each line contained in each and creating a list object that contains each line contained in each
included section. The list object is then returned to the calling included section. The list object is then returned to the calling
routine. routine.
All comments (#) are removed. A REM is inserted to show All comments (#) are removed. A REM is inserted to show
which section of the configuration file each line comes from. which section of the configuration file each line comes from.
We leave blanklines as they are sometimes useful for debugging We leave blanklines as they are sometimes useful for debugging
We also replace all of the Samba macros (e.g., %U, %G, %a, %m) with their We also replace all of the Samba macros (e.g., %U, %G, %a, %m) with their
expanded versions which have been passed to us by smbd expanded versions which have been passed to us by smbd
""" """
@ -109,18 +107,18 @@ def buildScript(buf, sections, group, user, ostype, machine, debug, pause):
'a': ostype, 'a': ostype,
'm': machine 'm': machine
} }
# #
# Process each section defined in the list sections # Process each section defined in the list sections
# #
for s in sections: for s in sections:
# print 'searching for: ' + s # print 'searching for: ' + s
idx = 0 idx = 0
while idx < len(buf): while idx < len(buf):
ln = buf[idx] ln = buf[idx]
# #
# We need to set up a regex for each possible section we # We need to set up a regex for each possible section we
# know about. This is slightly complicated due to the fact # know about. This is slightly complicated due to the fact
@ -143,29 +141,29 @@ def buildScript(buf, sections, group, user, ostype, machine, debug, pause):
if re.search(r'(?i)' + hdrstring, ln): if re.search(r'(?i)' + hdrstring, ln):
idx = idx + 1 # increment the counter to move to the next idx = idx + 1 # increment the counter to move to the next
# line. # line.
x = re.match(r'([^#\r\n]*)', ln) # Determine the section x = re.match(r'([^#\r\n]*)', ln) # Determine the section
# name and strip out CR/LF # name and strip out CR/LF
# and comment information # and comment information
if debug: if debug:
print 'rem ' + x.group(1) + ' commands' print 'rem ' + x.group(1) + ' commands'
else: else:
# create the rem at the beginning of each section of the # create the rem at the beginning of each section of the
# logon script. # logon script.
script.append('rem ' + x.group(1) + ' commands') script.append('rem ' + x.group(1) + ' commands')
# #
# process each line until we have found another section # process each line until we have found another section
# header # header
# #
while not re.search(r'.*\[.*\].*', buf[idx]): while not re.search(r'.*\[.*\].*', buf[idx]):
# #
# strip comments and line endings # strip comments and line endings
# #
x = re.match(r'([^#\r\n]*)', buf[idx]) x = re.match(r'([^#\r\n]*)', buf[idx])
if string.strip(x.group(1)) != '' : if string.strip(x.group(1)) != '' :
# if there is still content after stripping comments and # if there is still content after stripping comments and
# line endings then this is a line to process # line endings then this is a line to process
@ -184,18 +182,18 @@ def buildScript(buf, sections, group, user, ostype, machine, debug, pause):
if varname == '': if varname == '':
print "Error: No substition name specified line: %d" % idx print "Error: No substition name specified line: %d" % idx
sys.exit(1) sys.exit(1)
if varsub == '': if varsub == '':
print "Error: No substitution text provided line: %d" % idx print "Error: No substitution text provided line: %d" % idx
sys.exit(1) sys.exit(1)
if macros.has_key(varname): if macros.has_key(varname):
print "Warning: macro %s redefined line: %d" % (varname, idx) print "Warning: macro %s redefined line: %d" % (varname, idx)
macros[varname] = varsub macros[varname] = varsub
idx = idx + 1 idx = idx + 1
continue continue
# #
# Replace all the macros that we currently # Replace all the macros that we currently
# know about. # know about.
@ -209,31 +207,31 @@ def buildScript(buf, sections, group, user, ostype, machine, debug, pause):
for varname in macros.keys(): for varname in macros.keys():
line = re.sub(r'%' + varname + r'(\W)', line = re.sub(r'%' + varname + r'(\W)',
macros[varname] + r'\1', line) macros[varname] + r'\1', line)
if debug: if debug:
print line print line
if pause: if pause:
print 'pause' print 'pause'
else: else:
script.append(line) script.append(line)
idx = idx + 1 idx = idx + 1
if idx == len(buf): if idx == len(buf):
break # if we have reached the end of the file break # if we have reached the end of the file
# stop processing. # stop processing.
idx = idx + 1 # increment the line counter idx = idx + 1 # increment the line counter
if debug: if debug:
print '' print ''
else: else:
script.append('') script.append('')
return script return script
# End buildScript() # End buildScript()
def run(): def run():
""" """
run() everything starts here. The main routine reads the command line run() everything starts here. The main routine reads the command line
@ -254,7 +252,7 @@ def run():
sections = ['Global', 'Machine', 'OS', 'Group', 'User'] # Currently supported sections = ['Global', 'Machine', 'OS', 'Group', 'User'] # Currently supported
# configuration file # configuration file
# sections # sections
options, args = getopt.getopt(sys.argv[1:], 'd:f:g:ho:u:m:v', options, args = getopt.getopt(sys.argv[1:], 'd:f:g:ho:u:m:v',
['templatefile=', ['templatefile=',
'group=', 'group=',
@ -266,7 +264,7 @@ def run():
'version', 'version',
'pause', 'pause',
'debug']) 'debug'])
# #
# Process the command line arguments # Process the command line arguments
# #
@ -275,17 +273,17 @@ def run():
if (i[0] == '-f') or (i[0] == '--templatefile'): if (i[0] == '-f') or (i[0] == '--templatefile'):
configfile = i[1] configfile = i[1]
# print 'configfile = ' + configfile # print 'configfile = ' + configfile
# define the group to be used # define the group to be used
elif (i[0] == '-g') or (i[0] == '--group'): elif (i[0] == '-g') or (i[0] == '--group'):
group = i[1] group = i[1]
# print 'group = ' + group # print 'group = ' + group
# define the os type # define the os type
elif (i[0] == '-o') or (i[0] == '--os'): elif (i[0] == '-o') or (i[0] == '--os'):
ostype = i[1] ostype = i[1]
# print 'os = ' + os # print 'os = ' + os
# define the user # define the user
elif (i[0] == '-u') or (i[0] == '--user'): elif (i[0] == '-u') or (i[0] == '--user'):
user = i[1] user = i[1]
@ -295,7 +293,7 @@ def run():
# define the machine # define the machine
elif (i[0] == '-m') or (i[0] == '--machine'): elif (i[0] == '-m') or (i[0] == '--machine'):
machine = i[1] machine = i[1]
# define the netlogon directory # define the netlogon directory
elif (i[0] == '-d') or (i[0] == '--dir'): elif (i[0] == '-d') or (i[0] == '--dir'):
outdir = i[1] outdir = i[1]
@ -310,7 +308,7 @@ def run():
elif (i[0] == '--pause'): elif (i[0] == '--pause'):
pause = 1 pause = 1
# print 'pause = ' + pause # print 'pause = ' + pause
# if we are asked for the version number, print it. # if we are asked for the version number, print it.
elif (i[0] == '-v') or (i[0] == '--version'): elif (i[0] == '-v') or (i[0] == '--version'):
print version print version
@ -329,8 +327,8 @@ def run():
except IOError: except IOError:
print 'Unable to open configuration file: ' + configfile print 'Unable to open configuration file: ' + configfile
sys.exit(1) sys.exit(1)
# #
# open the output file # open the output file
# #
@ -340,9 +338,9 @@ def run():
except IOError: except IOError:
print 'Unable to open logon script file: ' + outdir + outfile print 'Unable to open logon script file: ' + outdir + outfile
sys.exit(1) sys.exit(1)
buf = iFile.readlines() # read in the entire configuration file buf = iFile.readlines() # read in the entire configuration file
# #
# call the script building routine # call the script building routine
# #
@ -355,11 +353,11 @@ def run():
for ln in script: for ln in script:
oFile.write(ln + '\r\n') oFile.write(ln + '\r\n')
if pause: if pause:
if string.strip(ln) != '': # Because whitespace is if string.strip(ln) != '': # Because whitespace
oFile.write('pause' + '\r\n') # is a useful tool, we oFile.write('pause' + '\r\n') # is a useful tool, we
# don't put pauses after # don't put pauses after
# an empty line. # an empty line.
# End run() # End run()
@ -372,7 +370,7 @@ else:
print "Module ntlogon.py imported." print "Module ntlogon.py imported."
print "To run, type: ntlogon.run()" print "To run, type: ntlogon.run()"
print "To reload after changes to the source, type: reload(ntlogon)" print "To reload after changes to the source, type: reload(ntlogon)"
# #
# End NTLogon.py # End NTLogon.py
# #