home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume6
/
shadow-2.pt3
/
dialup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-03
|
2KB
|
99 lines
#include <stdio.h>
#include <string.h>
#include "dialup.h"
static FILE *dialpwd;
void setduent ()
{
if (dialpwd)
rewind (dialpwd);
else
dialpwd = fopen (DIALPWD, "r");
}
void endduent ()
{
if (dialpwd)
fclose (dialpwd);
dialpwd = (FILE *) 0;
}
struct dialup *getduent ()
{
static struct dialup dialup; /* static structure to point to */
static char shell[64]; /* some space for a login shell */
static char passwd[16]; /* some space for dialup password */
char buf[BUFSIZ];
char *cp;
if (! dialpwd)
setduent ();
if (! dialpwd || feof (dialpwd))
return ((struct dialup *) 0);
while (fgets (buf, BUFSIZ, dialpwd) == buf)
if (buf[0] == '#')
continue;
if (feof (dialpwd))
return ((struct dialup *) 0);
cp = strchr (buf, ':');
if (cp - buf > sizeof shell) /* something is fishy ... */
return ((struct dialup *) 0);
(void) strncpy (shell, buf, cp - buf);
shell[cp - buf] = '\0';
if (strlen (cp + 1) > sizeof passwd) /* something is REALLY fishy */
return ((struct dialup *) 0);
(void) strcpy (passwd, cp + 1);
passwd[strlen (passwd) - 1] = '\0';
if (cp = strchr (passwd, ':'))
*cp = '\0';
dialup.du_shell = shell;
dialup.du_passwd = passwd;
return (&dialup);
}
struct dialup *getdushell (shell)
char *shell;
{
struct dialup *dialup;
while (dialup = getduent ())
if (strcmp (shell, dialup->du_shell) == 0)
return (dialup);
return ((struct dialup *) 0);
}
int isadialup (tty)
char *tty;
{
FILE *fp;
char buf[BUFSIZ];
int dialup = 0;
if (! (fp = fopen (DIALUPS, "r")))
return (0);
while (fgets (buf, BUFSIZ, fp) == buf) {
buf[strlen (buf) - 1] = '\0';
if (strcmp (buf, tty) == 0) {
dialup = 1;
break;
}
}
fclose (fp);
return (dialup);
}