if (p) {
*p = 0;
module_params = p+1;
- trim_string(module_params, " ", " ");
+ trim_char(module_params, ' ', ' ');
}
- trim_string(module_name, " ", " ");
+ trim_char(module_name, ' ', ' ');
entry = auth_find_backend_entry(module_name);
if (! lines) return False;
for (i=0; lines[i]; i++) {
char *buf = lines[i];
- trim_string(buf," "," ");
+ trim_char(buf,' ',' ');
if (buf[0] != '#' && buf[0] != '\n')
{
special_char_sub(prompt);
fstrcpy(t->prompt, prompt);
strlower_m(t->prompt);
- trim_string(t->prompt, " ", " ");
+ trim_char(t->prompt, ' ', ' ');
if (!next_token(&p, reply, NULL, sizeof(fstring)))
break;
special_char_sub(reply);
fstrcpy(t->reply, reply);
strlower_m(t->reply);
- trim_string(t->reply, " ", " ");
+ trim_char(t->reply, ' ', ' ');
}
return list;
case PAM_PROMPT_ECHO_ON:
DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: PAM said: %s\n", msg[replies]->msg));
fstrcpy(current_prompt, msg[replies]->msg);
- trim_string(current_prompt, " ", " ");
+ trim_char(current_prompt, ' ', ' ');
for (t=pw_chat; t; t=t->next) {
DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s|\n",
case PAM_PROMPT_ECHO_OFF:
DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: PAM said: %s\n", msg[replies]->msg));
fstrcpy(current_prompt, msg[replies]->msg);
- trim_string(current_prompt, " ", " ");
+ trim_char(current_prompt, ' ', ' ');
for (t=pw_chat; t; t=t->next) {
DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s|\n",
*ddir2 = 0;
pstrcpy(ddir,mask);
- trim_string(ddir,".",NULL);
+ trim_char(ddir,'.','\0');
p = strtok(ddir,"/\\");
while (p) {
pstrcat(ddir2,p);
}
if (msgid && strncmp(lines[i], "msgstr \"", 8) == 0) {
msgstr = lines[i] + 8;
- trim_string(msgid, NULL, "\"");
- trim_string(msgstr, NULL, "\"");
+ trim_char(msgid, '\0', '\"');
+ trim_char(msgstr, '\0', '\"');
if (*msgstr == 0) {
msgstr = msgid;
}
}
if (flags & STR_TERMINATE) {
- if (src_len == (size_t)-1) {
- src_len = strlen_w(src)*2 + 2;
- } else {
+ /* src_len -1 is the default for null terminated strings. */
+ if (src_len != (size_t)-1) {
size_t len = strnlen_w(src, src_len/2);
if (len < src_len/2)
len++;
}
return 0;
}
-
already_perm = perm;
fstrcpy(tmp_local_machine,local_name);
- trim_string(tmp_local_machine," "," ");
+ trim_char(tmp_local_machine,' ',' ');
alpha_strcpy(local_machine,tmp_local_machine,SAFE_NETBIOS_CHARS,sizeof(local_machine)-1);
strlower_m(local_machine);
}
already_perm = perm;
fstrcpy(tmp_remote_machine,remote_name);
- trim_string(tmp_remote_machine," "," ");
+ trim_char(tmp_remote_machine,' ',' ');
alpha_strcpy(remote_machine,tmp_remote_machine,SAFE_NETBIOS_CHARS,sizeof(remote_machine)-1);
strlower_m(remote_machine);
}
return;
fstrcpy(tmp,name);
- trim_string(tmp," "," ");
+ trim_char(tmp,' ',' ');
strlower_m(tmp);
alpha_strcpy(smb_user_name,tmp,SAFE_NETBIOS_CHARS,sizeof(smb_user_name)-1);
}
}
fstrcpy( local_machine, global_myname() );
- trim_string( local_machine, " ", " " );
+ trim_char( local_machine, ' ', ' ' );
p = strchr( local_machine, ' ' );
if (p)
*p = 0;
trim_string(s,NULL,"/..");
}
-/*******************************************************************
- Convert '\' to '/'.
- Reduce a file name, removing or reducing /../ , /./ , // elements.
- Remove also any trailing . and /
- Return a new allocated string.
-********************************************************************/
-
-smb_ucs2_t *unix_clean_path(const smb_ucs2_t *s)
-{
- smb_ucs2_t *ns;
- smb_ucs2_t *p, *r, *t;
-
- DEBUG(3, ("unix_clean_path\n")); /* [%unicode]\n")); */
- if(!s)
- return NULL;
-
- /* convert '\' to '/' */
- ns = strdup_w(s);
- if (!ns)
- return NULL;
- unix_format_w(ns);
-
- /* remove all double slashes */
- p = ns;
- ns = all_string_sub_wa(p, "//", "/");
- SAFE_FREE(p);
- if (!ns)
- return NULL;
-
- /* remove any /./ */
- p = ns;
- ns = all_string_sub_wa(p, "/./", "/");
- SAFE_FREE(p);
- if (!ns)
- return NULL;
-
- /* reduce any /../ */
- t = ns;
- while (*t && (r = strstr_wa(t, "/.."))) {
- t = &(r[3]);
- if (*t == UCS2_CHAR('/') || *t == 0) {
- *r = 0;
- p = strrchr_w(ns, UCS2_CHAR('/'));
- if (!p)
- p = ns;
- if (*t == 0)
- *p = 0;
- else
- memmove(p, t, (strlen_w(t) + 1) * sizeof(smb_ucs2_t));
- t = p;
- }
- }
-
- /* remove any leading ./ trailing /. */
- trim_string_wa(ns, "./", "/.");
-
- /* remove any leading and trailing / */
- trim_string_wa(ns, "/", "/");
-
- return ns;
-}
-
/****************************************************************************
Make a dir struct.
****************************************************************************/
static pstring fname;
pstrcpy(fname,lp_lockdir());
- trim_string(fname,"","/");
+ trim_char(fname,'\0','/');
if (!directory_exist(fname,NULL))
mkdir(fname,0755);
static pstring fname;
pstrcpy(fname,lp_piddir());
- trim_string(fname,"","/");
+ trim_char(fname,'\0','/');
if (!directory_exist(fname,NULL))
mkdir(fname,0755);
void string_replace(pstring s,char oldc,char newc)
{
- push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
+ unsigned char *p;
+
+ /* this is quite a common operation, so we want it to be
+ fast. We optimise for the ascii case, knowing that all our
+ supported multi-byte character sets are ascii-compatible
+ (ie. they match for the first 128 chars) */
+
+ for (p = (unsigned char *)s; *p; p++) {
+ if (*p & 0x80) /* mb string - slow path. */
+ break;
+ if (*p == oldc)
+ *p = newc;
+ }
+
+ if (!*p)
+ return;
+
+ /* Slow (mb) path. */
+ push_ucs2(NULL, tmpbuf, p, sizeof(tmpbuf), STR_TERMINATE);
string_replace_w(tmpbuf, UCS2_CHAR(oldc), UCS2_CHAR(newc));
- pull_ucs2(NULL, s, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
+ pull_ucs2(NULL, p, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
}
/**
return strlen(tmpbuf2);
}
+BOOL trim_char(char *s,char cfront,char cback)
+{
+ BOOL ret = False;
+ char *ep;
+ char *fp = s;
+
+ /* Ignore null or empty strings. */
+ if (!s || (s[0] == '\0'))
+ return False;
+
+ if (cfront) {
+ while (*fp && *fp == cfront)
+ fp++;
+ if (!*fp) {
+ /* We ate the string. */
+ s[0] = '\0';
+ return True;
+ }
+ if (fp != s)
+ ret = True;
+ }
+
+ ep = fp + strlen(fp) - 1;
+ if (cback) {
+ /* Attempt ascii only. Bail for mb strings. */
+ while ((ep >= fp) && (*ep == cback)) {
+ ret = True;
+ if ((ep > fp) && (((unsigned char)ep[-1]) & 0x80)) {
+ /* Could be mb... bail back to tim_string. */
+ char fs[2], bs[2];
+ if (cfront) {
+ fs[0] = cfront;
+ fs[1] = '\0';
+ }
+ bs[0] = cback;
+ bs[1] = '\0';
+ return trim_string(s, cfront ? fs : NULL, bs);
+ } else {
+ ep--;
+ }
+ }
+ if (ep < fp) {
+ /* We ate the string. */
+ s[0] = '\0';
+ return True;
+ }
+ }
+
+ ep[1] = '\0';
+ memmove(s, fp, ep-fp+2);
+ return ret;
+}
+
/**
Trim the specified elements off the front and back of a string.
**/
char *p;
pstrcpy(path2,path);
- trim_string(path2,NULL,"\\");
- if (!*path2) *path2 = '\\';
+ trim_char(path2,'\0','\\');
+ if (!*path2)
+ *path2 = '\\';
memset(cli->outbuf,'\0',smb_size);
set_message(cli->outbuf,0,0,True);
p++;
for (i=0;i< *num_names;i++) {
StrnCpy(ret[i].name,p,15);
- trim_string(ret[i].name,NULL," ");
+ trim_char(ret[i].name,'\0',' ');
ret[i].type = CVAL(p,15);
ret[i].flags = p[16];
p += 18;
repository = alloc_sub_conn(conn, recycle_repository(handle));
ALLOC_CHECK(repository, done);
/* shouldn't we allow absolute path names here? --metze */
- trim_string(repository, "/", "/");
+ trim_char(repository, '/', '/');
if(!repository || *(repository) == '\0') {
DEBUG(3, ("recycle: repository path not set, purging %s...\n", file_name));
ZERO_STRUCTP(pdp);
- trim_string(temp,"\\","\\");
+ trim_char(temp,'\\','\\');
DEBUG(10,("temp in parse_dfs_path: .%s. after trimming \\'s\n",temp));
/* now tokenize */
char *q;
pstring buf;
pstrcpy(buf, dfspath);
- trim_string(buf, NULL, "\\");
+ trim_char(buf, '\0', '\\');
for (; consumed_level; consumed_level--) {
q = strrchr(buf, '\\');
if (q) *q = 0;
for(i=0; i<jn->referral_count; i++) {
char* refpath = jn->referral_list[i].alternate_path;
- trim_string(refpath, "\\", "\\");
+ trim_char(refpath, '\\', '\\');
if(*refpath == '\0') {
if (i == 0)
insert_comma = False;
pull_ascii_nstring(qname, p);
name_type = CVAL(p,15);
nb_flags = get_nb_flags(&p[16]);
- trim_string(qname,NULL," ");
+ trim_char(qname,'\0',' ');
p += 18;
pull_ascii_nstring(qname, p);
name_type = CVAL(p,15);
nb_flags = get_nb_flags(&p[16]);
- trim_string(qname,NULL," ");
+ trim_char(qname,'\0',' ');
p += 18;
updatecount++;
pstrcpy(fname,lp_lockdir());
- trim_string(fname,NULL,"/");
+ trim_char(fname,'\0' ,'/');
pstrcat(fname,"/");
pstrcat(fname,SERVER_LIST);
pstrcpy(fnamenew,fname);
lp_talloc = talloc_init("lp_talloc");
tmpstr = alloc_sub_basic(current_user_info.smb_name, s);
- if (trim_string(tmpstr, "\"", "\"")) {
- if (strchr(tmpstr,'"') != NULL) {
+ if (trim_char(tmpstr, '\"', '\"')) {
+ if (strchr(tmpstr,'\"') != NULL) {
SAFE_FREE(tmpstr);
tmpstr = alloc_sub_basic(current_user_info.smb_name,s);
}
pstr_sprintf(param_key, "%s:", pszParmName);
slen = strlen(param_key);
pstrcat(param_key, sep+1);
- trim_string(param_key+slen, " ", " ");
+ trim_char(param_key+slen, ' ', ' ');
not_added = True;
data = (snum < 0) ? Globals.param_opt :
ServicePtrs[snum]->param_opt;
if (p) {
*p = 0;
module_location = p+1;
- trim_string(module_location, " ", " ");
+ trim_char(module_location, ' ', ' ');
}
- trim_string(module_name, " ", " ");
+ trim_char(module_name, ' ', ' ');
DEBUG(5,("Attempting to find an passdb backend to match %s (%s)\n", selected, module_name));
if (p) {
*p = 0;
plugin_location = p+1;
- trim_string(plugin_location, " ", " ");
- } else plugin_location = NULL;
- trim_string(plugin_name, " ", " ");
+ trim_char(plugin_location, ' ', ' ');
+ } else {
+ plugin_location = NULL;
+ }
+ trim_char(plugin_name, ' ', ' ');
DEBUG(5, ("Trying to load sam plugin %s\n", plugin_name));
dl_handle = sys_dlopen(plugin_name, RTLD_NOW );
/* Make sure the status is valid */
parse_line.space2 = '\0';
- trim_string(parse_line.status, NULL, " ");
+ trim_char(parse_line.status, '\0', ' ');
if (!strequal(parse_line.status, LPRNT_PRINTING) &&
!strequal(parse_line.status, LPRNT_PAUSED) &&
!strequal(parse_line.status, LPRNT_WAITING))
return(False);
parse_line.space3 = '\0';
- trim_string(parse_line.jobname, NULL, " ");
+ trim_char(parse_line.jobname, '\0', ' ');
buf->job = atoi(parse_line.jobid);
buf->priority = 0;
/* Get the job name */
parse_line.space2[0] = '\0';
- trim_string(parse_line.jobname, NULL, " ");
+ trim_char(parse_line.jobname, '\0', ' ');
fstrcpy(buf->fs_file, parse_line.jobname);
buf->priority = 0;
/* Make sure we have a valid status */
parse_line.space4[0] = '\0';
- trim_string(parse_line.status, NULL, " ");
+ trim_char(parse_line.status, '\0', ' ');
if (!strequal(parse_line.status, LPROS2_PRINTING) &&
!strequal(parse_line.status, LPROS2_PAUSED) &&
!strequal(parse_line.status, LPROS2_WAITING))
if (info->servername[0]!='\0') {
trim_string(info->printername, info->servername, NULL);
- trim_string(info->printername, "\\", NULL);
+ trim_char(info->printername, '\\', '\0');
info->servername[0]='\0';
}
{
pstring refpath;
pstrcpy(refpath,jn.referral_list[i].alternate_path);
- trim_string(refpath, "\\", "\\");
+ trim_char(refpath, '\\', '\\');
DEBUG(10,("_dfs_remove: refpath: .%s.\n", refpath));
if(strequal(refpath, altpath))
{
struct referral* ref = &(j[i].referral_list[ii]);
pstrcpy(path, ref->alternate_path);
- trim_string(path,"\\","");
+ trim_char(path,'\\','\0');
p = strrchr_m(path,'\\');
if(p==NULL)
{
/* Eat leading/trailing whitespace before match. */
pstring str;
pstrcpy( str, buffer);
- trim_string( str, " ", " ");
+ trim_char( str, ' ', ' ');
if ((match = (unix_wild_match(expected, str) == 0)))
timeout = 200;
* also trim trailing /'s.
*/
- trim_string(name,"/","/");
+ trim_char(name,'/','/');
/*
* If we trimmed down to a single '\0' character
return(True);
start = name;
- while (strncmp(start,"./",2) == 0)
+ while (start[0] == '.' && start[1] == '/')
start += 2;
pstrcpy(orig_path, name);
return;
/*
- * Don't cache trivial valid directory entries.
+ * Don't cache trivial valid directory entries such as . and ..
*/
- if((*full_orig_name == '\0') || (strcmp(full_orig_name, ".") == 0) ||
- (strcmp(full_orig_name, "..") == 0))
+ if((*full_orig_name == '\0') || (full_orig_name[0] == '.' &&
+ ((full_orig_name[1] == '\0') ||
+ (full_orig_name[1] == '.' && full_orig_name[1] == '\0'))))
return;
/*
/* For w-files, first look for explicit "wtmp dir" */
if (uw_name[0] == 'w') {
pstrcpy(dirname,lp_wtmpdir());
- trim_string(dirname,"","/");
+ trim_char(dirname,'\0','/');
}
/* For u-files and non-explicit w-dir, look for "utmp dir" */
if (dirname == 0 || strlen(dirname) == 0) {
pstrcpy(dirname,lp_utmpdir());
- trim_string(dirname,"","/");
+ trim_char(dirname,'\0','/');
}
/* If explicit directory above, use it */
if (p) {
*p = 0;
module_param = p+1;
- trim_string(module_param, " ", " ");
+ trim_char(module_param, ' ', ' ');
}
- trim_string(module_name, " ", " ");
+ trim_char(module_name, ' ', ' ');
/* First, try to load the module with the new module system */
if((entry = vfs_find_backend_entry(module_name)) ||