Skip to content

Commit 2f83222

Browse files
author
Jesse Smith
committed
Added optimization to Makefile (can be set/overruled using OPT).
Added flag to display all warnings during compiling. Added status checks when parsing user/group IDs for Linux. Make sure Linux drops original user's groups when running as another user.
1 parent 79c6c61 commit 2f83222

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ PREFIX?=/usr/local
55
MANDIR?=$(DESTDIR)$(PREFIX)/man
66
SYSCONFDIR?=$(DESTDIR)$(PREFIX)/etc
77
OBJECTS=doas.o env.o execvpe.o reallocarray.o y.tab.o
8+
OPT?=-O2
89
# Can set GLOBAL_PATH here to set PATH for target user.
910
# TARGETPATH=-DGLOBAL_PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\"
10-
CFLAGS+=-DUSE_PAM -DDOAS_CONF=\"${SYSCONFDIR}/doas.conf\" $(TARGETPATH)
11+
CFLAGS+=-Wall $(OPT) -DUSE_PAM -DDOAS_CONF=\"${SYSCONFDIR}/doas.conf\" $(TARGETPATH)
1112
LDFLAGS+=-lpam
1213
UNAME_S := $(shell uname -s)
1314
ifeq ($(UNAME_S),Linux)

doas.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,25 @@ static int
8585
parseuid(const char *s, uid_t *uid)
8686
{
8787
struct passwd *pw;
88-
const char *errstr;
88+
#if !defined(__linux__) && !defined(__NetBSD__)
89+
const char *errstr = NULL;
90+
#else
91+
int status;
92+
#endif
8993

9094
if ((pw = getpwnam(s)) != NULL) {
9195
*uid = pw->pw_uid;
9296
return 0;
9397
}
9498
#if !defined(__linux__) && !defined(__NetBSD__)
9599
*uid = strtonum(s, 0, UID_MAX, &errstr);
96-
#else
97-
sscanf(s, "%d", uid);
98-
#endif
99100
if (errstr)
100101
return -1;
102+
#else
103+
status = sscanf(s, "%d", uid);
104+
if (status != 1)
105+
return -1;
106+
#endif
101107
return 0;
102108
}
103109

@@ -117,19 +123,25 @@ static int
117123
parsegid(const char *s, gid_t *gid)
118124
{
119125
struct group *gr;
120-
const char *errstr;
126+
#if !defined(__linux__) && !defined(__NetBSD__)
127+
const char *errstr = NULL;
128+
#else
129+
int status;
130+
#endif
121131

122132
if ((gr = getgrnam(s)) != NULL) {
123133
*gid = gr->gr_gid;
124134
return 0;
125135
}
126136
#if !defined(__linux__) && !defined(__NetBSD__)
127137
*gid = strtonum(s, 0, GID_MAX, &errstr);
128-
#else
129-
sscanf(s, "%d", gid);
130-
#endif
131138
if (errstr)
132139
return -1;
140+
#else
141+
status = sscanf(s, "%d", gid);
142+
if (status != 1)
143+
return -1;
144+
#endif
133145
return 0;
134146
}
135147

0 commit comments

Comments
 (0)