summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-11-12 15:02:50 -0800
committerJeremy Allison <jra@samba.org>2007-11-12 15:02:50 -0800
commit79266500cd3f84c74b2f89ceeb15c23cedacc2b5 (patch)
treeeaa0bafb15a808b2485501dbd952963c434e960e /source3/lib
parent86558e0376558f730ba1a650af2f8b545ad96b4d (diff)
downloadsamba-79266500cd3f84c74b2f89ceeb15c23cedacc2b5.tar.gz
samba-79266500cd3f84c74b2f89ceeb15c23cedacc2b5.tar.bz2
samba-79266500cd3f84c74b2f89ceeb15c23cedacc2b5.zip
Remove all pstrings from smbd/chgpasswd.c.
Jeremy. (This used to be commit eaf14c701b08e9eff5b94bf57af68cb29142d7fc)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util_str.c64
1 files changed, 44 insertions, 20 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index f1078c6383..6d429e3719 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -1254,22 +1254,27 @@ char *realloc_string_sub(char *string, const char *pattern,
return string;
}
-/* Same as string_sub, but returns a talloc'ed string */
+/*
+ * Internal guts of talloc_string_sub and talloc_all_string_sub.
+ * 'filter' differentiates between them.
+ */
-char *talloc_string_sub(TALLOC_CTX *mem_ctx, const char *src,
- const char *pattern, const char *insert)
+static char *talloc_string_sub_internal(TALLOC_CTX *mem_ctx, const char *src,
+ const char *pattern, const char *insert, bool filter)
{
char *p, *in;
char *s;
char *string;
ssize_t ls,lp,li,ld, i;
- if (!insert || !pattern || !*pattern || !src || !*src)
+ if (!insert || !pattern || !*pattern || !src || !*src) {
return NULL;
+ }
string = talloc_strdup(mem_ctx, src);
if (string == NULL) {
- DEBUG(0, ("talloc_strdup failed\n"));
+ DEBUG(0, ("talloc_string_sub_internal: "
+ "talloc_strdup failed\n"));
return NULL;
}
@@ -1277,27 +1282,30 @@ char *talloc_string_sub(TALLOC_CTX *mem_ctx, const char *src,
in = SMB_STRDUP(insert);
if (!in) {
- DEBUG(0, ("talloc_string_sub: out of memory!\n"));
+ DEBUG(0, ("talloc_string_sub_internal: ENOMEM\n"));
return NULL;
}
ls = (ssize_t)strlen(s);
lp = (ssize_t)strlen(pattern);
li = (ssize_t)strlen(insert);
ld = li - lp;
- for (i=0;i<li;i++) {
- switch (in[i]) {
- case '`':
- case '"':
- case '\'':
- case ';':
- case '$':
- case '%':
- case '\r':
- case '\n':
- in[i] = '_';
- default:
- /* ok */
- break;
+
+ if (filter) {
+ for (i=0;i<li;i++) {
+ switch (in[i]) {
+ case '`':
+ case '"':
+ case '\'':
+ case ';':
+ case '$':
+ case '%':
+ case '\r':
+ case '\n':
+ in[i] = '_';
+ default:
+ /* ok */
+ break;
+ }
}
}
@@ -1325,6 +1333,14 @@ char *talloc_string_sub(TALLOC_CTX *mem_ctx, const char *src,
return string;
}
+/* Same as string_sub, but returns a talloc'ed string */
+
+char *talloc_string_sub(TALLOC_CTX *mem_ctx, const char *src,
+ const char *pattern, const char *insert)
+{
+ return talloc_string_sub_internal(mem_ctx, src, pattern, insert, true);
+}
+
/**
Similar to string_sub() but allows for any character to be substituted.
Use with caution!
@@ -1367,6 +1383,14 @@ void all_string_sub(char *s,const char *pattern,const char *insert, size_t len)
}
}
+char *talloc_all_string_sub(TALLOC_CTX *ctx,
+ const char *src,
+ const char *pattern,
+ const char *insert)
+{
+ return talloc_string_sub_internal(ctx, src, pattern, insert, false);
+}
+
/**
Similar to all_string_sub but for unicode strings.
Return a new allocated unicode string.