Epiphanic Networks' Wikka : AthemeGeneratePass

Home :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Atheme Password Generation Script


Last edited by KogAdmin:
notes
Thu, 06 Oct 2005 04:03 PDT [diff]


Here's the work I did to create the Atheme command "GENERATEPASS" for UserServ, call it a tutorial in terms of making an Atheme module. I was using the SVN current from the main trunk (Atheme 0.3beta3 [20051003-2531] #16 version tells me).

This file is also available on Atheme's Wiki

General overview
1 - Create the command for the service (.c file)
2 - Add it to the makefile.in
3 - Create a help file
4 - Edit help.c in the atheme-current/src directory to include the hook for your help file
5 - Edit your atheme.conf and add a loadmodule
6 - recompile, re-run
7 - notes

NOTE: remember to run ./configure after updating makefile.in!
 


Of course, you can always use opserv's modload command, but you won't get the help for it until you follow all of the above steps. If doing so, you can feel free to "make generatepass.so" to compile the shared object, move it into the appropriate directory and call modload in opserv.

1 - Creation of generatepass.c
in atheme-current/modules/userserv I created a file called generatepass.c. If you're using NickServ you should put it in the appropriate folder.

/*
 * Copyright (c) 2005 Greg Feigenson
 * Rights to this code are as documented in doc/LICENSE.
 *
 * Generates a new password, either n digits long (w/ userserv arg), or 7 digits
 *
 * $Id:$
 */


#include "atheme.h"

DECLARE_MODULE_V1
(
    "userserv/generatepass", FALSE, _modinit, _moddeinit,
    "$Id:$",
    "Epiphanic Networks <http://www.epiphanic.org>"
);

static void us_cmd_generatepass(char *origin);

command_t us_generatepass = { "GENERATEPASS", "Generates a random password.",
                        AC_NONE, us_cmd_generatepass };
                                                                                  
list_t *us_cmdtree;
list_t *us_helptree;

void _modinit(module_t *m)
{
    us_cmdtree = module_locate_symbol("userserv/main", "us_cmdtree");
    command_add(&us_generatepass, us_cmdtree);
    us_helptree = module_locate_symbol("userserv/main", "us_helptree");
    help_addentry(us_helptree, "GENERATEPASS", "help/userserv/generatepass", NULL);
   
    /* You'll need to create a helpfile and put in help/userserv */
}

void _moddeinit()
{
    command_delete(&us_generatepass, us_cmdtree);
    help_delentry(us_helptree, "GENERATEPASS");
}

static void us_cmd_generatepass(char *origin)
{
    int n;
    char *newpass = strtok(NULL, " ");
   
    if (newpass)
        n = atoi(newpass);
   
    if (!n)
        n = 7;

    newpass = gen_pw(n);

    notice(usersvs.nick, origin, "Randomly generated password: %s",newpass);
    free(newpass);
}


2 - Makefile addition
This is so we will know to build the module (and make generatepass.so) and do our magic on it when we make && make install.

You're going to want to edit your Makefile.in (and re-run ./configure), or also edit your Makefile (as it's generated by autoconfigure). You'll notice there's a definition for base_srcs that contains a bunch of .c files. Add generatepass in there, add a tab and a \ if it's not the last entry (that's a character that tells it ignore linebreak).

An example BASE_SRCS:
BASE_SRCS = 		\
	main.c		\
	drop.c		\
	generatepass.c	\
	freeze.c	\
	help.c		\
	hold.c		\
	info.c		\
	list.c		\
	listmail.c	\
	login.c		\
	logout.c	\
	mark.c		\
	myaccess.c	\
	register.c	\
	sendpass.c	\
	resetpass.c	\
	set.c		\
	status.c	\
	taxonomy.c	\
	verify.c


3 - The Help File
in atheme-current/help/userserv I created a file with the following contents:
Help for GENERATEPASS:

GENERATEPASS generates a random password for
use with &nick& accounts (or anywhere else
you'd need a password). Optionally you
can pass it a length parameter to specify the
length of the password

Syntax: GENERATEPASS <length>

Example:
	/msg &nick& GENERATEPASS
	/msg &nick& GENERATEPASS 6


Which will be read literally to the user. The squares up top are a control character, telling Atheme to use bold text

4 - help.c Hookin
Is no longer necessary! There's now a list_t called us_helptree that contains all help hookins, and you can see we add ourselves as a node to it. Thank you nenolod et al.

5 - Editing atheme.conf
Ok, if you can't do this you're in some serious trouble... Scroll down to a section where there's a bunch of statements that look like:
loadmodule "modules/userserv/generatepass";

and add that one...

6 - Recompilation
Another one of those steps you should know... If you're not just rebuilding the module (modunload/make generatepass.conf/modload), you should make && make install, then run the binary. For debugging I usually screen it and then run -dn (debug, don't fork/stay in fg)

I hope that was clear, and accurate... my Wiki was offline while doing this, so I'm writing from memory. Also, my C skills aren't the greatest, but I'm pretty sure the code I built is, given the framework, quite clean. I'm going to be working on some memoserv stuff next, so there'll be a more substantial bit (including how to make a brand new service agent).

7 - Notes
You can find source for both userserv and nickserv in /contrib. I believe I tested the boundary case where someone gives generatepass an alpha char, but my results looked like I had a bad compile... Please add a comment if this is not the case.


CategoryAtheme

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.3
Page was generated in 0.0963 seconds