1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

move score files to home directory and drop setgid. from Ricardo Mestre

This commit is contained in:
tedu 2015-11-24 02:51:50 +00:00
parent b64d8bbd6b
commit 7e0a668373
6 changed files with 33 additions and 116 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.8 2002/05/31 03:46:35 pjanzen Exp $
# $OpenBSD: Makefile,v 1.9 2015/11/24 02:51:50 tedu Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
PROG= canfield
@ -6,15 +6,6 @@ MAN= canfield.6
DPADD= ${LIBCURSES}
LDADD= -lcurses
MLINKS= canfield.6 cfscores.6
BINMODE=2555
beforeinstall:
@if [ ! -f ${DESTDIR}/var/games/cfscores ]; then \
${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 664 \
/dev/null ${DESTDIR}/var/games/cfscores ; \
else \
true ; \
fi
.include "../../Makefile.inc"
.include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: canfield.6,v 1.9 2014/09/26 21:41:56 schwarze Exp $
.\" $OpenBSD: canfield.6,v 1.10 2015/11/24 02:51:50 tedu Exp $
.\" $NetBSD: canfield.6,v 1.4 1995/03/21 15:08:30 cgd Exp $
.\"
.\" Copyright (c) 1983, 1993
@ -30,7 +30,7 @@
.\"
.\" @(#)canfield.6 8.1 (Berkeley) 5/31/93
.\"
.Dd $Mdocdate: September 26 2014 $
.Dd $Mdocdate: November 24 2015 $
.Dt CANFIELD 6
.Os
.Sh NAME
@ -40,8 +40,6 @@
.Sh SYNOPSIS
.Nm canfield
.Nm cfscores
.Op Fl a
.Op Ar username
.Sh DESCRIPTION
If you have never played solitaire before, it is recommended
that you consult a solitaire instruction book.
@ -101,23 +99,14 @@ that became visible since it was last turned on.
Thus the maximum cost of information is $34.
Playing time is charged at a rate of $1 per minute.
.Pp
With no arguments, the program
The program
.Nm cfscores
prints out the current status of your canfield account.
If a
.Ar username
is specified,
it prints out the status of that user's canfield account.
If the
.Fl a
flag is specified,
it prints out the canfield accounts for all users that have
played the game since the database was set up.
.Sh FILES
.Bl -tag -width /usr/games/cfscores -compact
.It Pa /usr/games/cfscores
the score database printer
.It Pa /var/games/cfscores
.It Pa $HOME/cfscores
the database of scores
.El
.Sh AUTHORS

View File

@ -1,4 +1,4 @@
/* $OpenBSD: canfield.c,v 1.15 2015/11/05 23:16:44 tedu Exp $ */
/* $OpenBSD: canfield.c,v 1.16 2015/11/24 02:51:50 tedu Exp $ */
/* $NetBSD: canfield.c,v 1.7 1995/05/13 07:28:35 jtc Exp $ */
/*
@ -46,6 +46,7 @@
#include <ctype.h>
#include <curses.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
@ -53,8 +54,6 @@
#include <time.h>
#include <unistd.h>
#include "pathnames.h"
#define decksize 52
#define originrow 0
#define origincol 0
@ -154,7 +153,6 @@ bool mtfdone, Cflag = FALSE;
#define BETTINGBOX 2
#define NOBOX 3
int status = INSTRUCTIONBOX;
int uid;
/*
* Basic betting costs
@ -1379,7 +1377,7 @@ suspend(void)
move(21, 0);
refresh();
if (dbfd != -1) {
lseek(dbfd, uid * sizeof(struct betinfo), SEEK_SET);
lseek(dbfd, sizeof(struct betinfo), SEEK_SET);
write(dbfd, (char *)&total, sizeof(total));
}
kill(getpid(), SIGTSTP);
@ -1626,17 +1624,18 @@ void
initall(void)
{
int i;
char scorepath[PATH_MAX];
time(&acctstart);
initdeck(deck);
uid = getuid();
if (uid < 0)
uid = 0;
dbfd = open(_PATH_SCORE, O_RDWR);
setegid(getgid());
if (!getenv("HOME"))
return;
snprintf(scorepath, sizeof(scorepath), "%s/%s", getenv("HOME"),
"cfscores");
dbfd = open(scorepath, O_RDWR | O_CREAT, 0644);
if (dbfd < 0)
return;
i = lseek(dbfd, uid * sizeof(struct betinfo), SEEK_SET);
i = lseek(dbfd, sizeof(struct betinfo), SEEK_SET);
if (i < 0) {
close(dbfd);
dbfd = -1;
@ -1699,7 +1698,7 @@ cleanup(int dummy)
status = NOBOX;
updatebettinginfo();
if (dbfd != -1) {
lseek(dbfd, uid * sizeof(struct betinfo), SEEK_SET);
lseek(dbfd, sizeof(struct betinfo), SEEK_SET);
write(dbfd, (char *)&total, sizeof(total));
close(dbfd);
}
@ -1744,10 +1743,6 @@ main(int argc, char *argv[])
noecho();
initall();
/* revoke privs */
gid = getgid();
setresgid(gid, gid, gid);
instruct();
makeboard();
for (;;) {

View File

@ -1,36 +0,0 @@
/* $OpenBSD: pathnames.h,v 1.3 2003/06/03 03:01:39 millert Exp $ */
/* $NetBSD: pathnames.h,v 1.3 1995/03/21 15:08:34 cgd Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)pathnames.h 8.1 (Berkeley) 5/31/93
*/
#define _PATH_SCORE "/var/games/cfscores"

View File

@ -1,10 +1,9 @@
# $OpenBSD: Makefile,v 1.4 2002/05/31 03:46:35 pjanzen Exp $
# $OpenBSD: Makefile,v 1.5 2015/11/24 02:51:50 tedu Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
PROG= cfscores
CFLAGS+=-I${.CURDIR}/../canfield
NOMAN= noman
BINMODE=2555
.include "../../Makefile.inc"
.include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: cfscores.c,v 1.15 2009/10/27 23:59:24 deraadt Exp $ */
/* $OpenBSD: cfscores.c,v 1.16 2015/11/24 02:51:50 tedu Exp $ */
/* $NetBSD: cfscores.c,v 1.3 1995/03/21 15:08:37 cgd Exp $ */
/*
@ -33,12 +33,12 @@
#include <sys/types.h>
#include <err.h>
#include <fcntl.h>
#include <limits.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "pathnames.h"
struct betinfo {
long hand; /* cost of dealing hand */
@ -52,6 +52,7 @@ struct betinfo {
};
int dbfd;
char scorepath[PATH_MAX];
void printuser(const struct passwd *, int);
@ -60,41 +61,19 @@ main(int argc, char *argv[])
{
struct passwd *pw;
uid_t uid;
gid_t gid;
if (argc > 2) {
fprintf(stderr, "usage: cfscores [-a] [username]\n");
exit(1);
}
dbfd = open(_PATH_SCORE, O_RDONLY);
if (!getenv("HOME"))
return;
snprintf(scorepath, sizeof(scorepath), "%s/%s", getenv("HOME"),
"cfscores");
dbfd = open(scorepath, O_RDONLY);
if (dbfd < 0)
err(2, "%s", _PATH_SCORE);
/* revoke privs */
gid = getgid();
setresgid(gid, gid, gid);
err(2, "%s", scorepath);
setpwent();
if (argc == 1) {
uid = getuid();
pw = getpwuid(uid);
if (pw == 0) {
printf("You are not listed in the password file?!?\n");
exit(2);
}
printuser(pw, 1);
exit(0);
}
if (strcmp(argv[1], "-a") == 0) {
while ((pw = getpwent()) != 0)
printuser(pw, 0);
exit(0);
}
pw = getpwnam(argv[1]);
if (pw == 0) {
printf("User %s unknown\n", argv[1]);
exit(3);
}
uid = getuid();
pw = getpwuid(uid);
printuser(pw, 1);
exit(0);
}
@ -112,14 +91,14 @@ printuser(const struct passwd *pw, int printfail)
printf("Bad uid %u\n", pw->pw_uid);
return;
}
i = lseek(dbfd, pw->pw_uid * sizeof(struct betinfo), SEEK_SET);
i = lseek(dbfd, sizeof(struct betinfo), SEEK_SET);
if (i < 0) {
warn("lseek %s", _PATH_SCORE);
warn("lseek %s", scorepath);
return;
}
i = read(dbfd, (char *)&total, sizeof(total));
if (i < 0) {
warn("lseek %s", _PATH_SCORE);
warn("lseek %s", scorepath);
return;
}
if (i == 0 || total.hand == 0) {