Project

General

Profile

Submit #3261 ยป 0001-talkd-Find-users-in-more-than-one-talk-request.patch

dancrossnyc, 01/13/2021 04:02 PM

View differences:

libexec/talkd/Makefile
# @(#)Makefile 8.1 (Berkeley) 6/4/93
# $FreeBSD: src/libexec/talkd/Makefile,v 1.6.2.2 2001/10/18 12:30:42 des Exp $
.PATH: ${.CURDIR}/../../usr.bin/wall ${.CURDIR}/../../usr.bin/who
.PATH: ${.CURDIR}/../../usr.bin/wall
PROG= ntalkd
SRCS= talkd.c announce.c process.c table.c print.c ttymsg.c utmpentry.c
SRCS= talkd.c announce.c process.c table.c print.c ttymsg.c
MAN= talkd.8
DPADD= ${LIBUTIL}
LDADD= -lutil
CFLAGS+=-I${.CURDIR}/../../usr.bin/wall
CFLAGS+=-I${.CURDIR}/../../usr.bin/who
.include <bsd.prog.mk>
libexec/talkd/extern.h
void do_announce(CTL_MSG *, CTL_RESPONSE *);
CTL_MSG *find_match(CTL_MSG *request);
CTL_MSG *find_request(CTL_MSG *request);
int find_user(const char *name, char *tty);
int find_user(const char *name, char *tty, size_t ttylen);
void insert_table(CTL_MSG *, CTL_RESPONSE *);
int new_id(void);
int print_mesg(const char *, CTL_MSG *, const char *);
libexec/talkd/process.c
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include "utmpentry.h"
#include <utmpx.h>
#include "extern.h"
......
int result;
/* see if the user is logged */
result = find_user(mp->r_name, mp->r_tty);
result = find_user(mp->r_name, mp->r_tty, sizeof(mp->r_tty));
if (result != SUCCESS) {
rp->answer = result;
return;
......
* Search utmpx for the local user
*/
int
find_user(const char *name, char *tty)
find_user(const char *name, char *tty, size_t ttylen)
{
struct utmpentry *ep = NULL; /* avoid gcc warnings */
struct utmpx *ut; /* avoid gcc warnings */
int status;
struct stat statb;
time_t best = 0;
char ftty[sizeof(_PATH_DEV) + sizeof(ep->line)];
time_t best;
char ftty[sizeof(_PATH_DEV) + _UTX_LINESIZE];
getutentries(NULL, &ep);
if (ttylen > sizeof(ftty))
ttylen = sizeof(ftty);
#define SCMPN(a, b) strncmp(a, b, sizeof (a))
best = 0;
status = NOT_HERE;
(void) strcpy(ftty, _PATH_DEV);
for (; ep; ep = ep->next)
if (SCMPN(ep->name, name) == 0) {
if (*tty == '\0' || best != 0) {
if (best == 0)
status = PERMISSION_DENIED;
/* no particular tty was requested */
(void) strcpy(ftty + sizeof(_PATH_DEV) - 1,
ep->line);
if (stat(ftty, &statb) == 0) {
if (!(statb.st_mode & 020))
continue;
if (statb.st_atime > best) {
best = statb.st_atime;
(void) strcpy(tty, ep->line);
status = SUCCESS;
continue;
}
strlcpy(ftty, _PATH_DEV, sizeof(ftty));
setutxent();
while ((ut = getutxent()) != NULL) {
if (ut->ut_type != USER_PROCESS)
continue;
if (strncmp(ut->ut_name, name, sizeof(ut->ut_name)) != 0)
continue;
if (*tty == '\0' || best != 0) {
if (best == 0)
status = PERMISSION_DENIED;
/* no particular tty was requested */
strlcat(ftty, ut->ut_line, sizeof(ftty));
if (stat(ftty, &statb) == 0) {
if (!(statb.st_mode & 020))
continue;
if (statb.st_atime > best) {
best = statb.st_atime;
strlcpy(tty, ut->ut_line, ttylen);
status = SUCCESS;
continue;
}
}
if (strcmp(ep->line, tty) == 0) {
status = SUCCESS;
break;
}
}
if (strcmp(ut->ut_line, tty) == 0) {
status = SUCCESS;
break;
}
}
endutxent();
return (status);
}
    (1-1/1)