Mercurial > hg > early-roguelike
annotate arogue7/main.c @ 143:7faf4568c295
Advanced Rogue family: overhaul privilege handling.
Advanced Rogue 5 and 7, and XRogue, now open the scorefile and logfile
at startup and then drop any set[ug]id privileges if the savedir is not
being used.
author | John "Elwin" Edwards |
---|---|
date | Sat, 16 May 2015 13:39:26 -0400 |
parents | 796e2a10cd41 |
children | aac28331e71d |
rev | line source |
---|---|
125
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
1 /* |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
2 * main.c - setup code |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
3 * |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
4 * Advanced Rogue |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
5 * Copyright (C) 1984, 1985, 1986 Michael Morgan, Ken Dalka and AT&T |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
6 * All rights reserved. |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
7 * |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
8 * Based on "Rogue: Exploring the Dungeons of Doom" |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
10 * All rights reserved. |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
11 * |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
12 * See the file LICENSE.TXT for full copyright and licensing information. |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
13 */ |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
14 |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
15 #include "curses.h" |
126 | 16 #include <stdlib.h> |
17 #include <string.h> | |
125
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
18 #include <signal.h> |
143
7faf4568c295
Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents:
131
diff
changeset
|
19 #include <sys/types.h> |
7faf4568c295
Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents:
131
diff
changeset
|
20 #include <fcntl.h> |
125
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
21 #ifdef BSD |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
22 #include <sys/time.h> |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
23 #else |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
24 #include <time.h> |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
25 #endif |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
26 #include "mach_dep.h" |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
27 #include "network.h" |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
28 #include "rogue.h" |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
29 #ifdef PC7300 |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
30 #include "sys/window.h" |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
31 #include <ctype.h> |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
32 extern struct uwdata wdata, oldwin; |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
33 extern char oldtext[WTXTNUM][WTXTLEN]; |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
34 #endif |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
35 |
143
7faf4568c295
Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents:
131
diff
changeset
|
36 int scorefd = -1; |
7faf4568c295
Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents:
131
diff
changeset
|
37 FILE *logfile = NULL; |
7faf4568c295
Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents:
131
diff
changeset
|
38 void open_records(void); |
128 | 39 |
125
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
40 main(argc, argv, envp) |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
41 char **argv; |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
42 char **envp; |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
43 { |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
44 register char *env; |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
45 int lowtime; |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
46 time_t now; |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
47 #ifdef PC7300 |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
48 int hardwindow; /* Do we have a hardware window? */ |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
49 #endif |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
50 |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
51 md_init(); |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
52 |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
53 /* |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
54 * get home and options from environment |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
55 */ |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
56 |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
57 strncpy(home, md_gethomedir(), LINELEN); |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
58 |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
59 /* Get default save file */ |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
60 strcpy(file_name, home); |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
61 strcat(file_name, "arogue77.sav"); |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
62 |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
63 /* Get default score file */ |
127
8ae3ffd6c6e7
arogue7: make the scorefile location configurable.
John "Elwin" Edwards
parents:
126
diff
changeset
|
64 #ifdef SCOREFILE |
8ae3ffd6c6e7
arogue7: make the scorefile location configurable.
John "Elwin" Edwards
parents:
126
diff
changeset
|
65 strncpy(score_file, SCOREFILE, LINELEN); |
8ae3ffd6c6e7
arogue7: make the scorefile location configurable.
John "Elwin" Edwards
parents:
126
diff
changeset
|
66 score_file[LINELEN-1] = '\0'; |
8ae3ffd6c6e7
arogue7: make the scorefile location configurable.
John "Elwin" Edwards
parents:
126
diff
changeset
|
67 #else |
125
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
68 strcpy(score_file, md_getroguedir()); |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
69 |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
70 if (*score_file) |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
71 strcat(score_file,"/"); |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
72 |
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
73 strcat(score_file,"arogue77.scr"); |
127
8ae3ffd6c6e7
arogue7: make the scorefile location configurable.
John "Elwin" Edwards
parents:
126
diff
changeset
|
74 #endif |
125
adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff
changeset
|
75 |
128 | 76 #ifdef SAVEDIR |
77 /* Check for common save location */ | |
78 if (argc >= 3 && strcmp(argv[1], "-n") == 0) | |
79 { | |
80 strncpy(whoami, argv[2], 79); | |
81 whoami[79] = '\0'; | |
82 use_savedir = TRUE; | |
83 if (LINELEN <= snprintf(file_name, LINELEN, "%s/%d-%s.ar7sav", SAVEDIR, | |
84 md_getuid(), whoami)) | |
85 { | |
86 strcpy(file_name, "xrogue.sav"); | |
87 use_savedir = FALSE; | |
88 } | |
89 } | |
c697782a9b37
arogue7: implement the -n option.
John "Elwin" Edwards |