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
1 1
#	@(#)Makefile	8.1 (Berkeley) 6/4/93
2 2
# $FreeBSD: src/libexec/talkd/Makefile,v 1.6.2.2 2001/10/18 12:30:42 des Exp $
3 3

  
4
.PATH:  ${.CURDIR}/../../usr.bin/wall ${.CURDIR}/../../usr.bin/who
4
.PATH:  ${.CURDIR}/../../usr.bin/wall
5 5

  
6 6
PROG=	ntalkd
7
SRCS=	talkd.c announce.c process.c table.c print.c ttymsg.c utmpentry.c
7
SRCS=	talkd.c announce.c process.c table.c print.c ttymsg.c
8 8
MAN=	talkd.8
9 9

  
10 10
DPADD=	${LIBUTIL}
11 11
LDADD=	-lutil
12 12

  
13 13
CFLAGS+=-I${.CURDIR}/../../usr.bin/wall
14
CFLAGS+=-I${.CURDIR}/../../usr.bin/who
15 14

  
16 15
.include <bsd.prog.mk>
libexec/talkd/extern.h
30 30
void	do_announce(CTL_MSG *, CTL_RESPONSE *);
31 31
CTL_MSG	*find_match(CTL_MSG *request);
32 32
CTL_MSG	*find_request(CTL_MSG *request);
33
int	find_user(const char *name, char *tty);
33
int	find_user(const char *name, char *tty, size_t ttylen);
34 34
void	insert_table(CTL_MSG *, CTL_RESPONSE *);
35 35
int	new_id(void);
36 36
int	print_mesg(const char *, CTL_MSG *, const char *);
libexec/talkd/process.c
50 50
#include <stdio.h>
51 51
#include <string.h>
52 52
#include <syslog.h>
53
#include "utmpentry.h"
53
#include <utmpx.h>
54 54

  
55 55
#include "extern.h"
56 56

  
......
140 140
	int result;
141 141

  
142 142
	/* see if the user is logged */
143
	result = find_user(mp->r_name, mp->r_tty);
143
	result = find_user(mp->r_name, mp->r_tty, sizeof(mp->r_tty));
144 144
	if (result != SUCCESS) {
145 145
		rp->answer = result;
146 146
		return;
......
177 177
 * Search utmpx for the local user
178 178
 */
179 179
int
180
find_user(const char *name, char *tty)
180
find_user(const char *name, char *tty, size_t ttylen)
181 181
{
182
	struct utmpentry *ep = NULL;	/* avoid gcc warnings */
182
	struct utmpx *ut;	/* avoid gcc warnings */
183 183
	int status;
184 184
	struct stat statb;
185
	time_t best = 0;
186
	char ftty[sizeof(_PATH_DEV) + sizeof(ep->line)];
185
	time_t best;
186
	char ftty[sizeof(_PATH_DEV) + _UTX_LINESIZE];
187 187

  
188
	getutentries(NULL, &ep);
188
	if (ttylen > sizeof(ftty))
189
		ttylen = sizeof(ftty);
189 190

  
190
#define SCMPN(a, b)	strncmp(a, b, sizeof (a))
191
	best = 0;
191 192
	status = NOT_HERE;
192
	(void) strcpy(ftty, _PATH_DEV);
193
	for (; ep; ep = ep->next)
194
		if (SCMPN(ep->name, name) == 0) {
195
			if (*tty == '\0' || best != 0) {
196
				if (best == 0)
197
					status = PERMISSION_DENIED;
198
				/* no particular tty was requested */
199
				(void) strcpy(ftty + sizeof(_PATH_DEV) - 1,
200
				    ep->line);
201
				if (stat(ftty, &statb) == 0) {
202
					if (!(statb.st_mode & 020))
203
						continue;
204
					if (statb.st_atime > best) {
205
						best = statb.st_atime;
206
						(void) strcpy(tty, ep->line);
207
						status = SUCCESS;
208
						continue;
209
					}
193
	strlcpy(ftty, _PATH_DEV, sizeof(ftty));
194
	setutxent();
195
	while ((ut = getutxent()) != NULL) {
196
		if (ut->ut_type != USER_PROCESS)
197
			continue;
198
		if (strncmp(ut->ut_name, name, sizeof(ut->ut_name)) != 0)
199
			continue;
200
		if (*tty == '\0' || best != 0) {
201
			if (best == 0)
202
				status = PERMISSION_DENIED;
203
			/* no particular tty was requested */
204
			strlcat(ftty, ut->ut_line, sizeof(ftty));
205
			if (stat(ftty, &statb) == 0) {
206
				if (!(statb.st_mode & 020))
207
					continue;
208
				if (statb.st_atime > best) {
209
					best = statb.st_atime;
210
					strlcpy(tty, ut->ut_line, ttylen);
211
					status = SUCCESS;
212
					continue;
210 213
				}
211 214
			}
212
			if (strcmp(ep->line, tty) == 0) {
213
				status = SUCCESS;
214
				break;
215
			}
216 215
		}
216
		if (strcmp(ut->ut_line, tty) == 0) {
217
			status = SUCCESS;
218
			break;
219
		}
220
	}
221
	endutxent();
217 222

  
218 223
	return (status);
219 224
}
    (1-1/1)