Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ libshadow_la_SOURCES = \
spawn.c \
sssd.c \
sssd.h \
string/ctype/strchrisascii/strchriscntrl.c \
string/ctype/strchrisascii/strchriscntrl.h \
string/ctype/strisascii/strisdigit.c \
string/ctype/strisascii/strisdigit.h \
string/ctype/strisascii/strisprint.c \
string/ctype/strisascii/strisprint.h \
string/ctype/strtoascii/strtolower.c \
string/ctype/strtoascii/strtolower.h \
string/ctype/isascii.c \
string/ctype/isascii.h \
string/ctype/strchrisascii.c \
string/ctype/strchrisascii.h \
string/ctype/strisascii.c \
string/ctype/strisascii.h \
string/ctype/strtoascii.c \
string/ctype/strtoascii.h \
string/memset/memzero.c \
string/memset/memzero.h \
string/sprintf/aprintf.c \
Expand Down
29 changes: 10 additions & 19 deletions lib/chkname.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@

#include "defines.h"
#include "chkname.h"
#include "string/ctype/strchrisascii/strchriscntrl.h"
#include "string/ctype/strisascii/strisdigit.h"
#include "string/ctype/isascii.h"
#include "string/ctype/strchrisascii.h"
#include "string/ctype/strisascii.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strcaseeq.h"

Expand Down Expand Up @@ -68,8 +69,8 @@ is_valid_name(const char *name)
|| streq(name, "..")
|| strspn(name, "-")
|| strpbrk(name, " \"#',/:;")
|| strchriscntrl(name)
|| strisdigit(name))
|| strchriscntrl_c(name)
|| strisdigit_c(name))
{
errno = EINVAL;
return false;
Expand All @@ -87,26 +88,16 @@ is_valid_name(const char *name)
* sake of Samba 3.x "add machine script"
*/

if (!((*name >= 'a' && *name <= 'z') ||
(*name >= 'A' && *name <= 'Z') ||
(*name >= '0' && *name <= '9') ||
*name == '_' ||
*name == '.'))
{
if (!ispfchar_c(*name)) {
errno = EILSEQ;
return false;
}

while (!streq(++name, "")) {
if (!((*name >= 'a' && *name <= 'z') ||
(*name >= 'A' && *name <= 'Z') ||
(*name >= '0' && *name <= '9') ||
*name == '_' ||
*name == '.' ||
*name == '-' ||
streq(name, "$")
))
{
if (streq(name, "$")) // Samba
return true;

if (!ispfchar_c(*name)) {
errno = EILSEQ;
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/fields.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <string.h>

#include "prototypes.h"
#include "string/ctype/strisascii/strisprint.h"
#include "string/ctype/strchrisascii/strchriscntrl.h"
#include "string/ctype/strisascii.h"
#include "string/ctype/strchrisascii.h"
#include "string/strcmp/streq.h"
#include "string/strspn/stpspn.h"
#include "string/strspn/stprspn.h"
Expand All @@ -41,12 +41,12 @@ valid_field_(const char *field, const char *illegal)

if (strpbrk(field, illegal))
return -1;
if (strchriscntrl(field))
if (strchriscntrl_c(field))
return -1;
if (strisprint(field))
return 0;
if (streq(field, ""))
return 0;
if (strisprint_c(field))
return 0;

return 1; // !ASCII
}
Expand Down
3 changes: 2 additions & 1 deletion lib/getrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "atoi/a2i.h"
#include "defines.h"
#include "prototypes.h"
#include "string/ctype/isascii.h"
#include "string/strcmp/streq.h"


Expand Down Expand Up @@ -57,7 +58,7 @@ getrange(const char *range,
if (streq(end, ""))
return 0; /* <long>- */
parse_max:
if (!isdigit((unsigned char) *end))
if (!isdigit_c(*end))
return -1;

if (a2ul(max, end, NULL, 10, *min, ULONG_MAX) == -1)
Expand Down
2 changes: 1 addition & 1 deletion lib/obscure.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "prototypes.h"
#include "defines.h"
#include "getdef.h"
#include "string/ctype/strtoascii/strtolower.h"
#include "string/ctype/strtoascii.h"
#include "string/memset/memzero.h"
#include "string/sprintf/aprintf.h"
#include "string/strcmp/streq.h"
Expand Down
7 changes: 4 additions & 3 deletions lib/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "defines.h"
#include "port.h"
#include "prototypes.h"
#include "string/ctype/isascii.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strtok/stpsep.h"
Expand Down Expand Up @@ -211,7 +212,7 @@ getportent(void)
* week or the other two values.
*/

for (i = 0; isalpha(cp[i]) && ('\0' != cp[i + 1]); i += 2) {
for (i = 0; isalpha_c(cp[i]) && ('\0' != cp[i + 1]); i += 2) {
switch ((cp[i] << 8) | (cp[i + 1])) {
case ('S' << 8) | 'u':
port.pt_times[j].t_days |= 01;
Expand Down Expand Up @@ -260,7 +261,7 @@ getportent(void)
* representing the times of day.
*/

for (dtime = 0; isdigit (cp[i]); i++) {
for (dtime = 0; isdigit_c(cp[i]); i++) {
dtime = dtime * 10 + cp[i] - '0';
}

Expand All @@ -270,7 +271,7 @@ getportent(void)
port.pt_times[j].t_start = dtime;
cp = cp + i + 1;

for (dtime = 0, i = 0; isdigit (cp[i]); i++) {
for (dtime = 0, i = 0; isdigit_c(cp[i]); i++) {
dtime = dtime * 10 + cp[i] - '0';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/setupenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static void read_env_file (const char *filename)
} else if (*cp == '\0') {
/* end of string */
goto finished;
} else if (isspace (*cp)) {
} else if (isspace_c(*cp)) {
/* unescaped whitespace - end of string */
stpcpy(cp, "");
goto finished;
Expand Down
21 changes: 13 additions & 8 deletions lib/string/README
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,26 @@ Specific guidelines:

ctype/ - Character classification and conversion functions

strchrisascii/
The functions defined under this directory
isascii.h
The functions defined in this file
return true
if the character
belongs to the category specified in the function name.

strchrisascii.h
The functions defined in this file
return true
if the string has any characters that
belong to the category specified in the function name.

strisascii/
The functions defined under this directory
strisascii.h
The functions defined in this file
return true
if all of the characters of the string
belong to the category specified in the function name
and the string is not an empty string.
belong to the category specified in the function name.

strtoascii/
The functions defined under this directory
strtoascii.h
The functions defined in this file
translate all characters in a string.

memset/ - Memory zeroing
Expand Down
7 changes: 7 additions & 0 deletions lib/string/ctype/isascii.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#include "config.h"

#include "string/ctype/isascii.h"
50 changes: 50 additions & 0 deletions lib/string/ctype/isascii.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_STRING_CTYPE_ISASCII_H_
#define SHADOW_INCLUDE_LIB_STRING_CTYPE_ISASCII_H_


#include "config.h"

#include <string.h>

#include "string/strcmp/streq.h"


#define CTYPE_CNTRL_C \
"\x1F\x1E\x1D\x1C\x1B\x1A\x19\x18\x17\x16\x15\x14\x13\x12\x11\x10" \
"\x0F\x0E\x0D\x0C\x0B\x0A\x09\x08\x07\x06\x05\x04\x03\x02\x01" /*NUL*/

#define CTYPE_LOWER_C "abcdefghijklmnopqrstuvwxyz"
#define CTYPE_UPPER_C "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define CTYPE_DIGIT_C "0123456789"
#define CTYPE_PUNCT_C "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
#define CTYPE_SPACE_C " \t\n\v\f\r"
#define CTYPE_ALPHA_C CTYPE_LOWER_C CTYPE_UPPER_C
#define CTYPE_ALNUM_C CTYPE_ALPHA_C CTYPE_DIGIT_C
#define CTYPE_GRAPH_C CTYPE_ALNUM_C CTYPE_PUNCT_C
#define CTYPE_PRINT_C CTYPE_GRAPH_C " "
#define CTYPE_XDIGIT_C CTYPE_DIGIT_C "abcdefABCDEF"
#define CTYPE_ASCII_C CTYPE_PRINT_C CTYPE_CNTRL_C /*NUL*/
#define CTYPE_PFCHAR_C CTYPE_ALNUM_C "._-" // portable filename character set


// isascii_c - is [:ascii:] C-locale
#define isascii_c(c) (!!strchr(CTYPE_ASCII_C, c))
#define iscntrl_c(c) (!!strchr(CTYPE_CNTRL_C, c))
#define islower_c(c) (!streq(strchrnul(CTYPE_LOWER_C, c), ""))
#define isupper_c(c) (!streq(strchrnul(CTYPE_UPPER_C, c), ""))
#define isdigit_c(c) (!streq(strchrnul(CTYPE_DIGIT_C, c), ""))
#define ispunct_c(c) (!streq(strchrnul(CTYPE_PUNCT_C, c), ""))
#define isspace_c(c) (!streq(strchrnul(CTYPE_SPACE_C, c), ""))
#define isalpha_c(c) (!streq(strchrnul(CTYPE_ALPHA_C, c), ""))
#define isalnum_c(c) (!streq(strchrnul(CTYPE_ALNUM_C, c), ""))
#define isgraph_c(c) (!streq(strchrnul(CTYPE_GRAPH_C, c), ""))
#define isprint_c(c) (!streq(strchrnul(CTYPE_PRINT_C, c), ""))
#define isxdigit_c(c) (!streq(strchrnul(CTYPE_XDIGIT_C, c), ""))
#define ispfchar_c(c) (!streq(strchrnul(CTYPE_PFCHAR_C, c), ""))


#endif // include guard
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@

#include "config.h"

#include "string/ctype/strisascii/strisprint.h"

#include <stdbool.h>


extern inline bool strisprint(const char *s);
#include "string/ctype/strchrisascii.h"
20 changes: 20 additions & 0 deletions lib/string/ctype/strchrisascii.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_STRING_CTYPE_STRCHRISASCII_H_
#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRCHRISASCII_H_


#include "config.h"

#include <string.h>

#include "string/ctype/isascii.h"


// strchriscntrl_c - string character is [:cntrl:] C-locale
#define strchriscntrl_c(s) (!!strpbrk(s, CTYPE_CNTRL_C))


#endif // include guard
12 changes: 0 additions & 12 deletions lib/string/ctype/strchrisascii/strchriscntrl.c

This file was deleted.

36 changes: 0 additions & 36 deletions lib/string/ctype/strchrisascii/strchriscntrl.h

This file was deleted.

7 changes: 7 additions & 0 deletions lib/string/ctype/strisascii.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#include "config.h"

#include "string/ctype/strisascii.h"
21 changes: 21 additions & 0 deletions lib/string/ctype/strisascii.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_H_
#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_H_


#include "config.h"

#include "string/ctype/isascii.h"
#include "string/strcmp/streq.h"
#include "string/strspn/stpspn.h"


// strisascii_c - string is [:ascii:] C-locale
#define strisdigit_c(s) streq(stpspn(s, CTYPE_DIGIT_C), "")
#define strisprint_c(s) streq(stpspn(s, CTYPE_PRINT_C), "")


#endif // include guard
12 changes: 0 additions & 12 deletions lib/string/ctype/strisascii/strisdigit.c

This file was deleted.

Loading
Loading