Skip to content

Commit 83d1bee

Browse files
committed
Rename sudo_parse_host_port -> iolog_parse_host_port and mv to lib/iolog
It is not used outside of the I/O log client and server and the host:port syntax may change in the future.
1 parent fbf2511 commit 83d1bee

File tree

10 files changed

+49
-47
lines changed

10 files changed

+49
-47
lines changed

MANIFEST

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ include/sudo_rand.h
102102
include/sudo_util.h
103103
install-sh
104104
lib/iolog/Makefile.in
105+
lib/iolog/host_port.c
105106
lib/iolog/hostcheck.c
106107
lib/iolog/iolog_fileio.c
107108
lib/iolog/iolog_json.c
108109
lib/iolog/iolog_json.h
109110
lib/iolog/iolog_path.c
110111
lib/iolog/iolog_util.c
112+
lib/iolog/regress/host_port/host_port_test.c
111113
lib/iolog/regress/iolog_json/check_iolog_json.c
112114
lib/iolog/regress/iolog_json/test1.in
113115
lib/iolog/regress/iolog_json/test2.in
@@ -150,7 +152,6 @@ lib/util/gettime.c
150152
lib/util/getusershell.c
151153
lib/util/gidlist.c
152154
lib/util/glob.c
153-
lib/util/host_port.c
154155
lib/util/inet_ntop.c
155156
lib/util/inet_pton.c
156157
lib/util/isblank.c
@@ -182,7 +183,6 @@ lib/util/regress/getgrouplist/getgrouplist_test.c
182183
lib/util/regress/glob/files
183184
lib/util/regress/glob/globtest.c
184185
lib/util/regress/glob/globtest.in
185-
lib/util/regress/host_port/host_port_test.c
186186
lib/util/regress/mktemp/mktemp_test.c
187187
lib/util/regress/parse_gids/parse_gids_test.c
188188
lib/util/regress/progname/progname_test.c

include/sudo_iolog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ struct iolog_path_escape {
107107
size_t (*copy_fn)(char *, size_t, void *);
108108
};
109109

110+
/* host_port.c */
111+
bool iolog_parse_host_port(char *str, char **hostp, char **portp, bool *tlsp, char *defport, char *defport_tls);
112+
110113
/* iolog_path.c */
111114
bool expand_iolog_path(const char *inpath, char *path, size_t pathlen, const struct iolog_path_escape *escapes, void *closure);
112115

include/sudo_util.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ __dso_public int sudo_parse_gids_v1(const char *gidstr, const gid_t *basegid, GE
207207
__dso_public int sudo_getgrouplist2_v1(const char *name, gid_t basegid, GETGROUPS_T **groupsp, int *ngroupsp);
208208
#define sudo_getgrouplist2(_a, _b, _c, _d) sudo_getgrouplist2_v1((_a), (_b), (_c), (_d))
209209

210-
/* host_port.c */
211-
__dso_public bool sudo_parse_host_port_v1(char *str, char **hostp, char **portp, bool *tlsp, char *defport, char *defport_tls);
212-
#define sudo_parse_host_port(_a, _b, _c, _d, _e, _f) sudo_parse_host_port_v1((_a), (_b), (_c), (_d), (_e), (_f))
213-
214210
/* key_val.c */
215211
__dso_public char *sudo_new_key_val_v1(const char *key, const char *value);
216212
#define sudo_new_key_val(_a, _b) sudo_new_key_val_v1((_a), (_b))

lib/iolog/Makefile.in

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ PVS_IGNORE = 'V707,V011,V002,V536'
7575
PVS_LOG_OPTS = -a 'GA:1,2' -e -t errorfile -d $(PVS_IGNORE)
7676

7777
# Regression tests
78-
TEST_PROGS = check_iolog_json check_iolog_path check_iolog_util
78+
TEST_PROGS = check_iolog_json check_iolog_path check_iolog_util host_port_test
7979
TEST_LIBS = @LIBS@
8080
TEST_LDFLAGS = @LDFLAGS@
8181

@@ -87,7 +87,7 @@ DEVEL = @DEVEL@
8787
SHELL = @SHELL@
8888

8989
LIBIOLOG_OBJS = iolog_fileio.lo iolog_json.lo iolog_path.lo iolog_util.lo \
90-
hostcheck.lo
90+
host_port.lo hostcheck.lo
9191

9292
IOBJS = $(LIBIOLOG_OBJS:.lo=.i)
9393

@@ -99,6 +99,8 @@ CHECK_IOLOG_UTIL_OBJS = check_iolog_util.lo iolog_json.lo iolog_util.lo
9999

100100
CHECK_IOLOG_JSON_OBJS = check_iolog_json.lo iolog_json.lo
101101

102+
HOST_PORT_TEST_OBJS = host_port_test.lo host_port.lo
103+
102104
all: libsudo_iolog.la
103105

104106
pvs-log-files: $(POBJS)
@@ -137,6 +139,9 @@ check_iolog_util: $(CHECK_IOLOG_UTIL_OBJS) libsudo_iolog.la
137139
check_iolog_json: $(CHECK_IOLOG_JSON_OBJS) libsudo_iolog.la
138140
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -o $@ $(CHECK_IOLOG_JSON_OBJS) libsudo_iolog.la $(ASAN_LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
139141

142+
host_port_test: $(HOST_PORT_TEST_OBJS) libsudo_iolog.la
143+
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -o $@ $(HOST_PORT_TEST_OBJS) libsudo_iolog.la $(ASAN_LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
144+
140145
pre-install:
141146

142147
install:
@@ -167,6 +172,7 @@ check: $(TEST_PROGS)
167172
./check_iolog_json $(srcdir)/regress/iolog_json/*.in || rval=`expr $$rval + $$?`; \
168173
./check_iolog_path $(srcdir)/regress/iolog_path/data || rval=`expr $$rval + $$?`; \
169174
./check_iolog_util || rval=`expr $$rval + $$?`; \
175+
./host_port_test || rval=`expr $$rval + $$?`; \
170176
exit $$rval; \
171177
fi
172178

@@ -226,6 +232,30 @@ check_iolog_util.i: $(srcdir)/regress/iolog_util/check_iolog_util.c \
226232
$(CC) -E -o $@ $(CPPFLAGS) $<
227233
check_iolog_util.plog: check_iolog_util.i
228234
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/regress/iolog_util/check_iolog_util.c --i-file $< --output-file $@
235+
host_port.lo: $(srcdir)/host_port.c $(incdir)/compat/stdbool.h \
236+
$(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
237+
$(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
238+
$(incdir)/sudo_util.h $(top_builddir)/config.h
239+
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/host_port.c
240+
host_port.i: $(srcdir)/host_port.c $(incdir)/compat/stdbool.h \
241+
$(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
242+
$(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
243+
$(incdir)/sudo_util.h $(top_builddir)/config.h
244+
$(CC) -E -o $@ $(CPPFLAGS) $<
245+
host_port.plog: host_port.i
246+
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/host_port.c --i-file $< --output-file $@
247+
host_port_test.lo: $(srcdir)/regress/host_port/host_port_test.c \
248+
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
249+
$(incdir)/sudo_fatal.h $(incdir)/sudo_util.h \
250+
$(top_builddir)/config.h
251+
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/regress/host_port/host_port_test.c
252+
host_port_test.i: $(srcdir)/regress/host_port/host_port_test.c \
253+
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
254+
$(incdir)/sudo_fatal.h $(incdir)/sudo_util.h \
255+
$(top_builddir)/config.h
256+
$(CC) -E -o $@ $(CPPFLAGS) $<
257+
host_port_test.plog: host_port_test.i
258+
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/regress/host_port/host_port_test.c --i-file $< --output-file $@
229259
hostcheck.lo: $(srcdir)/hostcheck.c $(incdir)/compat/stdbool.h \
230260
$(incdir)/hostcheck.h $(incdir)/sudo_compat.h \
231261
$(incdir)/sudo_debug.h $(incdir)/sudo_queue.h \
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
* Fills in hostp and portp which may point within str, which is modified.
4242
*/
4343
bool
44-
sudo_parse_host_port_v1(char *str, char **hostp, char **portp, bool *tlsp,
44+
iolog_parse_host_port(char *str, char **hostp, char **portp, bool *tlsp,
4545
char *defport, char *defport_tls)
4646
{
4747
char *flags, *port, *host = str;
4848
bool ret = false;
4949
bool tls = false;
50-
debug_decl(sudo_parse_host_port, SUDO_DEBUG_UTIL);
50+
debug_decl(iolog_parse_host_port, SUDO_DEBUG_UTIL);
5151

5252
/* Check for IPv6 address like [::0] followed by optional port */
5353
if (*host == '[') {

lib/util/regress/host_port/host_port_test.c renamed to lib/iolog/regress/host_port/host_port_test.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@
3232
#else
3333
# include "compat/stdbool.h"
3434
#endif
35+
#include <time.h>
36+
#include <unistd.h>
3537

3638
#include "sudo_compat.h"
3739
#include "sudo_fatal.h"
40+
#include "sudo_iolog.h"
3841
#include "sudo_util.h"
3942

4043
__dso_public int main(int argc, char *argv[]);
4144

4245
/*
43-
* Test that sudo_parse_host_port() works as expected.
46+
* Test that iolog_parse_host_port() works as expected.
4447
*/
4548

4649
struct host_port_test {
@@ -95,7 +98,7 @@ main(int argc, char *argv[])
9598
sudo_fatal_nodebug(NULL);
9699

97100
ntests++;
98-
ret = sudo_parse_host_port(copy, &host, &port, &tls,
101+
ret = iolog_parse_host_port(copy, &host, &port, &tls,
99102
test_data[i].defport, test_data[i].defport_tls);
100103
if (ret != test_data[i].ret) {
101104
sudo_warnx_nodebug("test #%d: %s: returned %s, expected %s",

lib/util/Makefile.in

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ PVS_LOG_OPTS = -a 'GA:1,2' -e -t errorfile -d $(PVS_IGNORE)
104104
# Regression tests
105105
TEST_PROGS = conf_test hltq_test parseln_test progname_test strsplit_test \
106106
strtobool_test strtoid_test strtomode_test strtonum_test \
107-
parse_gids_test getgrouplist_test host_port_test @COMPAT_TEST_PROGS@
107+
parse_gids_test getgrouplist_test @COMPAT_TEST_PROGS@
108108
TEST_LIBS = @LIBS@
109109
TEST_LDFLAGS = @LDFLAGS@
110110

@@ -120,7 +120,7 @@ DEVEL = @DEVEL@
120120
SHELL = @SHELL@
121121

122122
LTOBJS = @DIGEST@ event.lo fatal.lo key_val.lo gethostname.lo gettime.lo \
123-
getgrouplist.lo gidlist.lo host_port.lo json.lo lbuf.lo locking.lo \
123+
getgrouplist.lo gidlist.lo json.lo lbuf.lo locking.lo \
124124
logfac.lo logpri.lo mkdir_parents.lo parseln.lo progname.lo \
125125
roundup.lo secure_path.lo setgroups.lo strsplit.lo strtobool.lo \
126126
strtoid.lo strtomode.lo strtonum.lo sudo_conf.lo \
@@ -161,8 +161,6 @@ PARSE_GIDS_TEST_OBJS = parse_gids_test.lo gidlist.lo
161161

162162
GETGROUPLIST_TEST_OBJS = getgrouplist_test.lo getgrouplist.lo
163163

164-
HOST_PORT_TEST_OBJS = host_port_test.lo host_port.lo
165-
166164
STRSIG_TEST_OBJS = strsig_test.lo sig2str.lo str2sig.lo @SIGNAME@
167165

168166
VSYSLOG_TEST_OBJS = vsyslog_test.lo vsyslog.lo
@@ -259,9 +257,6 @@ parse_gids_test: $(PARSE_GIDS_TEST_OBJS) libsudo_util.la
259257
getgrouplist_test: $(GETGROUPLIST_TEST_OBJS) libsudo_util.la
260258
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -o $@ $(GETGROUPLIST_TEST_OBJS) libsudo_util.la $(ASAN_LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
261259

262-
host_port_test: $(HOST_PORT_TEST_OBJS) libsudo_util.la
263-
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -o $@ $(HOST_PORT_TEST_OBJS) libsudo_util.la $(ASAN_LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
264-
265260
strsplit_test: $(STRSPLIT_TEST_OBJS) libsudo_util.la
266261
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -o $@ $(STRSPLIT_TEST_OBJS) libsudo_util.la $(ASAN_LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
267262

@@ -351,7 +346,6 @@ check: $(TEST_PROGS)
351346
./strsig_test || rval=`expr $$rval + $$?`; \
352347
fi; \
353348
./getgrouplist_test || rval=`expr $$rval + $$?`; \
354-
./host_port_test || rval=`expr $$rval + $$?`; \
355349
./strtobool_test || rval=`expr $$rval + $$?`; \
356350
./strtoid_test || rval=`expr $$rval + $$?`; \
357351
./strtomode_test || rval=`expr $$rval + $$?`; \
@@ -766,30 +760,6 @@ hltq_test.i: $(srcdir)/regress/tailq/hltq_test.c $(incdir)/compat/stdbool.h \
766760
$(CC) -E -o $@ $(CPPFLAGS) $<
767761
hltq_test.plog: hltq_test.i
768762
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/regress/tailq/hltq_test.c --i-file $< --output-file $@
769-
host_port.lo: $(srcdir)/host_port.c $(incdir)/compat/stdbool.h \
770-
$(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
771-
$(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
772-
$(incdir)/sudo_util.h $(top_builddir)/config.h
773-
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/host_port.c
774-
host_port.i: $(srcdir)/host_port.c $(incdir)/compat/stdbool.h \
775-
$(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
776-
$(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
777-
$(incdir)/sudo_util.h $(top_builddir)/config.h
778-
$(CC) -E -o $@ $(CPPFLAGS) $<
779-
host_port.plog: host_port.i
780-
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/host_port.c --i-file $< --output-file $@
781-
host_port_test.lo: $(srcdir)/regress/host_port/host_port_test.c \
782-
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
783-
$(incdir)/sudo_fatal.h $(incdir)/sudo_util.h \
784-
$(top_builddir)/config.h
785-
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/regress/host_port/host_port_test.c
786-
host_port_test.i: $(srcdir)/regress/host_port/host_port_test.c \
787-
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
788-
$(incdir)/sudo_fatal.h $(incdir)/sudo_util.h \
789-
$(top_builddir)/config.h
790-
$(CC) -E -o $@ $(CPPFLAGS) $<
791-
host_port_test.plog: host_port_test.i
792-
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/regress/host_port/host_port_test.c --i-file $< --output-file $@
793763
inet_pton.lo: $(srcdir)/inet_pton.c $(incdir)/sudo_compat.h \
794764
$(top_builddir)/config.h
795765
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/inet_pton.c

lib/util/util.exp.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ sudo_logpri2str_v1
108108
sudo_mkdir_parents_v1
109109
sudo_new_key_val_v1
110110
sudo_parse_gids_v1
111-
sudo_parse_host_port_v1
112111
sudo_parseln_v1
113112
sudo_parseln_v2
114113
sudo_pow2_roundup_v1

logsrvd/logsrvd_conf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ cb_listen_address(struct logsrvd_config *config, const char *str)
382382
}
383383

384384
/* Parse host[:port] */
385-
if (!sudo_parse_host_port(copy, &host, &port, &tls, DEFAULT_PORT,
385+
if (!iolog_parse_host_port(copy, &host, &port, &tls, DEFAULT_PORT,
386386
DEFAULT_PORT_TLS))
387387
goto done;
388388
if (host[0] == '*' && host[1] == '\0')

plugins/sudoers/iolog_client.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
#include "sudoers.h"
6262
#include "sudo_event.h"
63+
#include "sudo_iolog.h"
6364
#include "iolog_plugin.h"
6465
#include "hostcheck.h"
6566

@@ -549,7 +550,7 @@ log_server_connect(struct client_closure *closure)
549550
STAILQ_FOREACH(server, closure->log_details->log_servers, entries) {
550551
free(copy);
551552
copy = strdup(server->str);
552-
if (!sudo_parse_host_port(copy, &host, &port, &tls, DEFAULT_PORT,
553+
if (!iolog_parse_host_port(copy, &host, &port, &tls, DEFAULT_PORT,
553554
DEFAULT_PORT_TLS)) {
554555
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
555556
"unable to parse %s", copy);

0 commit comments

Comments
 (0)