home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
2
/
2286
/
dialup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-28
|
2KB
|
122 lines
/*
* Copyright 1989, 1990, John F. Haugh II
* All rights reserved.
*
* Use, duplication, and disclosure prohibited without
* the express written permission of the author.
*/
#include <stdio.h>
#ifndef BSD
#include <string.h>
#else
#include <strings.h>
#define strchr index
#define strrchr rindex
#endif
#include "dialup.h"
#ifndef lint
static char _sccsid[] = "@(#)dialup.c 2.2 19:23:38 7/29/90";
#endif
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 && buf[0] == '#')
;
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);
if (strcmp (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) {
if (buf[0] == '#')
continue;
buf[strlen (buf) - 1] = '\0';
if (strcmp (buf, tty) == 0) {
dialup = 1;
break;
}
}
fclose (fp);
return (dialup);
}