[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

iauth modules anyone?



I'm currently trying to write a passwd module for iauth.

I can get the code to compile, but I can't get it to run.

I'm attaching the following items to this message:

 * the source to the authentication module
 * the makefile used to make it
 * the iauth.conf file that calls it
 * the errors generated by iauth
 * the output of 'nm -u /usr/etc/mod_passwd.so'

If anyone here has ever written one, I'd really appreciate some
hints.  This is turning out to be a pain in the butt. :-)

Jack.
-- 
Jack Twilley
jmt at tbe dot net
http colon slash slash www dot tbe dot net slash tilde jmt slash
/* mod_passwd.c - authentication module */

/* includes */
#include "os.h"
#include "a_defines.h"
#include "a_externs.h"

/* defines */
#define USERLENP1 (USERLEN+1) /* max username length plus one */
#define PASSWDLENP1 (PASSWDLEN+1) /* max password length plus one*/

/* structs */
struct passwd_entry {
  char *username;
  char *password;
  struct passwd_entry *next;
};

struct passwd_data {
  struct passwd_entry *entry;
  u_int ok, tried, baduser, badpass, nopass;
};

/* constants */

/* globals */

/* passwd_init - called when module loaded */
char *
passwd_init(self)
     AnInstance *self;
{
  FILE *stream;
  int i, eof, rc;
  char *from, *to;
  char username[USERLENP1], password[PASSWDLENP1];
  struct passwd_data *ptr = self->data;
  struct passwd_entry *ent;

  if (self->opt == NULL)
    return "Aie! no option(s): nothing to be done!";
  if (strncasecmp(self->opt, "file=", 5))
    return "Aie! unknown option(s): nothing to be done!";
  self->popt = self->opt + 5;

  /* open the file */
  if ((stream = fopen(self->popt, "r")) == NULL)
    return "Aie! can't open file!";

  /* if can, create and populate a passwd_data structure */
  if ((ptr = malloc(sizeof(struct passwd_data))) == NULL)
    return "Aie! can't malloc space!";

  for (i = 1, eof = 0, ent = ptr->entry;
       eof == 0;
       i++, ent = ent->next) {
    rc = fscanf(stream, "%s %s\n", &username, &password);
    if (rc == 0) {
      eof = 1;
    } else if (rc == 1) {
      eof = 1;
    } else if (rc == 2) {
      if ((ent = malloc(sizeof(struct passwd_entry))) == NULL)
	return "Aie! can't malloc space!";
      ent->username = strdup(username);
      ent->password = strdup(password);
    }
  }
  /* end the list and close the file*/
  ent->next = NULL;
  fclose(stream);

  /* exit cleanly */
  return NULL;
}

/* passwd_release - called when module is unloaded */
void
passwd_release(self)
     AnInstance *self;
{
  struct passwd_data *ptr = self->data;
  struct passwd_entry *ent, *nextent;

  for (ent = ptr->entry; ent == NULL; ent = nextent) {
    nextent = ent->next;
    free(ent);
  }
  free(ptr);
  free(self->popt);
}

/* passwd_stats - sends stats to server */
void
passwd_stats(self)
     AnInstance *self;
{
  struct passwd_data *ptr = self->data;

  sendto_ircd("S passwd ok %u tried %u baduser %u badpass %u nopass %u",
  	      ptr->ok, ptr->tried, ptr->baduser, ptr->badpass, ptr->nopass);
}

/* passwd_start - starts authentication */
int
passwd_start(cl)
     u_int cl;
{
  struct passwd_entry *ent;
  struct passwd_data *ptr = cldata[cl].instance->data;
  char *from, *to;

  /* no username means still waiting */
  if ((cldata[cl].state & A_GOTU) == 0) {
    (ptr->tried)++;
    return 1;
  }
  
  /* no password means rejected user */
  if ((cldata[cl].state & A_GOTP) == 0) {
    cldata[cl].state |= A_DENY;
    sendto_ircd("K %d %s %u", cl, cldata[cl].itsip, cldata[cl].itsport);
    (ptr->nopass)++;
    return -1;
  }

  /* got username and password */
  for (ent = ptr->entry; ent != NULL; ent = ent->next) {
    if (strcmp(ent->username, cldata[cl].user) == 0) {
      /* username matches */
      if (strcmp(ent->password, cldata[cl].passwd) == 0) {
	/* password matches */
	cldata[cl].state |= A_UNIX;
	if (cldata[cl].authuser)
	  free(cldata[cl].authuser);
	cldata[cl].authuser = strdup(cldata[cl].user);
	cldata[cl].authfrom = cldata[cl].instance->in;
  	sendto_ircd("U %d %s %u %s", cl, cldata[cl].itsip, cldata[cl].itsport, 
  		    cldata[cl].authuser);
	(ptr->ok)++;
      } else {
	/* password does not match */
	cldata[cl].state |= A_DENY;
  	sendto_ircd("K %d %s %u", cl, cldata[cl].itsip, cldata[cl].itsport);
	(ptr->badpass)++;
      }
    }
  }
  if (ent == NULL) {
    /* username not found */
    cldata[cl].state |= A_DENY;
    sendto_ircd("K %d %s %u", cl, cldata[cl].itsip, cldata[cl].itsport);
    (ptr->baduser)++;
  }
  return -1;
}

/* passwd_work - when there's work to do */
int
passwd_work(cl)
     u_int cl;
{
  return -1;
}

/* passwd_clean - called at interrupts */
void
passwd_clean(cl)
     u_int cl;
{
}

/* passwd_timeout - called in timeout situations */
int
passwd_timeout(cl)
     u_int cl;
{
  return 0;
}

static aModule Module_passwd =
{ "passwd", passwd_init, passwd_release, passwd_stats,
  passwd_start, passwd_work, passwd_timeout, passwd_clean };

aModule *
passwd_load()
{
  return &Module_passwd;
}

# makefile for mod test

all:	mod_passwd.so

mod_passwd.so:	mod_passwd.c
	cd ../../i586-pc-linux-gnu && gcc -c -g -I../iauth -I../common -I. ../contrib/mod_passwd/mod_passwd.c && ld -Bshareable mod_passwd.o -o mod_passwd.so && cp mod_passwd.so ../contrib/mod_passwd/mod_passwd.so

mod_mytest.so:	mod_mytest.c
	cd ../../i586-pc-linux-gnu && gcc -c -g -I../iauth -I../common -I. ../contrib/mod_passwd/mod_mytest.c && ld -Bshareable mod_mytest.o -o mod_mytest.so && cp mod_mytest.so ../contrib/mod_passwd/mod_mytest.so

clean:
	rm -rf *.so *~
notimeout
required
extinfo

shared passwd /usr/etc/mod_passwd.so
module passwd
        file=/usr/etc/iauth.passwd
Script started on Mon May  1 10:15:52 2000
[root@duchess /root]# /usr/sbin/iauth -c /usr/etc/iauth.conf
iauth 2.10.3 (with DSM support)

Reading "/usr/etc/iauth.conf"

line 5: /usr/etc/mod_passwd.so: undefined symbol: myncmp
line 6: Unknown module name.
line 7: Ignoring unexpected property.
Segmentation fault (core dumped)
[root@duchess /root]# exit
exit

Script done on Mon May  1 10:16:07 2000
Script started on Mon May  1 10:16:30 2000
[root@duchess /root]# nm -u /usr/etc/mod_passwd.so
cldata
fclose
fopen
free
fscanf
malloc
myncmp
sendto_ircd
strcmp
strdup
[root@duchess /root]# exit
Script done on Mon May  1 10:16:40 2000