home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
comm
/
mail
/
smail
/
src
/
rcs
/
pw.c,v
< prev
next >
Wrap
Text File
|
1993-12-21
|
7KB
|
425 lines
head 1.4;
access;
symbols
C_1:1.4;
locks; strict;
comment @ * @;
1.4
date 93.10.31.20.09.32; author Aussem; state Exp;
branches;
next 1.3;
1.3
date 93.10.30.21.44.37; author Aussem; state Exp;
branches;
next 1.2;
1.2
date 93.09.18.16.47.47; author Aussem; state Exp;
branches;
next 1.1;
1.1
date 93.09.08.16.27.13; author Aussem; state Exp;
branches;
next ;
desc
@passwd routines
@
1.4
log
@HAVE_GETPWENT insert for passwd routines without getpwent()
@
text
@/*
* pw.c
*
* Routines for the passwd
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: pw.c,v $
* Revision 1.3 1993/10/30 21:44:37 Aussem
* cosmetics changes
*
* Revision 1.2 1993/09/18 16:47:47 Aussem
* insert GNU license text in the header
*
* Revision 1.1 1993/09/08 16:27:13 Aussem
* Initial revision
*
*
*/
static char *rcsid="$Id: pw.c,v 1.3 1993/10/30 21:44:37 Aussem Exp Aussem $";
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include "defs.h"
#ifdef HAVE_GETPWENT
struct pw_node {
char *lname; /* login name */
char *fname; /* full name */
int uid; /* user-id */
char *home; /* login name */
pwlist *vlink; /* link to next item */
};
pwlist *pwhead; /* head of linked list */
pwlist *pwparse(); /* head of linked list */
#define PNULL ((pwlist *) 0)
char *
pwfnam(user)
char *user;
{
pwlist *f;
/*
** check for previously cached user
*/
for(f=pwhead; f != NULL; f=f->vlink) {
if(strcmp(user, f->lname) == 0) {
return(f->fname);
}
}
/*
** not found parse the password file
*/
while((f=pwparse()) != PNULL) {
if(strcmp(user, f->lname) == 0) {
return(f->fname);
}
}
return(NULL);
}
char *
pwuid(uid)
int uid;
{
pwlist *f;
/*
** check for previously cached user
*/
for(f=pwhead; f != NULL; f=f->vlink) {
if(uid == f->uid) {
return(f->lname);
}
}
/*
** not found parse the password file
*/
while((f=pwparse()) != PNULL) {
if(uid == f->uid) {
return(f->lname);
}
}
return(NULL);
}
char *
tilde(user)
char *user;
{
pwlist *f;
/*
** check for previously cached user
*/
for(f=pwhead; f != NULL; f=f->vlink) {
if(strcmp(user, f->lname) == 0) {
return(f->home);
}
}
/*
** not found parse the password file
*/
while((f=pwparse()) != PNULL) {
if(strcmp(user, f->lname) == 0) {
return(f->home);
}
}
return(NULL);
}
char *
fullname(gecos)
char *gecos;
{
static char fname[SMLBUF];
register char *cend;
(void) strcpy(fname, gecos);
if (cend = index(fname, ','))
*cend = '\0';
if (cend = index(fname, '('))
*cend = '\0';
/*
** Skip USG-style 0000-Name nonsense if necessary.
*/
if (isdigit(*(cend = fname))) {
if ((cend = index(fname, '-')) != NULL)
cend++;
else
/*
** There was no `-' following digits.
*/
cend = fname;
}
return (cend);
}
pwlist *
pwparse()
{
pwlist *f;
char *p, *name;
struct passwd *pwent, *getpwent();
unsigned int i;
static int pw_eof = 0;
if((pw_eof == 1)
|| ((pwent = getpwent()) == (struct passwd *) NULL)) {
pw_eof = 1;
return(PNULL);
}
/*
** Get an entry from the password file.
** Parse relevant strings.
*/
f = (pwlist *) malloc(sizeof(pwlist));
if(f == PNULL) return(PNULL);
f->vlink = pwhead;
pwhead = f;
f->uid = pwent->pw_uid;
i=strlen(pwent->pw_name)+1;
p = malloc(i);
if(p == NULL) return(PNULL);
f->lname = strcpy(p, pwent->pw_name);
i=strlen(pwent->pw_dir)+1;
p = malloc(i);
if(p == NULL) return(PNULL);
f->home = strcpy(p, pwent->pw_dir);
name = fullname(pwent->pw_gecos);
i=strlen(name)+1;
p = malloc(i);
if(p == NULL) return(PNULL);
f->fname = strcpy(p, name);
return(f);
}
#else /* !HAVE_GETPWENT */
struct passwd *getpwuid(int);
char *
pwfnam(user)
char *user;
{
struct passwd *pwd;
pwd=getpwnam(user);
if(!pwd)
return(NULL);
else
return(pwd->pw_name);
}
char *
pwuid(uid)
int uid;
{
struct passwd *pwd;
pwd=getpwuid(uid);
if(!pwd)
return(NULL);
else
return(pwd->pw_name);
}
char *
tilde(user)
char *user;
{
struct passwd *pwd;
pwd=getpwnam(user);
if(!pwd)
return(NULL);
else
return(pwd->pw_dir);
}
#endif /* HAVE_GETPWENT */
#ifdef FULLNAME
/*
** Resolve a full name to a login name.
** Not too much smarts here.
*/
char *
res_fname(user)
register char *user;
{
long pos, middle, hi, lo;
static long pathlength = 0;
register char *s;
int c;
static FILE *file;
int flag;
char namebuf[SMLBUF], *path;
extern enum edebug debug;
extern char *fnlist;
DEBUG("res_fname: looking for '%s'\n", user);
if(pathlength == 0) { /* open file on first use */
if((file=fopen(fnlist, "r")) == NULL) {
DEBUG( "can't access %s.\n", fnlist);
pathlength = -1;
} else {
(void) fseek(file, 0L, 2); /* find length */
pathlength = ftell(file);
}
}
if(pathlength == -1 ) return(NULL);
lo = 0;
hi = pathlength;
path = namebuf;
(void) strcpy( path, user );
(void) strcat( path, "\t" );
for( ;; ) {
pos = middle = ( hi+lo+1 )/2;
(void) fseek( file, pos, 0 ); /* find midpoint */
if (pos != 0) /* to beginning of next line */
while( ( c=getc( file ) ) != EOF && c != '\n' );
for( flag = 0, s = path; flag == 0; s++ ) { /* match??? */
if ( *s == '\0' ) {
goto solved;
}
c = getc( file );
flag = lower( c ) - lower( *s );
}
if (lo >= middle) /* failure? */
return(NULL);
if(c != EOF && flag < 0) /* close window */
lo = middle;
else
hi = middle - 1;
}
/*
** Now just copy the result.
*/
solved:
while(((c = getc(file)) != EOF) && (c != '\t') && (c != '\n')) {
*path++ = c;
}
if(path == namebuf) { /* NULL alias field */
return(NULL);
}
*path = '\0';
if((path = malloc((unsigned) strlen(namebuf)+1)) == NULL) {
return(NULL); /* sorry, no memory */
}
(void) strcpy(path, namebuf);
return(path);
}
#endif /* FULLNAME */
@
1.3
log
@cosmetics changes
@
text
@d21 3
d33 1
a33 1
static char *rcsid="$Id: pw.c,v 1.2 1993/09/18 16:47:47 Aussem Exp Aussem $";
d42 1
d206 44
@
1.2
log
@insert GNU license text in the header
@
text
@d21 3
d30 1
a30 1
static char *rcsid="$Id: pw.c,v 1.1 1993/09/08 16:27:13 Aussem Exp Aussem $";
a105 1
#ifndef SENDMAIL
a131 1
#endif /* not SENDMAIL */
@
1.1
log
@Initial revision
@
text
@d2 1
a2 1
* pw.c
d4 1
a4 1
* Routines for the passwd
d6 4
a9 1
* $Log$
d11 14
d27 1
a27 1
static char *rcsid="$Id$";
@