Subject: A small patch for authmgr

From: "MONIER Jean-Christophe (EURIWARE S.A.)" <[email-masked]>
Date: Tue, 5 Sep 2000 13:10:23 +0200

Hello all,

I've writting a small patch to extand syntax of the 'login' command of the
authmgr software.
This patch allow you to use login in 3 differents methods :

- original : enter "login" and authmgr prompt you for Username: and
Password:
or
- enter "login <username>" and authmgr prompt you only for Password:
or 
- enter "login <username> <user's password>" and authmgr prompt nothing

The last method allow you to login into authmgr from a script like a perl
program for example.
I use this 3th in a perl script that allow me to put new users from a
flat-text file.

Here is the patch

----------- CUT HERE ------------------------------

--- /usr/src/fwtk/auth/authmgr.c	Tue Sep  5 13:04:34 2000
+++ authmgr.c	Tue Sep  5 11:35:06 2000
@@ -45,7 +45,7 @@
  static	Cmd	*find_command();
 
  static Cmd ctab[] = {
-"login",	FLG_LOCAL,	"login",			do_login,
+"login",	FLG_LOCAL,	"login [username [password]]",
do_login,
  "adduser",	0,	"adduser username [longname]",		0,
  "deluser",	0,		"deluser username",		0,
  "display",	FLG_LOCAL,	"display username",
do_multiline,
@@ -203,6 +203,12 @@
  	char		*p;
 
  	logged_in = 0;
+	if(ac > 2) {
+		strncpy(usrbuf,av[1], 512);
+		usrbuf[511] = '\0';
+		strncpy(pbuf,av[2], 512);
+		rbuf[511] = '\0';
+	} else {
  	if(ac > 1) {
  		strncpy(usrbuf,av[1], 512);
  		usrbuf[511] = '\0';
@@ -212,6 +218,7 @@
  		if(fgets(usrbuf,sizeof(usrbuf),stdin) == (char *)0)
  			do_quit();
  	}
+	}
  	sprintf(rbuf,"authorize %s",usrbuf);
  	if(auth_send(rbuf))
  		lostconn();
@@ -238,9 +245,17 @@
  		if(!strncmp(rbuf,"chalnecho ",10)) {
  			p = getpassword(&rbuf[10]);
  		} else
-		if(!strncmp(rbuf,"password",8)) {
-			p = getpassword("Password: ");
-		} else {
+		if (ac <= 2) {
+			if(!strncmp(rbuf,"password",8)) {
+				p = getpassword("Password: ");
+			}
+		}
+		else
+		if  (ac > 2) {
+			p = pbuf;
+		}
+		else
+		{
  			fprintf(stderr,"%s\n",rbuf);
  			return(1);
  		}

----------- CUT HERE ------------------------------

Here is the perl script I use :

----------- CUT HERE ------------------------------
#!/usr/bin/perl5
#USAGE: authadd.pl [ userfile ]
# userfile is : userid \t groupid \t password \t longname
$DATABASE = @ARGV[0];
$AUTHSRV="/usr/local/etc/authmgr";

open(IN, "$DATABASE");
open(OUT, "| $AUTHSRV");
# Authenticate with a SUPER-WIZ user
print OUT "login adminuser adminpwd\n";

# Add users from userfile (one user per line)
while (<IN>) {
   $_ =~  s/[\r\n]//g;
   ($uid, $group, $PASSWORD, @longnameparts) = split(/[ \t]/, $_);
   $longname = "\"" . join(" ", @longnameparts) . "\"";
    print OUT "adduser $uid $longname\n";
    print OUT "group $uid $group\n";
    print OUT "password $uid $PASSWORD\n";
    print OUT "enable $uid\n";
    print OUT "display $uid\n";
}
print OUT "quit\n";

----------- CUT HERE ------------------------------

I include this 2 files to this mail too.

I put this 2 codes in public domain for FWTK user's.

Comments are welcome.

Hope this help somebody ...

Regards,

  <<authadd.pl>>  <<authmgr.patch>> 
PS : Please, excuse my 'poor' english language.

Jean-Christophe MONIER
EURIWARE S.A. - France
Responsable de la Cellule Sécurité des Systèmes d'Informations
ASSI  - Région SQY