home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
idutil
/
pwinf.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-12
|
3KB
|
108 lines
#include <stdio.h>
#include <memory.h>
#include <pwd.h>
#include "pwinf.h"
static char *RCSid="$Header: pwinf.c,v 1.1 91/10/28 10:38:25 dtb Exp $";
int pwinf_info_fpr (fp)
FILE * fp;
{
int nout = 0;
nout += fprintf (fp, "%s %s\n", __FILE__, PWINF_RCSid);
return (nout);
}
/*
pwinfrq_set_dflt
Puts default values in pwinfrq structure.
A pointer to the structure is passed as an argument.
If a NULL pointer is used as an argument, then memory will
be allocated and a pointer to the new structure returned.
If a NULL pointer is returned, memory could not be allocated.
*/
struct pwinfrq * pwinfrq_set_dflt ( p)
struct pwinfrq * p;
{
if (p == NULL)
p = (struct pwinfrq *) malloc ( sizeof (struct pwinfrq) ) ;
if (p != NULL) {
(void) memset (p, 0, sizeof (struct pwinfrq) );
p->dlm = PWINFRQ_DLM_DFLT ;
}
return (p);
}
int pwinf_fpr ( fp, pwd, pwinf)
FILE * fp;
struct passwd * pwd;
struct pwinfrq * pwinf;
{
int nout = 0; /* Number of bytes output */
int dreq = 0; /* Is delimiter required */
if (pwinf->nam) {
if (pwinf->vbs)
nout += fprintf (fp, "usrname=");
nout += fprintf (fp, "%s", pwd->pw_name);
dreq = 1;
}
if (pwinf->epw) {
if (dreq)
nout += fprintf (fp, "%c", pwinf->dlm);
if (pwinf->vbs)
nout += fprintf (fp, "pass=");
nout += fprintf (fp, "%s", pwd->pw_passwd);
}
if (pwinf->uid) {
if (dreq)
nout += fprintf (fp, "%c", pwinf->dlm);
if (pwinf->vbs)
nout += fprintf (fp, "uid=");
nout += fprintf (fp, "%d", pwd->pw_uid);
}
if (pwinf->gid) {
if (dreq)
nout += fprintf (fp, "%c", pwinf->dlm);
if (pwinf->vbs)
nout += fprintf (fp, "gid=");
nout += fprintf (fp, "%d", pwd->pw_gid);
}
/*
if (pwinf->age) {
if (dreq)
nout += fprintf (fp, "%c", pwinf->dlm);
if (pwinf->vbs)
nout += fprintf (fp, "age=");
nout += fprintf (fp, "%s", pwd->pw_age);
}
*/
if (pwinf->cmt) {
if (dreq)
nout += fprintf (fp, "%c", pwinf->dlm);
if (pwinf->vbs)
nout += fprintf (fp, "comment=");
nout += fprintf (fp, "%s", pwd->pw_comment);
}
if (pwinf->dir) {
if (dreq)
nout += fprintf (fp, "%c", pwinf->dlm);
if (pwinf->vbs)
nout += fprintf (fp, "home_dir=");
nout += fprintf (fp, "%s", pwd->pw_dir);
}
if (pwinf->shl) {
if (dreq)
nout += fprintf (fp, "%c", pwinf->dlm);
if (pwinf->vbs)
nout += fprintf (fp, "shell=");
nout += fprintf (fp, "%s", pwd->pw_shell);
}
if ( pwinf->nam | pwinf->epw | pwinf->uid | pwinf->gid | pwinf->age
| pwinf->cmt | pwinf->dir | pwinf->shl )
nout += fprintf (fp, "\n");
return (nout);
}