Skip to content

Commit 4967899

Browse files
committed
Move strlcpy_no_slash() to libsudo_iolog to sudo_logsrvd can use it.
1 parent 7f546c6 commit 4967899

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

include/sudo_iolog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ bool iolog_parse_host_port(char *str, char **hostp, char **portp, bool *tlsp, co
103103

104104
/* iolog_path.c */
105105
bool expand_iolog_path(const char *inpath, char *path, size_t pathlen, const struct iolog_path_escape *escapes, void *closure);
106+
size_t strlcpy_no_slash(char * restrict dst, const char * restrict src, size_t size);
106107

107108
/* iolog_util.c */
108109
bool iolog_parse_timing(const char *line, struct timing_closure *timing);

lib/iolog/iolog_path.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,29 @@ expand_iolog_path(const char *inpath, char *path, size_t pathlen,
123123
bad:
124124
debug_return_bool(false);
125125
}
126+
127+
/*
128+
* Like strlcpy(3) but replaces '/' with '_'.
129+
*/
130+
size_t
131+
strlcpy_no_slash(char * restrict dst, const char * restrict src, size_t size)
132+
{
133+
size_t len = 0;
134+
char ch;
135+
debug_decl(strlcpy_no_slash, SUDO_DEBUG_UTIL);
136+
137+
while ((ch = *src++) != '\0') {
138+
if (size > 1) {
139+
/* Replace '/' with '_' */
140+
if (ch == '/')
141+
ch = '_';
142+
*dst++ = ch;
143+
size--;
144+
}
145+
len++;
146+
}
147+
if (size > 0)
148+
*dst = '\0';
149+
150+
debug_return_size_t(len);
151+
}

plugins/sudoers/iolog_path_escapes.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,6 @@
2828
#include <sudoers.h>
2929
#include <sudo_iolog.h>
3030

31-
/*
32-
* Like strlcpy(3) but replaces '/' with '_'.
33-
*/
34-
static size_t
35-
strlcpy_no_slash(char * restrict dst, const char * restrict src, size_t size)
36-
{
37-
size_t len = 0;
38-
char ch;
39-
debug_decl(strlcpy_no_slash, SUDOERS_DEBUG_UTIL);
40-
41-
while ((ch = *src++) != '\0') {
42-
if (size > 1) {
43-
/* Replace '/' with '_' */
44-
if (ch == '/')
45-
ch = '_';
46-
*dst++ = ch;
47-
size--;
48-
}
49-
len++;
50-
}
51-
if (size > 0)
52-
*dst = '\0';
53-
54-
debug_return_size_t(len);
55-
}
56-
5731
static size_t
5832
fill_seq(char * restrict str, size_t strsize, void * restrict v)
5933
{

0 commit comments

Comments
 (0)