1 /* Copyright (C) 2015-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
21 /* Rewrite VALUE to a valid field value in the NSS database. Invalid
22 characters are replaced with a single space character ' '. If
23 VALUE is NULL, the empty string is returned. *TO_BE_FREED is
24 overwritten with a pointer the caller has to free if the function
25 returns successfully. On failure, return NULL. */
27 __nss_rewrite_field (const char *value
, char **to_be_freed
)
33 /* Search for non-allowed characters. */
34 const char *p
= strpbrk (value
, __nss_invalid_field_characters
);
37 *to_be_freed
= __strdup (value
);
38 if (*to_be_freed
== NULL
)
41 /* Switch pointer to freshly-allocated buffer. */
42 char *bad
= *to_be_freed
+ (p
- value
);
46 bad
= strpbrk (bad
+ 1, __nss_invalid_field_characters
);