FreeBSD/usr.bin/login/login_fbtab.c
/* login_fbtab - apply protections specified in /etc/fbtab or logindevperm */
apply protections specified in /etc/fbtab or logindevperm
apply protections specified in / etc / fbtab or logindevperm
void
login_fbtab(char *tty, uid_t uid, gid_t gid)
{
    FILE   *fp;
    char    buf[BUFSIZ];
    char   *devname;
    char   *cp;
    int     prot;
    const char *table;
    if ((fp = fopen(table = _PATH_FBTAB, "r")) == NULL
    && (fp = fopen(table = _PATH_LOGINDEVPERM, "r")) == NULL)
	return;
    while (fgets(buf, sizeof(buf), fp)) {
	if ((cp = strchr(buf, '#')))
	    *cp = 0;				
	if ((cp = devname = strtok(buf, WSPACE)) == NULL)
	    continue;				
	if (strncmp(devname, _PATH_DEV, sizeof _PATH_DEV - 1) != 0
	       || (cp = strtok(NULL, WSPACE)) == NULL
	       || *cp != '0'
	       || sscanf(cp, "%o", &prot) == 0
	       || prot == 0
	       || (prot & 0777) != prot
	       || (cp = strtok(NULL, WSPACE)) == NULL) {
	    syslog(LOG_ERR, "%s: bad entry: %s", table, cp ? cp : "(null)");
	    continue;
	}
	if (strcmp(devname + 5, tty) == 0) {
	    for (cp = strtok(cp, ":"); cp; cp = strtok(NULL, ":")) {
		login_protect(table, cp, prot, uid, gid);
	    }
	}
    }
    fclose(fp);
}
void login_fbtab ( char * tty , uid_t uid , gid_t gid ) { FILE * fp ; char buf [ BUFSIZ ] ; char * devname ; char * cp ; int prot ; const char * table ; if ( ( fp = fopen ( table = _PATH_FBTAB , " " ) ) == NULL && ( fp = fopen ( table = _PATH_LOGINDEVPERM , " " ) ) == NULL ) return ; while ( fgets ( buf , sizeof ( buf ) , fp ) ) { if ( ( cp = strchr ( buf , ' ' ) ) ) * cp = 0 ; if ( ( cp = devname = strtok ( buf , WSPACE ) ) == NULL ) continue ; if ( strncmp ( devname , _PATH_DEV , sizeof _PATH_DEV - 1 ) != 0 || ( cp = strtok ( NULL , WSPACE ) ) == NULL || * cp != ' ' || sscanf ( cp , " " , & prot ) == 0 || prot == 0 || ( prot & 0777 ) != prot || ( cp = strtok ( NULL , WSPACE ) ) == NULL ) { syslog ( LOG_ERR , " " , table , cp ? cp : " " ) ; continue ; } if ( strcmp ( devname + 5 , tty ) == 0 ) { for ( cp = strtok ( cp , " " ) ; cp ; cp = strtok ( NULL , " " ) ) { login_protect ( table , cp , prot , uid , gid ) ; } } } fclose ( fp ) ; }
login_fbtab - apply protections specified in /etc/fbtab or logindevperm
login_fbtab - apply protections specified in / etc / fbtab or logindevperm
/* strip comment */ /* empty or comment */