From 94f59f54921174fc156fade575ca114d331b1bd8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 5 Sep 2003 19:59:55 +0000 Subject: [PATCH] More tuning from cachegrind. Change most trim_string() calls to trim_char(0, as that's what they do. Fix string_replace() to fast-path ascii. Jeremy. (This used to be commit f35e9a8b909d3c74be47083ccc4a4e91a14938db) --- source3/auth/auth.c | 4 +- source3/auth/auth_rhosts.c | 2 +- source3/auth/pampass.c | 8 ++-- source3/client/client.c | 2 +- source3/intl/lang_tdb.c | 4 +- source3/lib/charcnv.c | 6 +-- source3/lib/substitute.c | 6 +-- source3/lib/util.c | 68 ++--------------------------- source3/lib/util_str.c | 75 +++++++++++++++++++++++++++++++- source3/libsmb/clifile.c | 5 ++- source3/libsmb/namequery.c | 2 +- source3/modules/vfs_recycle.c | 2 +- source3/msdfs/msdfs.c | 6 +-- source3/nmbd/nmbd_browsesync.c | 4 +- source3/nmbd/nmbd_serverlistdb.c | 2 +- source3/param/loadparm.c | 6 +-- source3/passdb/pdb_interface.c | 4 +- source3/passdb/pdb_plugin.c | 8 ++-- source3/printing/lpq_parse.c | 8 ++-- source3/printing/nt_printing.c | 2 +- source3/rpc_server/srv_dfs_nt.c | 4 +- source3/smbd/chgpasswd.c | 2 +- source3/smbd/filename.c | 4 +- source3/smbd/statcache.c | 7 +-- source3/smbd/utmp.c | 4 +- source3/smbd/vfs.c | 4 +- 26 files changed, 130 insertions(+), 119 deletions(-) diff --git a/source3/auth/auth.c b/source3/auth/auth.c index 668bba0d641..553d9a686e3 100644 --- a/source3/auth/auth.c +++ b/source3/auth/auth.c @@ -373,10 +373,10 @@ BOOL load_auth_module(struct auth_context *auth_context, 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); diff --git a/source3/auth/auth_rhosts.c b/source3/auth/auth_rhosts.c index fab2d551f29..b295df9328f 100644 --- a/source3/auth/auth_rhosts.c +++ b/source3/auth/auth_rhosts.c @@ -40,7 +40,7 @@ static BOOL check_user_equiv(const char *user, const char *remote, const char *e 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') { diff --git a/source3/auth/pampass.c b/source3/auth/pampass.c index d666e439b0d..3239686a20d 100644 --- a/source3/auth/pampass.c +++ b/source3/auth/pampass.c @@ -230,7 +230,7 @@ static struct chat_struct *make_pw_chat(char *p) 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; @@ -241,7 +241,7 @@ static struct chat_struct *make_pw_chat(char *p) special_char_sub(reply); fstrcpy(t->reply, reply); strlower_m(t->reply); - trim_string(t->reply, " ", " "); + trim_char(t->reply, ' ', ' '); } return list; @@ -304,7 +304,7 @@ static int smb_pam_passchange_conv(int num_msg, 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", @@ -335,7 +335,7 @@ static int smb_pam_passchange_conv(int num_msg, 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", diff --git a/source3/client/client.c b/source3/client/client.c index 67931b00b4d..ecece8942ec 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -1006,7 +1006,7 @@ static int cmd_mkdir(void) *ddir2 = 0; pstrcpy(ddir,mask); - trim_string(ddir,".",NULL); + trim_char(ddir,'.','\0'); p = strtok(ddir,"/\\"); while (p) { pstrcat(ddir2,p); diff --git a/source3/intl/lang_tdb.c b/source3/intl/lang_tdb.c index 87ef4e39c7b..f12b9b6f151 100644 --- a/source3/intl/lang_tdb.c +++ b/source3/intl/lang_tdb.c @@ -53,8 +53,8 @@ static BOOL load_msg(const char *msg_file) } 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; } diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index a07ff7399d9..ceb9d57fc71 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -879,9 +879,8 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ } 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++; @@ -1051,4 +1050,3 @@ size_t align_string(const void *base_ptr, const char *p, int flags) } return 0; } - diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index a73f9d85dab..28466e43f29 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -57,7 +57,7 @@ void set_local_machine_name(const char* local_name, BOOL perm) 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); } @@ -79,7 +79,7 @@ void set_remote_machine_name(const char* remote_name, BOOL perm) 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); } @@ -111,7 +111,7 @@ void sub_set_smb_name(const char *name) 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); } diff --git a/source3/lib/util.c b/source3/lib/util.c index 5f4fae9baa2..766c5041b4e 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -261,7 +261,7 @@ BOOL init_names(void) } fstrcpy( local_machine, global_myname() ); - trim_string( local_machine, " ", " " ); + trim_char( local_machine, ' ', ' ' ); p = strchr( local_machine, ' ' ); if (p) *p = 0; @@ -605,68 +605,6 @@ void unix_clean_name(char *s) 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. ****************************************************************************/ @@ -2205,7 +2143,7 @@ char *lock_path(const char *name) static pstring fname; pstrcpy(fname,lp_lockdir()); - trim_string(fname,"","/"); + trim_char(fname,'\0','/'); if (!directory_exist(fname,NULL)) mkdir(fname,0755); @@ -2225,7 +2163,7 @@ char *pid_path(const char *name) static pstring fname; pstrcpy(fname,lp_piddir()); - trim_string(fname,"","/"); + trim_char(fname,'\0','/'); if (!directory_exist(fname,NULL)) mkdir(fname,0755); diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 70567f88afd..82b312e2415 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -364,9 +364,27 @@ BOOL strisnormal(const char *s) 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); } /** @@ -406,6 +424,59 @@ size_t str_ascii_charnum(const char *s) 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. **/ diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index f021076a46c..c7f0cdb84b5 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -951,8 +951,9 @@ BOOL cli_chkpath(struct cli_state *cli, const char *path) 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); diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index 9875f77c72e..1de74137117 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -61,7 +61,7 @@ static struct node_status *parse_node_status(char *p, int *num_names) 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; diff --git a/source3/modules/vfs_recycle.c b/source3/modules/vfs_recycle.c index c0b331b8621..b1b2ac03538 100644 --- a/source3/modules/vfs_recycle.c +++ b/source3/modules/vfs_recycle.c @@ -336,7 +336,7 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co 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)); diff --git a/source3/msdfs/msdfs.c b/source3/msdfs/msdfs.c index dc326f2eee8..afe523bf19b 100644 --- a/source3/msdfs/msdfs.c +++ b/source3/msdfs/msdfs.c @@ -40,7 +40,7 @@ static BOOL parse_dfs_path(char* pathname, struct dfs_path* pdp) ZERO_STRUCTP(pdp); - trim_string(temp,"\\","\\"); + trim_char(temp,'\\','\\'); DEBUG(10,("temp in parse_dfs_path: .%s. after trimming \\'s\n",temp)); /* now tokenize */ @@ -275,7 +275,7 @@ static BOOL resolve_dfs_path(char* dfspath, struct dfs_path* dp, 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; @@ -780,7 +780,7 @@ BOOL create_msdfs_link(struct junction_map* jn, BOOL exists) for(i=0; ireferral_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; diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 96e8fd1b815..6cde88651f9 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -204,7 +204,7 @@ static void domain_master_node_status_success(struct subnet_record *subrec, 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; @@ -427,7 +427,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub 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; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index a5008f803b4..cdb1089a54f 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -328,7 +328,7 @@ void write_browse_list(time_t t, BOOL force_write) updatecount++; pstrcpy(fname,lp_lockdir()); - trim_string(fname,NULL,"/"); + trim_char(fname,'\0' ,'/'); pstrcat(fname,"/"); pstrcat(fname,SERVER_LIST); pstrcpy(fnamenew,fname); diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 3d0aebf230b..c801c4c522f 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -1558,8 +1558,8 @@ static char *lp_string(const char *s) 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); } @@ -3112,7 +3112,7 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue 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; diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c index 5ebc14030f0..d548081e78b 100644 --- a/source3/passdb/pdb_interface.c +++ b/source3/passdb/pdb_interface.c @@ -422,10 +422,10 @@ static NTSTATUS make_pdb_methods_name(struct pdb_methods **methods, struct pdb_c 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)); diff --git a/source3/passdb/pdb_plugin.c b/source3/passdb/pdb_plugin.c index ea67da23a55..027cd0b5d33 100644 --- a/source3/passdb/pdb_plugin.c +++ b/source3/passdb/pdb_plugin.c @@ -41,9 +41,11 @@ NTSTATUS pdb_init_plugin(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con 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 ); diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 0acca67b704..111617e3aed 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -766,14 +766,14 @@ static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first) /* 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; @@ -837,7 +837,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) /* 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; @@ -850,7 +850,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) /* 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)) diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index b4a551c1612..4859d785be6 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -2026,7 +2026,7 @@ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info) 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'; } diff --git a/source3/rpc_server/srv_dfs_nt.c b/source3/rpc_server/srv_dfs_nt.c index eba4eaec756..3470ad99b45 100644 --- a/source3/rpc_server/srv_dfs_nt.c +++ b/source3/rpc_server/srv_dfs_nt.c @@ -159,7 +159,7 @@ WERROR _dfs_remove(pipes_struct *p, DFS_Q_DFS_REMOVE *q_u, { 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)) { @@ -257,7 +257,7 @@ static BOOL init_reply_dfs_info_3(TALLOC_CTX *ctx, struct junction_map* j, DFS_I 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) { diff --git a/source3/smbd/chgpasswd.c b/source3/smbd/chgpasswd.c index 0009f09028d..d99570ff7c0 100644 --- a/source3/smbd/chgpasswd.c +++ b/source3/smbd/chgpasswd.c @@ -259,7 +259,7 @@ static int expect(int master, char *issue, char *expected) /* 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; diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index ad107f9c3e1..643e315c069 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -125,7 +125,7 @@ BOOL unix_convert(pstring name,connection_struct *conn,char *saved_last_componen * also trim trailing /'s. */ - trim_string(name,"/","/"); + trim_char(name,'/','/'); /* * If we trimmed down to a single '\0' character @@ -164,7 +164,7 @@ BOOL unix_convert(pstring name,connection_struct *conn,char *saved_last_componen return(True); start = name; - while (strncmp(start,"./",2) == 0) + while (start[0] == '.' && start[1] == '/') start += 2; pstrcpy(orig_path, name); diff --git a/source3/smbd/statcache.c b/source3/smbd/statcache.c index fbebdb240f4..28915a30a08 100644 --- a/source3/smbd/statcache.c +++ b/source3/smbd/statcache.c @@ -66,11 +66,12 @@ void stat_cache_add( const char *full_orig_name, const char *orig_translated_pat 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; /* diff --git a/source3/smbd/utmp.c b/source3/smbd/utmp.c index d57e475ce26..a521d0113d4 100644 --- a/source3/smbd/utmp.c +++ b/source3/smbd/utmp.c @@ -217,13 +217,13 @@ static void uw_pathname(pstring fname, const char *uw_name, const char *uw_defau /* 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 */ diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 58a8a387925..753db4cece3 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -233,10 +233,10 @@ BOOL vfs_init_custom(connection_struct *conn, const char *vfs_object) 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)) || -- 2.34.1