FreeBSD/libexec/talkd/process.c
/*
 * Search utmp for the local user
 */
Search utmp for the local user
Search utmp for the local user
int
find_user(const char *name, char *tty)
{
	struct utmpx *ut;
	int status;
	struct stat statb;
	time_t best = 0;
	char ftty[sizeof(_PATH_DEV) - 1 + sizeof(ut->ut_line)];
	setutxent();
	status = NOT_HERE;
	(void) strcpy(ftty, _PATH_DEV);
	while ((ut = getutxent()) != NULL)
		if (ut->ut_type == USER_PROCESS &&
		    strcmp(ut->ut_user, name) == 0) {
			if (*tty == '\0' || best != 0) {
				if (best == 0)
					status = PERMISSION_DENIED;
				(void) strcpy(ftty + sizeof(_PATH_DEV) - 1,
				    ut->ut_line);
				if (stat(ftty, &statb) == 0) {
					if (!(statb.st_mode & 020))
						continue;
					if (statb.st_atime > best) {
						best = statb.st_atime;
						(void) strcpy(tty, ut->ut_line);
						status = SUCCESS;
						continue;
					}
				}
			}
			if (strcmp(ut->ut_line, tty) == 0) {
				status = SUCCESS;
				break;
			}
		}
	endutxent();
	return (status);
}
int find_user ( const char * name , char * tty ) { struct utmpx * ut ; int status ; struct stat statb ; time_t best = 0 ; char ftty [ sizeof ( _PATH_DEV ) - 1 + sizeof ( ut -> ut_line ) ] ; setutxent ( ) ; status = NOT_HERE ; ( void ) strcpy ( ftty , _PATH_DEV ) ; while ( ( ut = getutxent ( ) ) != NULL ) if ( ut -> ut_type == USER_PROCESS && strcmp ( ut -> ut_user , name ) == 0 ) { if ( * tty == ' \0 ' || best != 0 ) { if ( best == 0 ) status = PERMISSION_DENIED ; ( void ) strcpy ( ftty + sizeof ( _PATH_DEV ) - 1 , ut -> ut_line ) ; if ( stat ( ftty , & statb ) == 0 ) { if ( ! ( statb . st_mode & 020 ) ) continue ; if ( statb . st_atime > best ) { best = statb . st_atime ; ( void ) strcpy ( tty , ut -> ut_line ) ; status = SUCCESS ; continue ; } } } if ( strcmp ( ut -> ut_line , tty ) == 0 ) { status = SUCCESS ; break ; } } endutxent ( ) ; return ( status ) ; }
Search utmp for the local user
Search utmp for the local user
/* no particular tty was requested */