summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util_str.c12
-rw-r--r--source3/lib/util_unistr.c8
2 files changed, 14 insertions, 6 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index f1376fe0f7..1c1b31a83c 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -933,11 +933,12 @@ char *safe_strcat(char *dest, const char *src, size_t maxlength)
/*******************************************************************
Paranoid strcpy into a buffer of given length (includes terminating
- zero. Strips out all but 'a-Z0-9' and replaces with '_'. Deliberately
- does *NOT* check for multibyte characters. Don't change it !
+ zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars
+ and replaces with '_'. Deliberately does *NOT* check for multibyte
+ characters. Don't change it !
********************************************************************/
-char *alpha_strcpy(char *dest, const char *src, size_t maxlength)
+char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength)
{
size_t len, i;
@@ -955,9 +956,12 @@ char *alpha_strcpy(char *dest, const char *src, size_t maxlength)
if (len >= maxlength)
len = maxlength - 1;
+ if (!other_safe_chars)
+ other_safe_chars = "";
+
for(i = 0; i < len; i++) {
int val = (src[i] & 0xff);
- if(isupper(val) ||islower(val) || isdigit(val))
+ if(isupper(val) || islower(val) || isdigit(val) || strchr(other_safe_chars, val))
dest[i] = src[i];
else
dest[i] = '_';
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 7058665145..96aa62a283 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -1453,9 +1453,10 @@ BOOL str_is_all_w(const smb_ucs2_t *s,smb_ucs2_t c)
maxlength is in ucs2 units.
********************************************************************/
-smb_ucs2_t *alpha_strcpy_w(smb_ucs2_t *dest, const smb_ucs2_t *src, size_t maxlength)
+smb_ucs2_t *alpha_strcpy_w(smb_ucs2_t *dest, const smb_ucs2_t *src, const smb_ucs2_t *other_safe_chars, size_t maxlength)
{
size_t len, i;
+ smb_ucs2_t nullstr_w = (smb_ucs2_t)0;
if (!dest) {
DEBUG(0,("ERROR: NULL dest in alpha_strcpy_w\n"));
@@ -1471,9 +1472,12 @@ smb_ucs2_t *alpha_strcpy_w(smb_ucs2_t *dest, const smb_ucs2_t *src, size_t maxle
if (len >= maxlength)
len = maxlength - 1;
+ if (!other_safe_chars)
+ other_safe_chars = &nullstr_w;
+
for(i = 0; i < len; i++) {
smb_ucs2_t val = src[i];
- if(isupper_w(val) ||islower_w(val) || isdigit_w(val))
+ if(isupper_w(val) ||islower_w(val) || isdigit_w(val) || strchr_w(other_safe_chars, val))
dest[i] = src[i];
else
dest[i] = (smb_ucs2_t)'_';