Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 May 1998 16:43:41 +0800 (SGT)
From:      chas <panda@peace.com.my>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   Modifying calls to getpwnam() to use an external file
Message-ID:  <3.0.32.19980529170547.00959a70@peace.com.my>

next in thread | raw e-mail | index | archive | help
Sorry for troubling you all with a question that reveals
my ignorance of C (I make no pretenses otherwise) but
I have to put a FreeBSD machine live tomorrow morning and 
there is one part of the system that still needs customising :

I'm trying to get Cyrus IMAPd to use a different shadow
password file. Since it seems to be using getpwnam(),
I have been trying this :

1. In the Cyrus source code, replace all calls to getpwnam() 
   with my own function  fgetpwnam("/etc/master.passwd.cyrus", arg)
2. Add '#include "fgetpwnam.h"' to files that will use fgetpwnam()
3. Write fgetpwnam.h - yep, that's the bit that's making me
   regret the day I put K&R down. Anyway, based on boilerplate
   Stevens and much help from a linux guy.

fgetpwnam.h is :
----------------
/* error msg */
char *pwerrmsg;

/* main function */
struct passwd *fgetpwnam(char *fn,char *name);


and fgetpwnam.c is :
--------------------
#include <sys/types.h>
#include <pwd.h>
#include <stddef.h>
#include <string.h>
 
struct passwd *getpwnam(char *fn ,char *name) {
	FILE *f;
	f=fopen(fn,"r");
 	if(!f){
  		pwerrmsg="Cannot open file.";
  		return NULL;
  	}
	while(p=fgetpwent(f)!=NULL){
  		if(strcmp(name, p->pw_name) == 0)
   			break;
 	}
 	fclose(f);
 
	if(!p){
  		pwerrmsg="User not found.";
 	} 
	else {
  		pwerrmsg="Ok.";
 	}
 
 	return p;
}

But yes, now this means rewriting fgetpwent() to take
a file name argument instead of void :-(
And now I'm getting lost.

So, is there an easy way to do this ? I had hoped it 
would be something as simple as changing pwd.h since
global directories seem to be in there but it seems
that getpwnam() and getpwent() are hardcoded to the 
standard files. 

Certain that the ability to use an alternative password
file is something that others have desired long before
now, has anyone got a simple A,B,C on the steps ?

Then again, if I've missed the obvious : the bottomline
really is "how do I get any program to authenticate against
/etc/master.passwd.alternative instead of /etc/master.passwd ?
Creation of the alternative shadow files is not a problem.

Thank you very much,

chas


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3.0.32.19980529170547.00959a70>