Index | Thread | Search

From:
Daniel Dickman <didickman@gmail.com>
Subject:
Re: switch tacacs+ to python3
To:
Jan Vlach <janus@volny.cz>, ports@openbsd.org
Date:
Mon, 19 Feb 2024 10:21:47 -0500

Download raw body.

Thread

On Mon, 19 Feb 2024, Jeremie Courreges-Anglas wrote:

> On Sat, Feb 17 2024, Daniel Dickman <didickman@gmail.com> wrote:
> > Hello Jan, ports@,
> >
> > Please see below for a small update so tacacs+ doesn't need python2.
> >
> > It also looks like python2 is not needed at build time, but only at run 
> > time.
> >
> > ok to commit the diff below?
> 
> do_auth.py isn't ready for python3, if you really want to move this to
> python3 I would suggest using 2to3 -w in eg post-extract (and thus keep
> current MODPY_BUILDDEP).
> 

Indeed I botched the diff I sent out. I had run do_auth.py through 2to3 
and made a patch that should have been part of the original diff.

The reason I made a patch instead of running 2to3 dynamically is because 
it is only 1 file and more changes might be needed in do_auth.py to adapt 
to future python updates in the future.

ok on this revised version?

Index: Makefile
===================================================================
RCS file: /cvs/ports/net/tacacs+/Makefile,v
diff -u -p -u -r1.25 Makefile
--- Makefile	27 Sep 2023 14:18:34 -0000	1.25
+++ Makefile	19 Feb 2024 15:14:54 -0000
@@ -4,7 +4,7 @@ V =		4.0.4.28
 DISTNAME =	tacacs-F${V}
 PKGNAME =	tacacs+-${V}
 EPOCH =		0
-REVISION =	1
+REVISION =	2
 
 SHARED_LIBS +=  tacacs                    1.0
 
@@ -20,7 +20,9 @@ WANTLIB += c pthread
 SITES =		ftp://ftp.shrubbery.net/pub/tac_plus/
 
 MODULES =	lang/python
-MODPY_VERSION =	${MODPY_DEFAULT_VERSION_2}
+
+MODPY_BUILDDEP =	No
+
 MODPY_ADJ_FILES = do_auth.py
 
 BUILD_DEPENDS =	devel/bison
Index: patches/patch-do_auth_py
===================================================================
RCS file: patches/patch-do_auth_py
diff -N patches/patch-do_auth_py
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-do_auth_py	19 Feb 2024 15:14:54 -0000
@@ -0,0 +1,101 @@
+converted to python3 via 2to3
+
+Index: do_auth.py
+--- do_auth.py.orig
++++ do_auth.py
+@@ -211,7 +211,7 @@ General Public License for more details.
+ Written by Dan Schmidt - Please visit tacacs.org to check for updates.
+ '''
+ 
+-import sys,re,getopt,ConfigParser
++import sys,re,getopt,configparser
+ from time import strftime
+ 
+ # I really don't want to deal with these exceptions more than once
+@@ -230,23 +230,23 @@ def get_attribute(config, the_section, the_option, log
+     #Should not have any exceptions - BUT, just in case
+     try:
+         attributes = config.get(the_section, the_option)
+-    except ConfigParser.NoSectionError:
++    except configparser.NoSectionError:
+         log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+                 + "Error: Section '%s' Doesn't Exist!\n" 
+                 % (the_section))
+         sys.exit(1)
+-    except ConfigParser.DuplicateSectionError:
++    except configparser.DuplicateSectionError:
+         log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+                 + "Error: Duplicate section '%s'\n" 
+                 % (the_section))
+         sys.exit(1)
+-    except ConfigParser.NoOptionError:
++    except configparser.NoOptionError:
+         log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+                     + "Error: '%s' not found in section '%s\n'" 
+                      % (the_option, the_section))
+         sys.exit(1)
+     #To do: finish exceptions. 
+-    except ConfigParser.ParsingError:
++    except configparser.ParsingError:
+         log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+                 + "Error: Can't parse file '%s'! (You got me)\n" 
+              % (filename))
+@@ -298,9 +298,9 @@ def main():
+     argv = sys.argv
+     try:
+         optlist, args = getopt.getopt(sys.argv[1:], 'i:u:f:l:d:?:D', ['fix_crs_bug','?', '-?', 'help', 'Help'])
+-    except getopt.GetoptError, err:
+-        print str(err) 
+-        print __doc__
++    except getopt.GetoptError as err:
++        print(str(err)) 
++        print(__doc__)
+         sys.exit(1)
+     for (i, j) in optlist:
+         if i == '-i':
+@@ -314,15 +314,15 @@ def main():
+         elif i == '-d':
+             device = j
+         elif i in ('?', '-?', 'help', 'Help'):
+-            print __doc__
++            print(__doc__)
+             sys.exit(1)
+         elif i == '-D':
+             is_debug = True
+         else:
+-            print 'Unknown option:', i
++            print('Unknown option:', i)
+             sys.exit(1)
+     if len(argv) < 7:
+-        print __doc__
++        print(__doc__)
+         sys.exit(1)
+     log_file = open (log_name, "a")
+ #DEBUG!  We at least got CALLED
+@@ -384,7 +384,7 @@ def main():
+         log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+                 + "Error: No username entered!\n")
+         sys.exit(1)
+-    config = ConfigParser.SafeConfigParser()
++    config = configparser.SafeConfigParser()
+     if not (filename in config.read(filename)):
+         log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+                 + "Error: Can't open/parse '%s'\n" 
+@@ -491,7 +491,7 @@ def main():
+                     for item in return_pairs:
+                         #DEBUG
+                         # log_file.write("Returning:%s\n" % item.strip())
+-                        print item.strip('\n')
++                        print(item.strip('\n'))
+                     if want_tac_pairs:
+                         #DEBUG
+                         # log_file.write("Exiting status 2\n")
+@@ -507,7 +507,7 @@ def main():
+             for item in return_pairs:
+                 #DEBUG
+                 # log_file.write("Returning:%s\n" % item.strip())
+-                print item.strip('\n')
++                print(item.strip('\n'))
+             log_file.write(strftime("%Y-%m-%d %H:%M:%S: ")
+                  + "User '%s' granted access to device '%s' in group '%s' from '%s'\n"
+                  % (user_name, device, this_group, ip_addr))
Index: pkg/PLIST
===================================================================
RCS file: /cvs/ports/net/tacacs+/pkg/PLIST,v
diff -u -p -u -r1.12 PLIST
--- pkg/PLIST	8 Nov 2022 11:17:02 -0000	1.12
+++ pkg/PLIST	19 Feb 2024 15:14:54 -0000
@@ -3,7 +3,7 @@
 @extraunexec rm -f /var/log/tac_plus/*
 @rcscript ${RCDIR}/tac_plus
 include/tacacs.h
-lib/libtacacs.a
+@static-lib lib/libtacacs.a
 lib/libtacacs.la
 @lib lib/libtacacs.so.${LIBtacacs_VERSION}
 @man man/man5/tac_plus.conf.5