lib/util_str.c

String utilities. [詳細]

ソースコードを見る。

関数

static BOOL next_token_internal (const char **ptr, char *buff, const char *sep, size_t bufsize, BOOL ltrim)
 Internal function to get the next token from a string, return False if none found.
BOOL next_token (const char **ptr, char *buff, const char *sep, size_t bufsize)
BOOL next_token_no_ltrim (const char **ptr, char *buff, const char *sep, size_t bufsize)
BOOL next_token_nr (const char **ptr, char *buff, const char *sep, size_t bufsize)
void set_first_token (char *ptr)
char ** toktocliplist (int *ctok, const char *sep)
 Convert list of tokens to array; dependent on above routine.
int StrCaseCmp (const char *s, const char *t)
 Case insensitive string compararison.
int StrnCaseCmp (const char *s, const char *t, size_t n)
 Case insensitive string compararison, length limited.
BOOL strequal (const char *s1, const char *s2)
 Compare 2 strings.
BOOL strnequal (const char *s1, const char *s2, size_t n)
 Compare 2 strings up to and including the nth char.
BOOL strcsequal (const char *s1, const char *s2)
 Compare 2 strings (case sensitive).
int strwicmp (const char *psz1, const char *psz2)
 Do a case-insensitive, whitespace-ignoring string compare.
char * strupper_static (const char *s)
 Convert a string to upper case, but don't modify it.
void strnorm (char *s, int case_default)
 Convert a string to "normal" form.
BOOL strisnormal (const char *s, int case_default)
 Check if a string is in "normal" case.
void string_replace (char *s, char oldc, char newc)
 String replace.
char * push_skip_string (char *buf)
 Skip past some strings in a buffer - old version - no checks.
char * skip_string (const char *base, size_t len, char *buf)
 Skip past a string in a buffer.
size_t str_charnum (const char *s)
 Count the number of characters in a string.
size_t str_ascii_charnum (const char *s)
 Count the number of characters in a string.
BOOL trim_char (char *s, char cfront, char cback)
BOOL trim_string (char *s, const char *front, const char *back)
 Trim the specified elements off the front and back of a string.
BOOL strhasupper (const char *s)
 Does a string have any uppercase chars in it?
BOOL strhaslower (const char *s)
 Does a string have any lowercase chars in it?
size_t count_chars (const char *s, char c)
 Find the number of 'c' chars in a string
char * safe_strcpy_fn (const char *fn, int line, char *dest, const char *src, size_t maxlength)
 Safe string copy into a known length string.
char * safe_strcat_fn (const char *fn, int line, char *dest, const char *src, size_t maxlength)
 Safe string cat into a string.
char * alpha_strcpy_fn (const char *fn, int line, char *dest, const char *src, const char *other_safe_chars, size_t maxlength)
 Paranoid strcpy into a buffer of given length (includes terminating zero.
char * StrnCpy_fn (const char *fn, int line, char *dest, const char *src, size_t n)
 Like strncpy but always null terminates.
static char * strncpyn (char *dest, const char *src, size_t n, char c)
 Like strncpy but copies up to the character marker.
size_t strhex_to_str (char *p, size_t len, const char *strhex)
 Routine to get hex characters and turn them into a 16 byte array.
DATA_BLOB strhex_to_data_blob (TALLOC_CTX *mem_ctx, const char *strhex)
char * hex_encode (TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len)
 Routine to print a buffer as HEX digits, into an allocated string.
BOOL in_list (const char *s, const char *list, BOOL casesensitive)
 Check if a string is part of a list.
static BOOL string_init (char **dest, const char *src)
 Set a string value, allocing the space for the string
void string_free (char **s)
 Free a string value.
BOOL string_set (char **dest, const char *src)
 Set a string value, deallocating any existing space, and allocing the space for the string
void string_sub2 (char *s, const char *pattern, const char *insert, size_t len, BOOL remove_unsafe_characters, BOOL replace_once, BOOL allow_trailing_dollar)
 Substitute a string for a pattern in another string.
void string_sub_once (char *s, const char *pattern, const char *insert, size_t len)
void string_sub (char *s, const char *pattern, const char *insert, size_t len)
void fstring_sub (char *s, const char *pattern, const char *insert)
void pstring_sub (char *s, const char *pattern, const char *insert)
char * realloc_string_sub (char *string, const char *pattern, const char *insert)
 Similar to string_sub, but it will accept only allocated strings and may realloc them so pay attention at what you pass on no pointers inside strings, no pstrings or const may be passed as string.
char * talloc_string_sub (TALLOC_CTX *mem_ctx, const char *src, const char *pattern, const char *insert)
void all_string_sub (char *s, const char *pattern, const char *insert, size_t len)
 Similar to string_sub() but allows for any character to be substituted.
static smb_ucs2_tall_string_sub_w (const smb_ucs2_t *s, const smb_ucs2_t *pattern, const smb_ucs2_t *insert)
 Similar to all_string_sub but for unicode strings.
smb_ucs2_tall_string_sub_wa (smb_ucs2_t *s, const char *pattern, const char *insert)
static void split_at_last_component (char *path, char *front, char sep, char *back)
 Splits out the front and back at a separator.
const char * octal_string (int i)
 Write an octal as a string.
char * string_truncate (char *s, unsigned int length)
 Truncate a string at a specified length.
char * strchr_m (const char *src, char c)
 Strchr and strrchr_m are very hard to do on general multi-byte strings.
char * strrchr_m (const char *s, char c)
char * strnrchr_m (const char *s, char c, unsigned int n)
char * strstr_m (const char *src, const char *findstr)
void strlower_m (char *s)
 Convert a string to lower case.
void strupper_m (char *s)
 Convert a string to upper case.
size_t strlen_m (const char *s)
 Count the number of UCS2 characters in a string.
size_t strlen_m_term (const char *s)
 Count the number of UCS2 characters in a string including the null terminator.
size_t strlen_m_term_null (const char *s)
char * binary_string_rfc2254 (char *buf, int len)
 Return a RFC2254 binary string representation of a buffer.
char * binary_string (char *buf, int len)
int pstr_sprintf (pstring s, const char *fmt,...)
 Just a typesafety wrapper for snprintf into a pstring.
int fstr_sprintf (fstring s, const char *fmt,...)
 Just a typesafety wrapper for snprintf into a fstring.
static char ** str_list_make_internal (TALLOC_CTX *mem_ctx, const char *string, const char *sep)
char ** str_list_make_talloc (TALLOC_CTX *mem_ctx, const char *string, const char *sep)
char ** str_list_make (const char *string, const char *sep)
BOOL str_list_copy (char ***dest, const char **src)
BOOL str_list_compare (char **list1, char **list2)
 Return true if all the elements of the list match exactly.
static void str_list_free_internal (TALLOC_CTX *mem_ctx, char ***list)
void str_list_free_talloc (TALLOC_CTX *mem_ctx, char ***list)
void str_list_free (char ***list)
int str_list_count (const char **list)
BOOL str_list_sub_basic (char **list, const char *smb_name, const char *domain_name)
BOOL str_list_substitute (char **list, const char *pattern, const char *insert)
char * ipstr_list_add (char **ipstr_list, const struct ip_service *service)
 Add ip string representation to ipstr list.
char * ipstr_list_make (char **ipstr_list, const struct ip_service *ip_list, int ip_count)
 Allocate and initialise an ipstr list using ip adresses passed as arguments.
int ipstr_list_parse (const char *ipstr_list, struct ip_service **ip_list)
 Parse given ip string list into array of ip addresses (as ip_service structures) e.g.
void ipstr_list_free (char *ipstr_list)
 Safely free ip string list
void rfc1738_unescape (char *buf)
 Unescape a URL encoded string, in place.
DATA_BLOB base64_decode_data_blob (const char *s)
 Decode a base64 string into a DATA_BLOB - simple and slow algorithm
void base64_decode_inplace (char *s)
 Decode a base64 string in-place - wrapper for the above
char * base64_encode_data_blob (DATA_BLOB data)
 Encode a base64 string into a malloc()ed string caller to free.
SMB_BIG_UINT STR_TO_SMB_BIG_UINT (const char *nptr, const char **entptr)
SMB_OFF_T conv_str_size (const char *str)
void string_append (char **left, const char *right)
BOOL add_string_to_array (TALLOC_CTX *mem_ctx, const char *str, const char ***strings, int *num)
void sprintf_append (TALLOC_CTX *mem_ctx, char **string, ssize_t *len, size_t *bufsize, const char *fmt,...)
char * sstring_sub (const char *src, char front, char back)
BOOL validate_net_name (const char *name, const char *invalid_chars, int max_len)
size_t ascii_len_n (const char *src, size_t n)
 return the number of bytes occupied by a buffer in ASCII format the result includes the null termination limited by 'n' bytes
size_t utf16_len (const void *buf)
 return the number of bytes occupied by a buffer in CH_UTF16 format the result includes the null termination
size_t utf16_len_n (const void *src, size_t n)
 return the number of bytes occupied by a buffer in CH_UTF16 format the result includes the null termination limited by 'n' bytes
char * escape_shell_string (const char *src)

変数

static const char * last_ptr = NULL
 This is like next_token but is not re-entrant and "remembers" the first parameter so you can pass NULL.
static uint16 tmpbuf [sizeof(pstring)]
static const char * null_string = ""
static const char * b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"


説明

String utilities.

util_str.c で定義されています。


関数

static BOOL next_token_internal ( const char **  ptr,
char *  buff,
const char *  sep,
size_t  bufsize,
BOOL  ltrim 
) [static]

Internal function to get the next token from a string, return False if none found.

Handles double-quotes. This is the work horse function called by next_token() and next_token_no_ltrim().

Based on a routine by GJC@VILLAGE.COM. Extensively modified by Andrew.Tridgell@anu.edu.au

util_str.c40 行で定義されています。

参照先 lenstrchr_m().

参照元 next_token()next_token_no_ltrim().

00045 {
00046         char *s;
00047         char *pbuf;
00048         BOOL quoted;
00049         size_t len=1;
00050 
00051         if (!ptr)
00052                 return(False);
00053 
00054         s = (char *)*ptr;
00055 
00056         /* default to simple separators */
00057         if (!sep)
00058                 sep = " \t\n\r";
00059 
00060         /* find the first non sep char, if left-trimming is requested */
00061         if (ltrim) {
00062                 while (*s && strchr_m(sep,*s))
00063                         s++;
00064         }
00065         
00066         /* nothing left? */
00067         if (! *s)
00068                 return(False);
00069         
00070         /* copy over the token */
00071         pbuf = buff;
00072         for (quoted = False; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) {
00073                 if ( *s == '\"' ) {
00074                         quoted = !quoted;
00075                 } else {
00076                         len++;
00077                         *pbuf++ = *s;
00078                 }
00079         }
00080         
00081         *ptr = (*s) ? s+1 : s;  
00082         *pbuf = 0;
00083         
00084         return(True);
00085 }

BOOL next_token ( const char **  ptr,
char *  buff,
const char *  sep,
size_t  bufsize 
)

util_str.c92 行で定義されています。

参照先 next_token_internal().

参照元 ads_gpo_explode_filesyspath()ads_gpo_prepare_local_store()announce_remote()browse_sync_remote()collect_aliasmem()complete_sync()do_cmd()do_global_checks()dos_attr_parse()fill_grent()get_dc_list()get_server_info()get_user_tokens()getlmhostsent()in_list()init_dom_sid2s()init_registry_data()initialise_wins()internal_resolve_name()ipstr_list_parse()ldapsam_get_seq_num()make_pw_chat()net_copy_driverfile()next_token_nr()one_alias_membership()open_sockets_smbd()parse_ace()parse_lpq_aix()parse_lpq_hpux()parse_lpq_lprng()parse_lpq_plp()parse_lpq_qnx()parse_lpq_sysv()parse_lpq_vlp()parse_usershare_acl()print_domain_groups()print_domain_users()process_cmd()py_enum_domain_groups()py_enum_domain_users()py_enum_trust_dom()reg_split_hive()sam_account_ok()sec_desc_parse()server_cryptkey()set_socket_options()smbc_parse_path()str_list_make_internal()talktochild()wbinfo_list_domains()wbinfo_lookuprids().

00093 {
00094     return next_token_internal(ptr, buff, sep, bufsize, True);
00095 }

BOOL next_token_no_ltrim ( const char **  ptr,
char *  buff,
const char *  sep,
size_t  bufsize 
)

util_str.c102 行で定義されています。

参照先 next_token_internal().

参照元 smbc_parse_path().

00106 {
00107     return next_token_internal(ptr, buff, sep, bufsize, False);
00108 }

BOOL next_token_nr ( const char **  ptr,
char *  buff,
const char *  sep,
size_t  bufsize 
)

util_str.c118 行で定義されています。

参照先 last_ptrnext_token().

参照元 cmd_altname()cmd_archive()cmd_cancel()cmd_cd()cmd_chmod()cmd_chown()cmd_close()cmd_del()cmd_dir()cmd_du()cmd_get()cmd_getfacl()cmd_hardlink()cmd_help()cmd_lcd()cmd_link()cmd_lock()cmd_logon()cmd_mget()cmd_mkdir()cmd_more()cmd_mput()cmd_newer()cmd_open()cmd_posix_mkdir()cmd_posix_open()cmd_posix_rmdir()cmd_posix_unlink()cmd_print()cmd_put()cmd_reget()cmd_rename()cmd_reput()cmd_rmdir()cmd_select()cmd_stat()cmd_symlink()cmd_unlock()cmd_vuid()cmd_wdel()cmd_wks_query_info()process_command_string()process_stdin()writetarheader().

00119 {
00120         BOOL ret;
00121         if (!ptr)
00122                 ptr = &last_ptr;
00123 
00124         ret = next_token(ptr, buff, sep, bufsize);
00125         last_ptr = *ptr;
00126         return ret;     
00127 }

void set_first_token ( char *  ptr  ) 

util_str.c131 行で定義されています。

参照先 last_ptr.

参照元 run_enums_test()run_ntlogin_test().

00132 {
00133         last_ptr = ptr;
00134 }

char** toktocliplist ( int *  ctok,
const char *  sep 
)

Convert list of tokens to array; dependent on above routine.

Uses last_ptr from above - bit of a hack.

util_str.c141 行で定義されています。

参照先 last_ptrstrchr_m().

参照元 writetarheader().

00142 {
00143         char *s=(char *)last_ptr;
00144         int ictok=0;
00145         char **ret, **iret;
00146 
00147         if (!sep)
00148                 sep = " \t\n\r";
00149 
00150         while(*s && strchr_m(sep,*s))
00151                 s++;
00152 
00153         /* nothing left? */
00154         if (!*s)
00155                 return(NULL);
00156 
00157         do {
00158                 ictok++;
00159                 while(*s && (!strchr_m(sep,*s)))
00160                         s++;
00161                 while(*s && strchr_m(sep,*s))
00162                         *s++=0;
00163         } while(*s);
00164         
00165         *ctok=ictok;
00166         s=(char *)last_ptr;
00167         
00168         if (!(ret=iret=SMB_MALLOC_ARRAY(char *,ictok+1)))
00169                 return NULL;
00170         
00171         while(ictok--) {    
00172                 *iret++=s;
00173                 if (ictok > 0) {
00174                         while(*s++)
00175                                 ;
00176                         while(!*s)
00177                                 s++;
00178                 }
00179         }
00180 
00181         ret[*ctok] = NULL;
00182         return ret;
00183 }

int StrCaseCmp ( const char *  s,
const char *  t 
)

Case insensitive string compararison.

iconv does not directly give us a way to compare strings in arbitrary unix character sets -- all we can is convert and then compare. This is expensive.

As an optimization, we do a first pass that considers only the prefix of the strings that is entirely 7-bit. Within this, we check whether they have the same value.

Hopefully this will often give the answer without needing to copy. In particular it should speed comparisons to literal ascii strings or comparisons of strings that are "obviously" different.

If we find a non-ascii character we fall back to converting via iconv.

This should never be slower than convering the whole thing, and often faster.

A different optimization would be to compare for bitwise equality in the binary encoding. (It would be possible thought hairy to do both simultaneously.) But in that case if they turn out to be different, we'd need to restart the whole thing.

Even better is to implement strcasecmp for each encoding and use a function pointer.

util_str.c214 行で定義されています。

参照先 push_ucs2_allocate()sizestrcasecmp_w()toupper_ascii().

参照元 ads_dump_field()cacl_get()check_privilege_for_user()cmd_listcommands()cmd_samr_delete_alias()cmd_samr_enum_als_groups()cmd_samr_lookup_names()cmd_samr_lookup_rids()cmd_samr_query_aliasmem()cmd_samr_query_useraliases()cmd_spoolss_get_short_archi()exact_match()fetch_reg_keys_specific()get_driver_3_param()get_short_archi()getprinterdata_printer_server()hashrec_cmp()in_list()lookup()main()map_regval_to_ads()ms_fnmatch()name_to_fqdn()net_groupmap_list()net_lookup()net_run_function()net_run_function2()pathtree_birth_child()pathtree_find_child()rpc_trustdom_list()rpc_trustdom_vampire()smbc_getxattr_ctx()smbc_removexattr_ctx()smbc_setxattr_ctx()smbldap_make_mod()strequal()usergrp_display()win_election().

00215 {
00216 
00217         const char *ps, *pt;
00218         size_t size;
00219         smb_ucs2_t *buffer_s, *buffer_t;
00220         int ret;
00221 
00222         for (ps = s, pt = t; ; ps++, pt++) {
00223                 char us, ut;
00224 
00225                 if (!*ps && !*pt)
00226                         return 0; /* both ended */
00227                 else if (!*ps)
00228                         return -1; /* s is a prefix */
00229                 else if (!*pt)
00230                         return +1; /* t is a prefix */
00231                 else if ((*ps & 0x80) || (*pt & 0x80))
00232                         /* not ascii anymore, do it the hard way from here on in */
00233                         break;
00234 
00235                 us = toupper_ascii(*ps);
00236                 ut = toupper_ascii(*pt);
00237                 if (us == ut)
00238                         continue;
00239                 else if (us < ut)
00240                         return -1;
00241                 else if (us > ut)
00242                         return +1;
00243         }
00244 
00245         size = push_ucs2_allocate(&buffer_s, ps);
00246         if (size == (size_t)-1) {
00247                 return strcmp(ps, pt); 
00248                 /* Not quite the right answer, but finding the right one
00249                    under this failure case is expensive, and it's pretty close */
00250         }
00251         
00252         size = push_ucs2_allocate(&buffer_t, pt);
00253         if (size == (size_t)-1) {
00254                 SAFE_FREE(buffer_s);
00255                 return strcmp(ps, pt); 
00256                 /* Not quite the right answer, but finding the right one
00257                    under this failure case is expensive, and it's pretty close */
00258         }
00259         
00260         ret = strcasecmp_w(buffer_s, buffer_t);
00261         SAFE_FREE(buffer_s);
00262         SAFE_FREE(buffer_t);
00263         return ret;
00264 }

int StrnCaseCmp ( const char *  s,
const char *  t,
size_t  n 
)

Case insensitive string compararison, length limited.

util_str.c270 行で定義されています。

参照先 unix_strupper().

参照元 alloc_sub_basic()cacl_get()delete_all_printer_data()dos_attr_parse()get_printer_subkeys()get_sid_from_input()get_sid_from_name()main()net_ads_join()net_groupmap_add()net_groupmap_delete()net_groupmap_list()net_groupmap_modify()parse_ace()regkey_open_internal()sec_desc_parse()smbc_getxattr_ctx()smbc_removexattr_ctx()smbc_setxattr_ctx()startsmbfilepwent()strnequal().

00271 {
00272         pstring buf1, buf2;
00273         unix_strupper(s, strlen(s)+1, buf1, sizeof(buf1));
00274         unix_strupper(t, strlen(t)+1, buf2, sizeof(buf2));
00275         return strncmp(buf1,buf2,n);
00276 }

BOOL strequal ( const char *  s1,
const char *  s2 
)

Compare 2 strings.

覚え書き:
The comparison is case-insensitive.

util_str.c283 行で定義されています。

参照先 StrCaseCmp().

参照元 _dfs_Remove()_net_sam_logon_internal()_reg_query_value()_samr_get_dispenum_index()_samr_lookup_domain()_samr_set_aliasinfo()_spoolss_getform()_spoolss_getprinterdata()_spoolss_setprinterdata()_srv_net_sess_del()_srv_net_share_add()_srv_net_share_del()_srv_net_share_set_info()add_a_form()add_afs_ace()add_failed_connection_entry()add_name_to_subnet()add_trusted_domain()ads_check_posix_schema_mapping()ads_cleanup_expired_creds()ads_dc_name()ads_do_paged_search_args()ads_generate_service_principal()ads_get_gpo_list()ads_gpo_prepare_local_store()ads_init()ads_keytab_add_entry()ads_keytab_verify_ticket()ads_ou_string()ads_site_dn_for_machine()ads_sitename_match()afs_set_nt_acl()announce_server()api_pipe_bind_req()api_RNetServerEnum()api_RNetServerGetInfo()api_SamOEMChangePassword()assume_domain()assume_own_realm()call_trans2qfilepathinfo()call_trans2qfsinfo()canonicalize_ea_name()cgi_load_variables()cgi_waspost()check_bind_req()check_bind_response()check_domain_match()check_for_master_browser_fail()check_magic()check_master_browser_exists()check_negative_conn_cache_timeout()check_ntdomain_security()check_samstrict_security()check_share_sanity()check_trustdomain_security()check_winbind_security()child_msg_offline()child_msg_online()cli_check_msdfs_proxy()cli_cm_find()cli_cm_get_mntpoint()cli_cm_set_mntpoint()cli_ns_check_server_type()cli_resolve_path()cli_session_setup_spnego()cmd_help()cmd_print()cmd_seal()cmd_sign()cmd_spoolss_deletedriverex()cmd_spoolss_enum_drivers()cmd_spoolss_setprinterdata()copy_fn()copy_id21_to_sam_passwd()count_fn()create_local_private_krb5_conf_for_domain()create_workgroup()delete_printer_key()display_finfo()do_cd()do_command()do_list_helper()do_mget()dptr_closepath()driver_arch_fetch_values()drv_file_in_use()ea_list_union()elog_open()elog_open_tdb()elog_validate_logname()enum_dom_groups()equal_parameter()eventlog_add_source()expect()fcb_or_dos_open()fetch_domain_info()fetch_reg_values_specific()fill_service_values()fill_share_info()fill_svc_config()fillup_pw_field()find_browser_in_lmb_cache()find_domain_from_name_noinit()find_idmap_domain_from_sid()find_lookup_domain_from_name()find_memory_creds_by_name()find_nss_domain()find_server_in_workgroup()find_service()find_service_by_name()find_valuename_index()find_workgroup_on_subnet()flush_negative_conn_cache_for_domain()fname_equal()generate_krb5_ccache()get_a_builtin_ntform()get_alloc_methods()get_audit_category_from_param()get_ccache_by_username()get_common_service_dispname()get_dc_list()get_dc_name()get_dcs()get_group_map_from_ntname()get_lanman2_dir_entry()get_longvar_val()get_methods()get_print_db_byname()get_printer_subkeys()get_privilege_dispname()get_sec_channel_type()get_server_info()get_share_type()gpo_process_a_gpo()gpo_sync_func()grant_privilege_by_name()guid_string_to_name()idmap_ad_initialize()idmap_init()init_bitmap()init_pipe_handle_list()init_srv_sess_info_1()initiate_myworkgroup_startup()internal_resolve_name()interpret_protocol()is_default()is_executable()is_myname()is_myname_or_ipaddr()is_myworkgroup()is_our_machine_account()is_our_primary_domain()is_owner()is_trusted_domain_situation()key_driver_fetch_keys()key_printers_fetch_keys()ldapsam_delete_entry()list_match()load_usershare_service()lookup_builtin_name()lookup_global_sam_name()lookup_name()lookup_printerkey()lookup_wellknown_name()lp_add_home()lp_enum()lp_set_enum_parm()main()make_connection()make_connection_snum()make_pw_chat()make_user_info_map()manage_ntlm_change_password_1_request()manage_ntlm_server_1_request()mangled_equal()map_filename()map_to_os2_driver()map_username()matchname()move_driver_to_download_area()msg_failed_to_go_online()msg_force_tdis()msg_try_to_go_online()name_to_guid_string()named_pipe()net_ads_join()net_copy_driverfile()net_idmap_secret()net_lookup_dc()net_rap_server()net_sam_do_list()net_sam_policy_set()net_sam_set_pwdmustchangenow()net_sam_set_userflag()net_sh_process()net_status_sessions()net_status_shares()nmb_name_equal()nmbd_message_election()nss_get_backend()nt_open_pipe()only_ipaddrs_in_list()parse_dest()parse_dfs_path()parse_gpttmpl()parse_lpq_aix()parse_lpq_bsd()parse_lpq_hpux()parse_lpq_lprng()parse_lpq_nt()parse_lpq_os2()parse_lpq_plp()parse_lpq_qnx()parse_lpq_sysv()pcap_cache_reload()pcap_printername_ok()pjob_store_notify()popt_common_credentials_callback()print_domain_groups()print_domain_users()print_notify_send_messages_to_printer()printer_driver_files_in_use()printer_driver_in_use()process_announce_request()process_browse_packet()process_cmd()process_dgram()process_election()process_get_backup_list_request()process_host_announce()process_lanman_packet()process_lm_announce_request()process_lm_host_announce()process_name_release_request()process_node_status_request()process_tok()process_workgroup_announce()py_smb_tconx()receive_getdc_response()reg_split_hive()register_name_response()regsubkey_ctr_delkey()regsubkey_ctr_key_exists()regval_ctr_delvalue()regval_ctr_getvalue()regval_ctr_key_exists()rename_internals()rename_internals_fsp()reply_copy()reply_negprot()reply_open_pipe_and_X()reply_spnego_kerberos()resolve_lmhosts()revoke_privilege_by_name()rpc_audit_set_internal()rpc_auth_verifier_chk()rpc_group_list_internals()rpc_printer_migrate_settings_internals()rpc_rights_list_internal()rpc_sh_user_flag_edit_internals()rpc_share_migrate_files_internals()run_test()sam_account_from_delta()sam_account_ok()samba_private_attr_name()samu_set_unix_internal()se_priv_from_name()SearchDir()send_notify2_changes()send_spoolss_notify2_msg()server_cryptkey()set_local_machine_name()set_netbios_aliases()set_printer_hnd_name()set_socket_options()set_user_info_21()set_workgroup_local_master_browser_name()setup_return_cc_name()share_sanity_checks()smb_delete_user()smb_ldap_setup_conn()smb_pam_start()smbc_getatr()smbldap_check_root_dse()smbldap_set_mod()snapin_guid_string_to_name()stored_sitename_changed()string_match()talktochild()test_one()trustdom_recv()unix_wild_match()unlink_internals()unpack_values()update_printer()user_in_list()validate_group()wbinfo_domain_info()wbinfo_lookuprids()winbindd_dual_list_trusted_domains()winbindd_dual_pam_auth_cached()winbindd_getgrnam()winbindd_getpwnam()winbindd_list_groups()winbindd_list_users()winbindd_setpwent_internal()wins_process_name_query_request()write_this_workgroup_name()writetarheader().

00284 {
00285         if (s1 == s2)
00286                 return(True);
00287         if (!s1 || !s2)
00288                 return(False);
00289   
00290         return(StrCaseCmp(s1,s2)==0);
00291 }

BOOL strnequal ( const char *  s1,
const char *  s2,
size_t  n 
)

Compare 2 strings up to and including the nth char.

覚え書き:
The comparison is case-insensitive.

util_str.c298 行で定義されています。

参照先 StrnCaseCmp().

参照元 ads_add_gpo_link()ads_get_gpo()ads_pull_strings_range()cgi_handle_authorization()cgi_setup()cgi_setup_error()check_name_to_ntstatus_security()get_ea_list_from_file()get_ea_value()handle_trans()is_msdfs_link()is_reserved_name()net_ads_gpo_get_gpo()net_usershare_add()parse_quota_set()process_tok()send_backup_list_response()smb_ldap_setup_conn()startsmbfilepwent()strhex_to_str().

00299 {
00300         if (s1 == s2)
00301                 return(True);
00302         if (!s1 || !s2 || !n)
00303                 return(False);
00304   
00305         return(StrnCaseCmp(s1,s2,n)==0);
00306 }

BOOL strcsequal ( const char *  s1,
const char *  s2 
)

Compare 2 strings (case sensitive).

util_str.c312 行で定義されています。

参照元 api_NetWkstaGetInfo()api_RDosPrintJobDel()api_WPrintQueueCtrl()ccache_entry_identical()cli_list_new()reload_nmbd_services()reload_services()reload_services_file()rename_internals()rename_internals_fsp()reply_negprot()str_list_compare()vfs_ChDir().

00313 {
00314         if (s1 == s2)
00315                 return(True);
00316         if (!s1 || !s2)
00317                 return(False);
00318   
00319         return(strcmp(s1,s2)==0);
00320 }

int strwicmp ( const char *  psz1,
const char *  psz2 
)

Do a case-insensitive, whitespace-ignoring string compare.

util_str.c326 行で定義されています。

参照先 toupper_ascii().

参照元 conv_str_size()do_section()dump_a_parameter()get_credentials_file()main()map_parameter()read_credentials_file()service_ok()set_boolean().

00327 {
00328         /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
00329         /* appropriate value. */
00330         if (psz1 == psz2)
00331                 return (0);
00332         else if (psz1 == NULL)
00333                 return (-1);
00334         else if (psz2 == NULL)
00335                 return (1);
00336 
00337         /* sync the strings on first non-whitespace */
00338         while (1) {
00339                 while (isspace((int)*psz1))
00340                         psz1++;
00341                 while (isspace((int)*psz2))
00342                         psz2++;
00343                 if (toupper_ascii(*psz1) != toupper_ascii(*psz2) || *psz1 == '\0'
00344                     || *psz2 == '\0')
00345                         break;
00346                 psz1++;
00347                 psz2++;
00348         }
00349         return (*psz1 - *psz2);
00350 }

char* strupper_static ( const char *  s  ) 

Convert a string to upper case, but don't modify it.

util_str.c357 行で定義されています。

参照先 strupper_m().

参照元 namecache_key()namecache_status_record_key()saf_key()sitename_key()trustdom_cache_key().

00358 {
00359         static pstring str;
00360 
00361         pstrcpy(str, s);
00362         strupper_m(str);
00363 
00364         return str;
00365 }

void strnorm ( char *  s,
int  case_default 
)

Convert a string to "normal" form.

util_str.c371 行で定義されています。

参照先 CASE_UPPERstrlower_m()strupper_m().

参照元 prealloc_open()unix_convert().

00372 {
00373         if (case_default == CASE_UPPER)
00374                 strupper_m(s);
00375         else
00376                 strlower_m(s);
00377 }

BOOL strisnormal ( const char *  s,
int  case_default 
)

Check if a string is in "normal" case.

util_str.c383 行で定義されています。

参照先 CASE_UPPERstrhaslower()strhasupper().

参照元 to_8_3().

00384 {
00385         if (case_default == CASE_UPPER)
00386                 return(!strhaslower(s));
00387         
00388         return(!strhasupper(s));
00389 }

void string_replace ( char *  s,
char  oldc,
char  newc 
)

String replace.

NOTE: oldc and newc must be 7 bit characters

util_str.c401 行で定義されています。

参照先 next_codepoint().

参照元 _srv_net_share_add()_srv_net_share_set_info()api_RNetShareAdd()call_trans2qfilepathinfo()dfs_path_lookup()enum_file_fn()init_mount()init_srv_share_info_2()init_srv_share_info_502()main()notify_fsp()parse_mount_smb()parse_msdfs_symlink()writetarheader().

00402 {
00403         char *p;
00404 
00405         /* this is quite a common operation, so we want it to be
00406            fast. We optimise for the ascii case, knowing that all our
00407            supported multi-byte character sets are ascii-compatible
00408            (ie. they match for the first 128 chars) */
00409 
00410         for (p = s; *p; p++) {
00411                 if (*p & 0x80) /* mb string - slow path. */
00412                         break;
00413                 if (*p == oldc) {
00414                         *p = newc;
00415                 }
00416         }
00417 
00418         if (!*p)
00419                 return;
00420 
00421         /* Slow (mb) path. */
00422 #ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
00423         /* With compose characters we must restart from the beginning. JRA. */
00424         p = s;
00425 #endif
00426 
00427         while (*p) {
00428                 size_t c_size;
00429                 next_codepoint(p, &c_size);
00430 
00431                 if (c_size == 1) {
00432                         if (*p == oldc) {
00433                                 *p = newc;
00434                         }
00435                 }
00436                 p += c_size;
00437         }
00438 }

char* push_skip_string ( char *  buf  ) 

Skip past some strings in a buffer - old version - no checks.

util_str.c444 行で定義されています。

00445 {
00446         buf += strlen(buf) + 1;
00447         return(buf);
00448 }

char* skip_string ( const char *  base,
size_t  len,
char *  buf 
)

Skip past a string in a buffer.

Buffer may not be null terminated. end_ptr points to the first byte after then end of the buffer.

util_str.c456 行で定義されています。

参照元 announce_local_master_browser_to_domain_master_browser()api_DosPrintQEnum()api_DosPrintQGetInfo()api_NetUserGetGroups()api_NetWkstaGetInfo()api_PrintJobInfo()api_RDosPrintJobDel()api_reply()api_RNetGroupEnum()api_RNetGroupGetUsers()api_RNetServerEnum()api_RNetServerGetInfo()api_RNetSessionEnum()api_RNetShareAdd()api_RNetShareEnum()api_RNetShareGetInfo()api_RNetUserEnum()api_RNetUserGetInfo()api_SamOEMChangePassword()api_SetUserPassword()api_WAccessGetUserPerms()api_WPrintDestEnum()api_WPrintDestGetInfo()api_WPrintDriverEnum()api_WPrintJobEnumerate()api_WPrintJobGetInfo()api_WPrintPortEnum()api_WPrintQProcEnum()api_WPrintQueueCtrl()api_WWkstaUserLogon()browse_sync_remote()cli_NetServerEnum()cli_NetWkstaUserLogon()cli_oem_change_password()cli_print_queue()cli_printjob_del()cli_RNetShareEnum()cli_send_mailslot()get_safe_str_ptr()process_lm_host_announce()process_logon_packet()send_backup_list_response()send_election_dgram()send_mailslot().

00457 {
00458         const char *end_ptr = base + len;
00459 
00460         if (end_ptr < base || !base || !buf || buf >= end_ptr) {
00461                 return NULL;
00462         }
00463 
00464         /* Skip the string */
00465         while (*buf) {
00466                 buf++;
00467                 if (buf >= end_ptr) {
00468                         return NULL;
00469                 }
00470         }
00471         /* Skip the '\0' */
00472         buf++;
00473         return buf;
00474 }

size_t str_charnum ( const char *  s  ) 

Count the number of characters in a string.

Normally this will be the same as the number of bytes in a string for single byte strings, but will be different for multibyte.

util_str.c482 行で定義されています。

参照先 push_ucs2()strlen_w().

参照元 change_oem_password()msrpc_gen().

00483 {
00484         uint16 tmpbuf2[sizeof(pstring)];
00485         push_ucs2(NULL, tmpbuf2,s, sizeof(tmpbuf2), STR_TERMINATE);
00486         return strlen_w(tmpbuf2);
00487 }

size_t str_ascii_charnum ( const char *  s  ) 

Count the number of characters in a string.

Normally this will be the same as the number of bytes in a string for single byte strings, but will be different for multibyte.

util_str.c495 行で定義されています。

参照先 push_ascii().

参照元 msrpc_gen().

00496 {
00497         pstring tmpbuf2;
00498         push_ascii(tmpbuf2, s, sizeof(tmpbuf2), STR_TERMINATE);
00499         return strlen(tmpbuf2);
00500 }

BOOL trim_char ( char *  s,
char  cfront,
char  cback 
)

util_str.c502 行で定義されています。

参照先 fptrim_string().

参照元 _dfs_Remove()cli_chkpath()cmd_mkdir()create_msdfs_link()dfs_path_lookup()domain_master_node_status_success()expect()get_domain_master_name_node_status_success()init_names()init_reply_dfs_info_3()load_auth_module()load_msg()lock_path()lp_do_parameter()lp_string()make_pdb_method_name()make_pw_chat()net_sam_provision()parse_dfs_path()parse_lpq_nt()parse_lpq_os2()parse_node_status()parse_usershare_file()pdb_init_ldapsam()pdb_init_ldapsam_compat()pid_path()recycle_unlink()set_local_machine_name()set_remote_machine_name()smb_pam_passchange_conv()sub_set_smb_name()update_a_printer_2()uw_pathname()vfs_init_custom()write_browse_list().

00503 {
00504         BOOL ret = False;
00505         char *ep;
00506         char *fp = s;
00507 
00508         /* Ignore null or empty strings. */
00509         if (!s || (s[0] == '\0'))
00510                 return False;
00511 
00512         if (cfront) {
00513                 while (*fp && *fp == cfront)
00514                         fp++;
00515                 if (!*fp) {
00516                         /* We ate the string. */
00517                         s[0] = '\0';
00518                         return True;
00519                 }
00520                 if (fp != s)
00521                         ret = True;
00522         }
00523 
00524         ep = fp + strlen(fp) - 1;
00525         if (cback) {
00526                 /* Attempt ascii only. Bail for mb strings. */
00527                 while ((ep >= fp) && (*ep == cback)) {
00528                         ret = True;
00529                         if ((ep > fp) && (((unsigned char)ep[-1]) & 0x80)) {
00530                                 /* Could be mb... bail back to tim_string. */
00531                                 char fs[2], bs[2];
00532                                 if (cfront) {
00533                                         fs[0] = cfront;
00534                                         fs[1] = '\0';
00535                                 }
00536                                 bs[0] = cback;
00537                                 bs[1] = '\0';
00538                                 return trim_string(s, cfront ? fs : NULL, bs);
00539                         } else {
00540                                 ep--;
00541                         }
00542                 }
00543                 if (ep < fp) {
00544                         /* We ate the string. */
00545                         s[0] = '\0';
00546                         return True;
00547                 }
00548         }
00549 
00550         ep[1] = '\0';
00551         memmove(s, fp, ep-fp+2);
00552         return ret;
00553 }

BOOL trim_string ( char *  s,
const char *  front,
const char *  back 
)

Trim the specified elements off the front and back of a string.

util_str.c559 行で定義されています。

参照先 len.

参照元 cmd_mput()dos_clean_name()driver_unix_convert()fill_printq_info_52()parse_usershare_file()seek_list()smbc_getatr()trim_char()unix_clean_name()update_a_printer_2().

00560 {
00561         BOOL ret = False;
00562         size_t front_len;
00563         size_t back_len;
00564         size_t len;
00565 
00566         /* Ignore null or empty strings. */
00567         if (!s || (s[0] == '\0'))
00568                 return False;
00569 
00570         front_len       = front? strlen(front) : 0;
00571         back_len        = back? strlen(back) : 0;
00572 
00573         len = strlen(s);
00574 
00575         if (front_len) {
00576                 while (len && strncmp(s, front, front_len)==0) {
00577                         /* Must use memmove here as src & dest can
00578                          * easily overlap. Found by valgrind. JRA. */
00579                         memmove(s, s+front_len, (len-front_len)+1);
00580                         len -= front_len;
00581                         ret=True;
00582                 }
00583         }
00584         
00585         if (back_len) {
00586                 while ((len >= back_len) && strncmp(s+len-back_len,back,back_len)==0) {
00587                         s[len-back_len]='\0';
00588                         len -= back_len;
00589                         ret=True;
00590                 }
00591         }
00592         return ret;
00593 }

BOOL strhasupper ( const char *  s  ) 

Does a string have any uppercase chars in it?

util_str.c599 行で定義されています。

参照先 isupper_w()push_ucs2()tmpbuf.

参照元 pass_check()strisnormal().

00600 {
00601         smb_ucs2_t *ptr;
00602         push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
00603         for(ptr=tmpbuf;*ptr;ptr++)
00604                 if(isupper_w(*ptr))
00605                         return True;
00606         return(False);
00607 }

BOOL strhaslower ( const char *  s  ) 

Does a string have any lowercase chars in it?

util_str.c613 行で定義されています。

参照先 islower_w()push_ucs2()tmpbuf.

参照元 pass_check()strisnormal().

00614 {
00615         smb_ucs2_t *ptr;
00616         push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
00617         for(ptr=tmpbuf;*ptr;ptr++)
00618                 if(islower_w(*ptr))
00619                         return True;
00620         return(False);
00621 }

size_t count_chars ( const char *  s,
char  c 
)

Find the number of 'c' chars in a string

util_str.c627 行で定義されています。

参照先 push_ucs2_allocate().

参照元 ipstr_list_parse()main()net_usershare_add()notify_add()parse_acl_string()parse_usershare_acl().

00628 {
00629         smb_ucs2_t *ptr;
00630         int count;
00631         smb_ucs2_t *alloc_tmpbuf = NULL;
00632 
00633         if (push_ucs2_allocate(&alloc_tmpbuf, s) == (size_t)-1) {
00634                 return 0;
00635         }
00636 
00637         for(count=0,ptr=alloc_tmpbuf;*ptr;ptr++)
00638                 if(*ptr==UCS2_CHAR(c))
00639                         count++;
00640 
00641         SAFE_FREE(alloc_tmpbuf);
00642         return(count);
00643 }

char* safe_strcpy_fn ( const char *  fn,
int  line,
char *  dest,
const char *  src,
size_t  maxlength 
)

Safe string copy into a known length string.

maxlength does not include the terminating zero.

util_str.c650 行で定義されています。

参照先 clobber_region()len.

00651 {
00652         size_t len;
00653 
00654         if (!dest) {
00655                 DEBUG(0,("ERROR: NULL dest in safe_strcpy, called from [%s][%d]\n", fn, line));
00656                 return NULL;
00657         }
00658 
00659 #ifdef DEVELOPER
00660         clobber_region(fn,line,dest, maxlength+1);
00661 #endif
00662 
00663         if (!src) {
00664                 *dest = 0;
00665                 return dest;
00666         }  
00667 
00668         len = strnlen(src, maxlength+1);
00669 
00670         if (len > maxlength) {
00671                 DEBUG(0,("ERROR: string overflow by %lu (%lu - %lu) in safe_strcpy [%.50s]\n",
00672                          (unsigned long)(len-maxlength), (unsigned long)len, 
00673                          (unsigned long)maxlength, src));
00674                 len = maxlength;
00675         }
00676       
00677         memmove(dest, src, len);
00678         dest[len] = 0;
00679         return dest;
00680 }  

char* safe_strcat_fn ( const char *  fn,
int  line,
char *  dest,
const char *  src,
size_t  maxlength 
)

Safe string cat into a string.

maxlength does not include the terminating zero.

util_str.c686 行で定義されています。

参照先 clobber_region().

00687 {
00688         size_t src_len, dest_len;
00689 
00690         if (!dest) {
00691                 DEBUG(0,("ERROR: NULL dest in safe_strcat, called from [%s][%d]\n", fn, line));
00692                 return NULL;
00693         }
00694 
00695         if (!src)
00696                 return dest;
00697         
00698         src_len = strnlen(src, maxlength + 1);
00699         dest_len = strnlen(dest, maxlength + 1);
00700 
00701 #ifdef DEVELOPER
00702         clobber_region(fn, line, dest + dest_len, maxlength + 1 - dest_len);
00703 #endif
00704 
00705         if (src_len + dest_len > maxlength) {
00706                 DEBUG(0,("ERROR: string overflow by %d in safe_strcat [%.50s]\n",
00707                          (int)(src_len + dest_len - maxlength), src));
00708                 if (maxlength > dest_len) {
00709                         memcpy(&dest[dest_len], src, maxlength - dest_len);
00710                 }
00711                 dest[maxlength] = 0;
00712                 return NULL;
00713         }
00714 
00715         memcpy(&dest[dest_len], src, src_len);
00716         dest[dest_len + src_len] = 0;
00717         return dest;
00718 }

char* alpha_strcpy_fn ( const char *  fn,
int  line,
char *  dest,
const char *  src,
const char *  other_safe_chars,
size_t  maxlength 
)

Paranoid strcpy into a buffer of given length (includes terminating 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 !

util_str.c726 行で定義されています。

参照先 clobber_region()islower_ascii()isupper_ascii()lenstrchr_m().

00727 {
00728         size_t len, i;
00729 
00730 #ifdef DEVELOPER
00731         clobber_region(fn, line, dest, maxlength);
00732 #endif
00733 
00734         if (!dest) {
00735                 DEBUG(0,("ERROR: NULL dest in alpha_strcpy, called from [%s][%d]\n", fn, line));
00736                 return NULL;
00737         }
00738 
00739         if (!src) {
00740                 *dest = 0;
00741                 return dest;
00742         }  
00743 
00744         len = strlen(src);
00745         if (len >= maxlength)
00746                 len = maxlength - 1;
00747 
00748         if (!other_safe_chars)
00749                 other_safe_chars = "";
00750 
00751         for(i = 0; i < len; i++) {
00752                 int val = (src[i] & 0xff);
00753                 if (isupper_ascii(val) || islower_ascii(val) || isdigit(val) || strchr_m(other_safe_chars, val))
00754                         dest[i] = src[i];
00755                 else
00756                         dest[i] = '_';
00757         }
00758 
00759         dest[i] = '\0';
00760 
00761         return dest;
00762 }

char* StrnCpy_fn ( const char *  fn,
int  line,
char *  dest,
const char *  src,
size_t  n 
)

Like strncpy but always null terminates.

Make sure there is room! The variable n should always be one less than the available size.

util_str.c768 行で定義されています。

参照先 clobber_region().

00769 {
00770         char *d = dest;
00771 
00772 #ifdef DEVELOPER
00773         clobber_region(fn, line, dest, n+1);
00774 #endif
00775 
00776         if (!dest) {
00777                 DEBUG(0,("ERROR: NULL dest in StrnCpy, called from [%s][%d]\n", fn, line));
00778                 return(NULL);
00779         }
00780 
00781         if (!src) {
00782                 *dest = 0;
00783                 return(dest);
00784         }
00785         
00786         while (n-- && (*d = *src)) {
00787                 d++;
00788                 src++;
00789         }
00790 
00791         *d = 0;
00792         return(dest);
00793 }

static char* strncpyn ( char *  dest,
const char *  src,
size_t  n,
char  c 
) [static]

Like strncpy but copies up to the character marker.

always null terminates. returns a pointer to the character marker in the source string (src).

util_str.c801 行で定義されています。

参照先 clobber_region()strchr_m().

00802 {
00803         char *p;
00804         size_t str_len;
00805 
00806 #ifdef DEVELOPER
00807         clobber_region(dest, n+1);
00808 #endif
00809         p = strchr_m(src, c);
00810         if (p == NULL) {
00811                 DEBUG(5, ("strncpyn: separator character (%c) not found\n", c));
00812                 return NULL;
00813         }
00814 
00815         str_len = PTR_DIFF(p, src);
00816         strncpy(dest, src, MIN(n, str_len));
00817         dest[str_len] = '\0';
00818 
00819         return p;
00820 }

size_t strhex_to_str ( char *  p,
size_t  len,
const char *  strhex 
)

Routine to get hex characters and turn them into a 16 byte array.

the array can be variable length, and any non-hex-numeric characters are skipped. "0xnn" or "0Xnn" is specially catered for.

valid examples: "0A5D15"; "0x15, 0x49, 0xa2"; "59\ta9\te3\n"

util_str.c833 行で定義されています。

参照先 strchr_m()strnequal()toupper_ascii().

参照元 ads_get_sid_from_extended_dn()init_rpc_blob_hex()strhex_to_data_blob().

00834 {
00835         size_t i;
00836         size_t num_chars = 0;
00837         unsigned char   lonybble, hinybble;
00838         const char     *hexchars = "0123456789ABCDEF";
00839         char           *p1 = NULL, *p2 = NULL;
00840 
00841         for (i = 0; i < len && strhex[i] != 0; i++) {
00842                 if (strnequal(hexchars, "0x", 2)) {
00843                         i++; /* skip two chars */
00844                         continue;
00845                 }
00846 
00847                 if (!(p1 = strchr_m(hexchars, toupper_ascii(strhex[i]))))
00848                         break;
00849 
00850                 i++; /* next hex digit */
00851 
00852                 if (!(p2 = strchr_m(hexchars, toupper_ascii(strhex[i]))))
00853                         break;
00854 
00855                 /* get the two nybbles */
00856                 hinybble = PTR_DIFF(p1, hexchars);
00857                 lonybble = PTR_DIFF(p2, hexchars);
00858 
00859                 p[num_chars] = (hinybble << 4) | lonybble;
00860                 num_chars++;
00861 
00862                 p1 = NULL;
00863                 p2 = NULL;
00864         }
00865         return num_chars;
00866 }

DATA_BLOB strhex_to_data_blob ( TALLOC_CTX mem_ctx,
const char *  strhex 
)

util_str.c868 行で定義されています。

参照先 data_blob_::datadata_blob()data_blob_talloc()data_blob_::lengthstrhex_to_str().

参照元 cmd_spoolss_setprinterdata()main()manage_ntlm_change_password_1_request()manage_ntlm_server_1_request().

00869 {
00870         DATA_BLOB ret_blob;
00871 
00872         if (mem_ctx != NULL)
00873                 ret_blob = data_blob_talloc(mem_ctx, NULL, strlen(strhex)/2+1);
00874         else
00875                 ret_blob = data_blob(NULL, strlen(strhex)/2+1);
00876 
00877         ret_blob.length = strhex_to_str((char*)ret_blob.data,   
00878                                         strlen(strhex), 
00879                                         strhex);
00880 
00881         return ret_blob;
00882 }

char* hex_encode ( TALLOC_CTX mem_ctx,
const unsigned char *  buff_in,
size_t  len 
)

Routine to print a buffer as HEX digits, into an allocated string.

util_str.c888 行で定義されています。

参照元 check_auth_crap()display_reg_value()manage_ntlm_server_1_request().

00889 {
00890         int i;
00891         char *hex_buffer;
00892 
00893         hex_buffer = TALLOC_ARRAY(mem_ctx, char, (len*2)+1);
00894 
00895         for (i = 0; i < len; i++)
00896                 slprintf(&hex_buffer[i*2], 3, "%02X", buff_in[i]);
00897 
00898         return hex_buffer;
00899 }

BOOL in_list ( const char *  s,
const char *  list,
BOOL  casesensitive 
)

Check if a string is part of a list.

util_str.c905 行で定義されています。

参照先 next_token()StrCaseCmp().

参照元 add_session_user()call_trans2findfirst()call_trans2findnext()check_share_sanity()ntlmssp_want_feature_list()reply_search().

00906 {
00907         pstring tok;
00908         const char *p=list;
00909 
00910         if (!list)
00911                 return(False);
00912 
00913         while (next_token(&p,tok,LIST_SEP,sizeof(tok))) {
00914                 if (casesensitive) {
00915                         if (strcmp(tok,s) == 0)
00916                                 return(True);
00917                 } else {
00918                         if (StrCaseCmp(tok,s) == 0)
00919                                 return(True);
00920                 }
00921         }
00922         return(False);
00923 }

static BOOL string_init ( char **  dest,
const char *  src 
) [static]

Set a string value, allocing the space for the string

util_str.c932 行で定義されています。

参照先 null_string.

参照元 string_set().

00933 {
00934         size_t l;
00935 
00936         if (!src)     
00937                 src = "";
00938 
00939         l = strlen(src);
00940 
00941         if (l == 0) {
00942                 *dest = CONST_DISCARD(char*, null_string);
00943         } else {
00944                 (*dest) = SMB_STRDUP(src);
00945                 if ((*dest) == NULL) {
00946                         DEBUG(0,("Out of memory in string_init\n"));
00947                         return False;
00948                 }
00949         }
00950         return(True);
00951 }

void string_free ( char **  s  ) 

Free a string value.

util_str.c957 行で定義されています。

参照先 null_string.

参照元 add_a_service()conn_free_internal()copy_service()file_free()FN_LOCAL_PARM_BOOL()free_service()init_globals()lp_do_parameter()print_fsp_end()string_set().

00958 {
00959         if (!s || !(*s))
00960                 return;
00961         if (*s == null_string)
00962                 *s = NULL;
00963         SAFE_FREE(*s);
00964 }

BOOL string_set ( char **  dest,
const char *  src 
)

Set a string value, deallocating any existing space, and allocing the space for the string

util_str.c971 行で定義されています。

参照先 string_free()string_init().

参照元 add_a_service()call_trans2findnext()conn_new()copy_service()dptr_close_internal()dptr_create()dup_file_fsp()file_new()handle_charset()handle_copy()handle_debug_list()handle_idmap_gid()handle_idmap_uid()handle_include()handle_netbios_name()handle_netbios_scope()handle_workgroup()init_globals()init_printer_values()lp_add_home()lp_add_ipc()lp_add_one_printer()lp_add_printer()lp_do_parameter()main()make_connection_snum()msg_file_was_renamed()open_directory()open_fake_file()open_file()open_file_stat()print_fsp_open()process_usershare_file()rename_open_files()reply_search()set_conn_connectpath()vfs_GetWd().

00972 {
00973         string_free(dest);
00974         return(string_init(dest,src));
00975 }

void string_sub2 ( char *  s,
const char *  pattern,
const char *  insert,
size_t  len,
BOOL  remove_unsafe_characters,
BOOL  replace_once,
BOOL  allow_trailing_dollar 
)

Substitute a string for a pattern in another string.

Make sure there is enough room!

This routine looks for pattern in s and replaces it with insert. It may do multiple replacements or just one.

Any of " ; ' $ or ` in the insert string are replaced with _ if len==0 then the string cannot be extended. This is different from the old use of len==0 which was for no length checks to be done.

util_str.c989 行で定義されています。

参照先 strstr_m().

参照元 ldapsam_rename_sam_account()print_queue_update()string_sub()string_sub_once()tdbsam_rename_sam_account().

00991 {
00992         char *p;
00993         ssize_t ls,lp,li, i;
00994 
00995         if (!insert || !pattern || !*pattern || !s)
00996                 return;
00997 
00998         ls = (ssize_t)strlen(s);
00999         lp = (ssize_t)strlen(pattern);
01000         li = (ssize_t)strlen(insert);
01001 
01002         if (len == 0)
01003                 len = ls + 1; /* len is number of *bytes* */
01004 
01005         while (lp <= ls && (p = strstr_m(s,pattern))) {
01006                 if (ls + (li-lp) >= len) {
01007                         DEBUG(0,("ERROR: string overflow by %d in string_sub(%.50s, %d)\n", 
01008                                  (int)(ls + (li-lp) - len),
01009                                  pattern, (int)len));
01010                         break;
01011                 }
01012                 if (li != lp) {
01013                         memmove(p+li,p+lp,strlen(p+lp)+1);
01014                 }
01015                 for (i=0;i<li;i++) {
01016                         switch (insert[i]) {
01017                         case '`':
01018                         case '"':
01019                         case '\'':
01020                         case ';':
01021                         case '$':
01022                                 /* allow a trailing $ (as in machine accounts) */
01023                                 if (allow_trailing_dollar && (i == li - 1 )) {
01024                                         p[i] = insert[i];
01025                                         break;
01026                                 }
01027                         case '%':
01028                         case '\r':
01029                         case '\n':
01030                                 if ( remove_unsafe_characters ) {
01031                                         p[i] = '_';
01032                                         /* yes this break should be here since we want to 
01033                                            fall throw if not replacing unsafe chars */
01034                                         break;
01035                                 }
01036                         default:
01037                                 p[i] = insert[i];
01038                         }
01039                 }
01040                 s = p + li;
01041                 ls += (li-lp);
01042 
01043                 if (replace_once)
01044                         break;
01045         }
01046 }

void string_sub_once ( char *  s,
const char *  pattern,
const char *  insert,
size_t  len 
)

util_str.c1048 行で定義されています。

参照先 string_sub2().

01049 {
01050         string_sub2( s, pattern, insert, len, True, True, False );
01051 }

void string_sub ( char *  s,
const char *  pattern,
const char *  insert,
size_t  len 
)

util_str.c1053 行で定義されています。

参照先 string_sub2().

参照元 cgi_setup()fstring_sub()parse_lpq_aix()parse_lpq_hpux()parse_lpq_plp()parse_lpq_qnx()pstring_sub()reghook_cache_find().

01054 {
01055         string_sub2( s, pattern, insert, len, True, False, False );
01056 }

void fstring_sub ( char *  s,
const char *  pattern,
const char *  insert 
)

util_str.c1058 行で定義されています。

参照先 string_sub().

参照元 pwd_sub().

01059 {
01060         string_sub(s, pattern, insert, sizeof(fstring));
01061 }

void pstring_sub ( char *  s,
const char *  pattern,
const char *  insert 
)

util_str.c1063 行で定義されています。

参照先 string_sub().

参照元 _Insure_trap_error()ads_gpo_explode_filesyspath()afs_login()authorise_login()automount_lookup()chgpasswd()CopyExpanded()create_conn_struct()Expand()generic_job_submit()msg_deliver()normalize_reg_path()print_run_command()regdb_fetch_keys()reghook_cache_add()smb_add_user_group()smb_create_group()smb_delete_group()smb_delete_user_group()StrlenExpanded()try_open().

01064 {
01065         string_sub(s, pattern, insert, sizeof(pstring));
01066 }

char* realloc_string_sub ( char *  string,
const char *  pattern,
const char *  insert 
)

Similar to string_sub, but it will accept only allocated strings and may realloc them so pay attention at what you pass on no pointers inside strings, no pstrings or const may be passed as string.

util_str.c1075 行で定義されています。

参照先 strstr_m().

参照元 alloc_sub_advanced()alloc_sub_basic()realloc_expand_env_var()realloc_expand_longvar().

01077 {
01078         char *p, *in;
01079         char *s;
01080         ssize_t ls,lp,li,ld, i;
01081 
01082         if (!insert || !pattern || !*pattern || !string || !*string)
01083                 return NULL;
01084 
01085         s = string;
01086 
01087         in = SMB_STRDUP(insert);
01088         if (!in) {
01089                 DEBUG(0, ("realloc_string_sub: out of memory!\n"));
01090                 return NULL;
01091         }
01092         ls = (ssize_t)strlen(s);
01093         lp = (ssize_t)strlen(pattern);
01094         li = (ssize_t)strlen(insert);
01095         ld = li - lp;
01096         for (i=0;i<li;i++) {
01097                 switch (in[i]) {
01098                         case '`':
01099                         case '"':
01100                         case '\'':
01101                         case ';':
01102                         case '$':
01103                         case '%':
01104                         case '\r':
01105                         case '\n':
01106                                 in[i] = '_';
01107                         default:
01108                                 /* ok */
01109                                 break;
01110                 }
01111         }
01112         
01113         while ((p = strstr_m(s,pattern))) {
01114                 if (ld > 0) {
01115                         int offset = PTR_DIFF(s,string);
01116                         string = (char *)SMB_REALLOC(string, ls + ld + 1);
01117                         if (!string) {
01118                                 DEBUG(0, ("realloc_string_sub: out of memory!\n"));
01119                                 SAFE_FREE(in);
01120                                 return NULL;
01121                         }
01122                         p = string + offset + (p - s);
01123                 }
01124                 if (li != lp) {
01125                         memmove(p+li,p+lp,strlen(p+lp)+1);
01126                 }
01127                 memcpy(p, in, li);
01128                 s = p + li;
01129                 ls += ld;
01130         }
01131         SAFE_FREE(in);
01132         return string;
01133 }

char* talloc_string_sub ( TALLOC_CTX mem_ctx,
const char *  src,
const char *  pattern,
const char *  insert 
)

util_str.c1137 行で定義されています。

参照先 stringstrstr_m()talloc_strdup().

参照元 find_forced_group()find_forced_user()get_ldap_filter()log_nt_token()talloc_sub_specified()token_contains_name()winbindd_dual_pam_auth().

01139 {
01140         char *p, *in;
01141         char *s;
01142         char *string;
01143         ssize_t ls,lp,li,ld, i;
01144 
01145         if (!insert || !pattern || !*pattern || !src || !*src)
01146                 return NULL;
01147 
01148         string = talloc_strdup(mem_ctx, src);
01149         if (string == NULL) {
01150                 DEBUG(0, ("talloc_strdup failed\n"));
01151                 return NULL;
01152         }
01153 
01154         s = string;
01155 
01156         in = SMB_STRDUP(insert);
01157         if (!in) {
01158                 DEBUG(0, ("talloc_string_sub: out of memory!\n"));
01159                 return NULL;
01160         }
01161         ls = (ssize_t)strlen(s);
01162         lp = (ssize_t)strlen(pattern);
01163         li = (ssize_t)strlen(insert);
01164         ld = li - lp;
01165         for (i=0;i<li;i++) {
01166                 switch (in[i]) {
01167                         case '`':
01168                         case '"':
01169                         case '\'':
01170                         case ';':
01171                         case '$':
01172                         case '%':
01173                         case '\r':
01174                         case '\n':
01175                                 in[i] = '_';
01176                         default:
01177                                 /* ok */
01178                                 break;
01179                 }
01180         }
01181         
01182         while ((p = strstr_m(s,pattern))) {
01183                 if (ld > 0) {
01184                         int offset = PTR_DIFF(s,string);
01185                         string = (char *)TALLOC_REALLOC(mem_ctx, string,
01186                                                         ls + ld + 1);
01187                         if (!string) {
01188                                 DEBUG(0, ("talloc_string_sub: out of "
01189                                           "memory!\n"));
01190                                 SAFE_FREE(in);
01191                                 return NULL;
01192                         }
01193                         p = string + offset + (p - s);
01194                 }
01195                 if (li != lp) {
01196                         memmove(p+li,p+lp,strlen(p+lp)+1);
01197                 }
01198                 memcpy(p, in, li);
01199                 s = p + li;
01200                 ls += ld;
01201         }
01202         SAFE_FREE(in);
01203         return string;
01204 }

void all_string_sub ( char *  s,
const char *  pattern,
const char *  insert,
size_t  len 
)

Similar to string_sub() but allows for any character to be substituted.

Use with caution! if len==0 then the string cannot be extended. This is different from the old use of len==0 which was for no length checks to be done.

util_str.c1213 行で定義されています。

参照先 strstr_m().

参照元 _reg_shutdown_ex()ads_build_domain()chgpasswd()do_cd()dos_clean_name()fetch_account_info()find_service()ldapsam_add_sam_account()ldapsam_search_suffix_by_name()ldapsam_setsampwent()load_msg()main()parse_lpq_aix()parse_lpq_hpux()parse_lpq_plp()parse_lpq_qnx()parse_quota_set()pdb_default_create_user()pwd_sub()run_netbench()smb_create_user()smb_delete_user()smb_set_primary_group()smbc_parse_path()special_char_sub()sync_browse_lists()tstring()unix_clean_name()wins_write_database()ws_name_replace()ws_name_return().

01214 {
01215         char *p;
01216         ssize_t ls,lp,li;
01217 
01218         if (!insert || !pattern || !s)
01219                 return;
01220 
01221         ls = (ssize_t)strlen(s);
01222         lp = (ssize_t)strlen(pattern);
01223         li = (ssize_t)strlen(insert);
01224 
01225         if (!*pattern)
01226                 return;
01227         
01228         if (len == 0)
01229                 len = ls + 1; /* len is number of *bytes* */
01230         
01231         while (lp <= ls && (p = strstr_m(s,pattern))) {
01232                 if (ls + (li-lp) >= len) {
01233                         DEBUG(0,("ERROR: string overflow by %d in all_string_sub(%.50s, %d)\n", 
01234                                  (int)(ls + (li-lp) - len),
01235                                  pattern, (int)len));
01236                         break;
01237                 }
01238                 if (li != lp) {
01239                         memmove(p+li,p+lp,strlen(p+lp)+1);
01240                 }
01241                 memcpy(p, insert, li);
01242                 s = p + li;
01243                 ls += (li-lp);
01244         }
01245 }

static smb_ucs2_t* all_string_sub_w ( const smb_ucs2_t s,
const smb_ucs2_t pattern,
const smb_ucs2_t insert 
) [static]

Similar to all_string_sub but for unicode strings.

Return a new allocated unicode string. similar to string_sub() but allows for any character to be substituted. Use with caution!

util_str.c1254 行で定義されています。

参照先 strlen_w()strstr_w().

参照元 all_string_sub_wa().

01256 {
01257         smb_ucs2_t *r, *rp;
01258         const smb_ucs2_t *sp;
01259         size_t  lr, lp, li, lt;
01260 
01261         if (!insert || !pattern || !*pattern || !s)
01262                 return NULL;
01263 
01264         lt = (size_t)strlen_w(s);
01265         lp = (size_t)strlen_w(pattern);
01266         li = (size_t)strlen_w(insert);
01267 
01268         if (li > lp) {
01269                 const smb_ucs2_t *st = s;
01270                 int ld = li - lp;
01271                 while ((sp = strstr_w(st, pattern))) {
01272                         st = sp + lp;
01273                         lt += ld;
01274                 }
01275         }
01276 
01277         r = rp = SMB_MALLOC_ARRAY(smb_ucs2_t, lt + 1);
01278         if (!r) {
01279                 DEBUG(0, ("all_string_sub_w: out of memory!\n"));
01280                 return NULL;
01281         }
01282 
01283         while ((sp = strstr_w(s, pattern))) {
01284                 memcpy(rp, s, (sp - s));
01285                 rp += ((sp - s) / sizeof(smb_ucs2_t));
01286                 memcpy(rp, insert, (li * sizeof(smb_ucs2_t)));
01287                 s = sp + lp;
01288                 rp += li;
01289         }
01290         lr = ((rp - r) / sizeof(smb_ucs2_t));
01291         if (lr < lt) {
01292                 memcpy(rp, s, ((lt - lr) * sizeof(smb_ucs2_t)));
01293                 rp += (lt - lr);
01294         }
01295         *rp = 0;
01296 
01297         return r;
01298 }

smb_ucs2_t* all_string_sub_wa ( smb_ucs2_t s,
const char *  pattern,
const char *  insert 
)

util_str.c1300 行で定義されています。

参照先 all_string_sub_w()push_ucs2().

01302 {
01303         wpstring p, i;
01304 
01305         if (!insert || !pattern || !s)
01306                 return NULL;
01307         push_ucs2(NULL, p, pattern, sizeof(wpstring) - 1, STR_TERMINATE);
01308         push_ucs2(NULL, i, insert, sizeof(wpstring) - 1, STR_TERMINATE);
01309         return all_string_sub_w(s, p, i);
01310 }

static void split_at_last_component ( char *  path,
char *  front,
char  sep,
char *  back 
) [static]

Splits out the front and back at a separator.

util_str.c1317 行で定義されています。

参照先 strrchr_m().

01318 {
01319         char *p = strrchr_m(path, sep);
01320 
01321         if (p != NULL)
01322                 *p = 0;
01323 
01324         if (front != NULL)
01325                 pstrcpy(front, path);
01326 
01327         if (p != NULL) {
01328                 if (back != NULL)
01329                         pstrcpy(back, p+1);
01330                 *p = '\\';
01331         } else {
01332                 if (back != NULL)
01333                         back[0] = 0;
01334         }
01335 }

const char* octal_string ( int  i  ) 

Write an octal as a string.

util_str.c1342 行で定義されています。

参照元 print_parameter()show_parameter().

01343 {
01344         static char ret[64];
01345         if (i == -1)
01346                 return "-1";
01347         slprintf(ret, sizeof(ret)-1, "0%o", i);
01348         return ret;
01349 }

char* string_truncate ( char *  s,
unsigned int  length 
)

Truncate a string at a specified length.

util_str.c1356 行で定義されています。

参照元 _srv_net_srv_get_info()announce_remote()initiate_myworkgroup_startup()mangle_map()write_browse_list().

01357 {
01358         if (s && strlen(s) > length)
01359                 s[length] = 0;
01360         return s;
01361 }

char* strchr_m ( const char *  src,
char  c 
)

Strchr and strrchr_m are very hard to do on general multi-byte strings.

We convert via ucs2 for now.

util_str.c1368 行で定義されています。

参照先 pull_ucs2_pstring()push_ucs2()strchr_w().

参照元 ads_keytab_add_entry()ads_keytab_create_default()ads_krb5_set_password()ads_pull_username()ads_startup_int()aix_cache_reload()alloc_sub_advanced()alloc_sub_basic()alpha_strcpy_fn()announce_remote()api_DosPrintQGetInfo()Atoic()automount_path()base64_decode_data_blob()cgi_download()cgi_handle_authorization()cgi_load_variables()cgi_setup()check_printer_ok()clean_path()cli_resolve_path()cli_session_setup()cli_session_setup_spnego()connect_one()do_connect()do_connection()encode_krb5_setpw()expand_msdfs_readlink()expand_msdfs_target()FindSectionEnd()get_credentials_file()get_mydnsdomname()get_myname()get_real_name()get_user_and_realm()getlmhostsent()grab_line()interpret_interface()is_ipaddress()is_mangled()is_ntfs_stream_name()kerberos_secrets_store_salting_principal()lookup_name()lookup_name_smbconf()main()make_dir_struct()manage_gss_spnego_request()map_username()ms_fnmatch_lanman_core()name_to_fqdn()net_ads_password()net_lookup_host()net_update_dns_internal()net_usershare_add()new_afs_ace()next_command()next_token_internal()nfs_quotas()only_ipaddrs_in_list()parse_ace()parse_acl_string()parse_afs_acl()parse_dfs_path()parse_lpq_aix()parse_lpq_entry()parse_lpq_hpux()parse_lpq_lprng()parse_lpq_nt()parse_lpq_plp()parse_lpq_sysv()parse_mount_smb()parse_quota_set()pcap_cache_reload()plus_to_space_unescape()popt_common_credentials_callback()print_parameter()process_command_string()put_nmb_name()read_target_host()realloc_expand_env_var()realloc_expand_longvar()reply_spnego_kerberos()reply_tcon_and_X()rfc1738_unescape()set_namearray()set_printer_hnd_name()set_printer_hnd_printertype()set_socket_options()show_parameter()smb_file_rename_information()smb_getpwnam()smbc_parse_path()split_dfs_path()startsmbfilepwent()strhex_to_str()string_match()strncpyn()strstr_m()sys_fgetxattr()sys_fremovexattr()sys_fsetxattr()sys_gethostbyname()sys_getxattr()sys_lgetxattr()sys_lremovexattr()sys_lsetxattr()sys_removexattr()sys_setxattr()sysv_cache_reload()talloc_sub_specified()terminate_path_at_separator()toktocliplist()unpack_values()update_printer()usergrp_display()validate_net_name()vfs_init_custom()wins_hook()writetarheader().

01369 {
01370         wpstring ws;
01371         pstring s2;
01372         smb_ucs2_t *p;
01373         const char *s;
01374 
01375         /* characters below 0x3F are guaranteed to not appear in
01376            non-initial position in multi-byte charsets */
01377         if ((c & 0xC0) == 0) {
01378                 return strchr(src, c);
01379         }
01380 
01381         /* this is quite a common operation, so we want it to be
01382            fast. We optimise for the ascii case, knowing that all our
01383            supported multi-byte character sets are ascii-compatible
01384            (ie. they match for the first 128 chars) */
01385 
01386         for (s = src; *s && !(((unsigned char)s[0]) & 0x80); s++) {
01387                 if (*s == c)
01388                         return (char *)s;
01389         }
01390 
01391         if (!*s)
01392                 return NULL;
01393 
01394 #ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
01395         /* With compose characters we must restart from the beginning. JRA. */
01396         s = src;
01397 #endif
01398 
01399         push_ucs2(NULL, ws, s, sizeof(ws), STR_TERMINATE);
01400         p = strchr_w(ws, UCS2_CHAR(c));
01401         if (!p)
01402                 return NULL;
01403         *p = 0;
01404         pull_ucs2_pstring(s2, ws);
01405         return (char *)(s+strlen(s2));
01406 }

char* strrchr_m ( const char *  s,
char  c 
)

util_str.c1408 行で定義されています。

参照先 lenpull_ucs2_pstring()push_ucs2()strrchr_w().

参照元 _ntsvcs_get_device_reg_property()call_trans2findfirst()call_trans2qfilepathinfo()check_magic()clean_path()cmd_print()copy_file()dfs_path_lookup()do_list_helper()dos_clean_name()dump_core_setup()generic_job_submit()get_lanman2_dir_entry()init_reply_dfs_info_3()is_executable()is_in_path()is_myname_or_ipaddr()main()parent_dirname()parent_dirname_talloc()parse_lpq_aix()parse_lpq_plp()parse_lpq_qnx()reduce_name()reg_test()rename_internals()rename_internals_fsp()reply_copy()reply_ctemp()reply_search()reply_tcon()resolve_wildcards()set_ea_dos_attribute()set_logfile()setup_logging()smb_file_rename_information()smb_set_file_unix_link()split_at_last_component()stat_cache_lookup()unix_clean_name()unix_convert()unlink_internals()writetarheader().

01409 {
01410         /* characters below 0x3F are guaranteed to not appear in
01411            non-initial position in multi-byte charsets */
01412         if ((c & 0xC0) == 0) {
01413                 return strrchr(s, c);
01414         }
01415 
01416         /* this is quite a common operation, so we want it to be
01417            fast. We optimise for the ascii case, knowing that all our
01418            supported multi-byte character sets are ascii-compatible
01419            (ie. they match for the first 128 chars). Also, in Samba
01420            we only search for ascii characters in 'c' and that
01421            in all mb character sets with a compound character
01422            containing c, if 'c' is not a match at position
01423            p, then p[-1] > 0x7f. JRA. */
01424 
01425         {
01426                 size_t len = strlen(s);
01427                 const char *cp = s;
01428                 BOOL got_mb = False;
01429 
01430                 if (len == 0)
01431                         return NULL;
01432                 cp += (len - 1);
01433                 do {
01434                         if (c == *cp) {
01435                                 /* Could be a match. Part of a multibyte ? */
01436                                 if ((cp > s) && (((unsigned char)cp[-1]) & 0x80)) {
01437                                         /* Yep - go slow :-( */
01438                                         got_mb = True;
01439                                         break;
01440                                 }
01441                                 /* No - we have a match ! */
01442                                 return (char *)cp;
01443                         }
01444                 } while (cp-- != s);
01445                 if (!got_mb)
01446                         return NULL;
01447         }
01448 
01449         /* String contained a non-ascii char. Slow path. */
01450         {
01451                 wpstring ws;
01452                 pstring s2;
01453                 smb_ucs2_t *p;
01454 
01455                 push_ucs2(NULL, ws, s, sizeof(ws), STR_TERMINATE);
01456                 p = strrchr_w(ws, UCS2_CHAR(c));
01457                 if (!p)
01458                         return NULL;
01459                 *p = 0;
01460                 pull_ucs2_pstring(s2, ws);
01461                 return (char *)(s+strlen(s2));
01462         }
01463 }

char* strnrchr_m ( const char *  s,
char  c,
unsigned int  n 
)

util_str.c1470 行で定義されています。

参照先 pull_ucs2_pstring()push_ucs2()strnrchr_w().

参照元 stat_cache_lookup().

01471 {
01472         wpstring ws;
01473         pstring s2;
01474         smb_ucs2_t *p;
01475 
01476         push_ucs2(NULL, ws, s, sizeof(ws), STR_TERMINATE);
01477         p = strnrchr_w(ws, UCS2_CHAR(c), n);
01478         if (!p)
01479                 return NULL;
01480         *p = 0;
01481         pull_ucs2_pstring(s2, ws);
01482         return (char *)(s+strlen(s2));
01483 }

char* strstr_m ( const char *  src,
const char *  findstr 
)

util_str.c1489 行で定義されています。

参照先 pull_ucs2_allocate()push_ucs2_allocate()strchr_m()strstr_w().

参照元 aix_cache_reload()all_string_sub()chgpasswd()do_global_checks()dos_clean_name()find_service()main()manage_ntlm_change_password_1_request()manage_ntlm_server_1_request()parse_lpq_entry()pcap_cache_reload()realloc_string_sub()str_list_substitute()string_sub2()talloc_string_sub()unix_clean_name().

01490 {
01491         smb_ucs2_t *p;
01492         smb_ucs2_t *src_w, *find_w;
01493         const char *s;
01494         char *s2;
01495         char *retp;
01496 
01497         size_t findstr_len = 0;
01498 
01499         /* for correctness */
01500         if (!findstr[0]) {
01501                 return (char*)src;
01502         }
01503 
01504         /* Samba does single character findstr calls a *lot*. */
01505         if (findstr[1] == '\0')
01506                 return strchr_m(src, *findstr);
01507 
01508         /* We optimise for the ascii case, knowing that all our
01509            supported multi-byte character sets are ascii-compatible
01510            (ie. they match for the first 128 chars) */
01511 
01512         for (s = src; *s && !(((unsigned char)s[0]) & 0x80); s++) {
01513                 if (*s == *findstr) {
01514                         if (!findstr_len) 
01515                                 findstr_len = strlen(findstr);
01516 
01517                         if (strncmp(s, findstr, findstr_len) == 0) {
01518                                 return (char *)s;
01519                         }
01520                 }
01521         }
01522 
01523         if (!*s)
01524                 return NULL;
01525 
01526 #if 1 /* def BROKEN_UNICODE_COMPOSE_CHARACTERS */
01527         /* 'make check' fails unless we do this */
01528 
01529         /* With compose characters we must restart from the beginning. JRA. */
01530         s = src;
01531 #endif
01532 
01533         if (push_ucs2_allocate(&src_w, src) == (size_t)-1) {
01534                 DEBUG(0,("strstr_m: src malloc fail\n"));
01535                 return NULL;
01536         }
01537         
01538         if (push_ucs2_allocate(&find_w, findstr) == (size_t)-1) {
01539                 SAFE_FREE(src_w);
01540                 DEBUG(0,("strstr_m: find malloc fail\n"));
01541                 return NULL;
01542         }
01543 
01544         p = strstr_w(src_w, find_w);
01545 
01546         if (!p) {
01547                 SAFE_FREE(src_w);
01548                 SAFE_FREE(find_w);
01549                 return NULL;
01550         }
01551         
01552         *p = 0;
01553         if (pull_ucs2_allocate(&s2, src_w) == (size_t)-1) {
01554                 SAFE_FREE(src_w);
01555                 SAFE_FREE(find_w);
01556                 DEBUG(0,("strstr_m: dest malloc fail\n"));
01557                 return NULL;
01558         }
01559         retp = (char *)(s+strlen(s2));
01560         SAFE_FREE(src_w);
01561         SAFE_FREE(find_w);
01562         SAFE_FREE(s2);
01563         return retp;
01564 }

void strlower_m ( char *  s  ) 

Convert a string to lower case.

util_str.c1570 行で定義されています。

参照先 errnolentolower_ascii()unix_strlower().

参照元 _dfs_Remove()_lsa_query_info2()ads_add_service_principal_name()ads_build_domain()ads_guess_service_principal()ads_join_realm()ads_leave_realm()ads_verify_ticket()afs_login()canonicalize_servicename()check_name_to_ntstatus_security()do_get()do_mget()elog_tdbname()fill_domain_username()fill_dsrole_dominfo_basic()fill_sam_account()find_service()get_dc_list()Get_Pwnam_internals()get_real_name()getpwsid_queryuser_recv()init_names()kerberos_standard_des_salt()ldapsam_rename_sam_account()make_connection()make_krb5_skew_error()make_printer_tdbkey()make_printers_secdesc_tdbkey()make_pw_chat()name_to_sid()negprot_spnego()net_ads_changetrustpw()net_rpc_join_newstyle()net_set_machine_spn()net_update_dns()net_usershare_info()net_usershare_list()netdom_join_domain()netdom_leave_domain()new_machine()ntlmssp_server_negotiate()offer_gss_spnego_mechs()parse_lpq_entry()pass_check()pdb_default_create_user()pdb_default_delete_user()process_root()rpc_oldjoin_internals()set_local_machine_name()set_remote_machine_name()strnorm()sub_set_smb_name()tdb_delete_samacct_only()tdb_update_ridrec_only()tdb_update_samacct_only()tdbsam_delete_sam_account()tdbsam_getsampwnam()tdbsam_rename_sam_account()unix_wild_match()user_in_netgroup()winbindd_dual_pam_auth()winbindd_fill_pwent()winbindd_raw_kerberos_login()writetarheader().

01571 {
01572         size_t len;
01573         int errno_save;
01574 
01575         /* this is quite a common operation, so we want it to be
01576            fast. We optimise for the ascii case, knowing that all our
01577            supported multi-byte character sets are ascii-compatible
01578            (ie. they match for the first 128 chars) */
01579 
01580         while (*s && !(((unsigned char)s[0]) & 0x80)) {
01581                 *s = tolower_ascii((unsigned char)*s);
01582                 s++;
01583         }
01584 
01585         if (!*s)
01586                 return;
01587 
01588         /* I assume that lowercased string takes the same number of bytes
01589          * as source string even in UTF-8 encoding. (VIV) */
01590         len = strlen(s) + 1;
01591         errno_save = errno;
01592         errno = 0;
01593         unix_strlower(s,len,s,len);     
01594         /* Catch mb conversion errors that may not terminate. */
01595         if (errno)
01596                 s[len-1] = '\0';
01597         errno = errno_save;
01598 }

void strupper_m ( char *  s  ) 

Convert a string to upper case.

util_str.c1604 行で定義されています。

参照先 errnolentoupper_ascii()unix_strupper().

参照元 _samr_enum_domains()_spoolss_enumprinters()ads_add_service_principal_name()ads_cached_connection()ads_dc_name()ads_guess_service_principal()ads_keytab_create_default()ads_startup_int()ads_try_connect()announce_local_master_browser_to_domain_master_browser()api_NetWkstaGetInfo()api_WWkstaUserLogon()browse_sync_remote()check_name_to_ntstatus_security()cli_NetWkstaUserLogoff()cli_NetWkstaUserLogon()cli_session_setup_spnego()cmd_samr_query_group()cmd_samr_query_groupmem()cmd_samr_query_sec_obj()cmd_samr_query_user()cmd_samr_query_useraliases()cmd_samr_query_usergroups()cmd_spoolss_addform()cmd_spoolss_addprinterex()cmd_spoolss_deletedriver()cmd_spoolss_deleteform()cmd_spoolss_enum_data()cmd_spoolss_enum_data_ex()cmd_spoolss_enum_forms()cmd_spoolss_enum_jobs()cmd_spoolss_enum_printerkey()cmd_spoolss_enum_printers()cmd_spoolss_getdriver()cmd_spoolss_getform()cmd_spoolss_getprinter()cmd_spoolss_getprinterdata()cmd_spoolss_getprinterdataex()cmd_spoolss_getprintprocdir()cmd_spoolss_open_printer_ex()cmd_spoolss_printercmp()cmd_spoolss_rffpcnex()cmd_spoolss_setdriver()cmd_spoolss_setform()cmd_spoolss_setprinter()cmd_spoolss_setprinterdata()cmd_spoolss_setprintername()cmd_wks_query_info()construct_printer_info_7()copy_service()create_browser_in_lmb_cache()create_local_private_krb5_conf_for_domain()create_server_on_workgroup()create_wks_info_100()fill_printdest_info()Get_Pwnam_internals()get_trust_creds()get_user_tokens()idmap_fetch_secret()idmap_store_secret()init_r_trust_dom()lookup_cached_name()lookup_name()lp_do_parameter()main()make_nmb_name()mangle_hash()my_make_nmb_name()name_mangle()name_to_key()name_to_sid()net_rpc_join_newstyle()net_set_machine_spn()normalize_reg_path()parse_domain_user()parse_ntlm_auth_domain_user()parse_wbinfo_domain_user()process_node_status_request()push_ascii()push_utf8()regdb_fetch_keys()rpc_trustdom_add_internals()rpc_trustdom_del_internals()rpc_trustdom_establish()rpc_trustdom_list()rpc_trustdom_revoke()rpccli_spoolss_addprinterdriver()rpccli_spoolss_addprinterex()rpccli_spoolss_deleteprinterdriver()rpccli_spoolss_deleteprinterdriverex()rpccli_spoolss_enum_ports()rpccli_spoolss_enumprinterdrivers()rpccli_spoolss_getprinterdriver()rpccli_spoolss_getprinterdriverdir()rpccli_srvsvc_net_file_close()rpccli_srvsvc_net_file_enum()rpccli_srvsvc_net_remote_tod()rpccli_srvsvc_net_share_add()rpccli_srvsvc_net_share_del()rpccli_srvsvc_net_share_enum()rpccli_srvsvc_net_share_get_info()rpccli_srvsvc_net_share_set_info()rpccli_srvsvc_net_srv_get_info()secrets_fetch_domain_guid()secrets_fetch_domain_sid()secrets_fetch_machine_password()secrets_restore_schannel_session_info()secrets_store_domain_guid()secrets_store_domain_sid()secrets_store_machine_password()secrets_store_schannel_session_info()send_announcement()send_backup_list_response()send_election_dgram()server_cryptkey()set_global_myname()set_global_myname_override()set_global_myworkgroup()set_global_scope()set_my_netbios_names()share_sanity_checks()strnorm()strupper_static()to_8_3()trust_keystr()trustdom_keystr()upcase_name()wcache_save_name_to_sid()winbindd_dual_pam_auth_cached()winbindd_raw_kerberos_login().

01605 {
01606         size_t len;
01607         int errno_save;
01608 
01609         /* this is quite a common operation, so we want it to be
01610            fast. We optimise for the ascii case, knowing that all our
01611            supported multi-byte character sets are ascii-compatible
01612            (ie. they match for the first 128 chars) */
01613 
01614         while (*s && !(((unsigned char)s[0]) & 0x80)) {
01615                 *s = toupper_ascii((unsigned char)*s);
01616                 s++;
01617         }
01618 
01619         if (!*s)
01620                 return;
01621 
01622         /* I assume that lowercased string takes the same number of bytes
01623          * as source string even in multibyte encoding. (VIV) */
01624         len = strlen(s) + 1;
01625         errno_save = errno;
01626         errno = 0;
01627         unix_strupper(s,len,s,len);     
01628         /* Catch mb conversion errors that may not terminate. */
01629         if (errno)
01630                 s[len-1] = '\0';
01631         errno = errno_save;
01632 }

size_t strlen_m ( const char *  s  ) 

Count the number of UCS2 characters in a string.

Normally this will be the same as the number of bytes in a string for single byte strings, but will be different for multibyte.

util_str.c1640 行で定義されています。

参照先 cnext_codepoint().

参照元 strlen_m_term()strlen_m_term_null().

01641 {
01642         size_t count = 0;
01643 
01644         if (!s) {
01645                 return 0;
01646         }
01647 
01648         while (*s && !(((uint8_t)*s) & 0x80)) {
01649                 s++;
01650                 count++;
01651         }
01652 
01653         if (!*s) {
01654                 return count;
01655         }
01656 
01657         while (*s) {
01658                 size_t c_size;
01659                 codepoint_t c = next_codepoint(s, &c_size);
01660                 if (c < 0x10000) {
01661                         /* Unicode char fits into 16 bits. */
01662                         count += 1;
01663                 } else {
01664                         /* Double-width unicode char - 32 bits. */
01665                         count += 2;
01666                 }
01667                 s += c_size;
01668         }
01669 
01670         return count;
01671 }

size_t strlen_m_term ( const char *  s  ) 

Count the number of UCS2 characters in a string including the null terminator.

util_str.c1678 行で定義されています。

参照先 strlen_m().

01679 {
01680         if (!s) {
01681                 return 0;
01682         }
01683         return strlen_m(s) + 1;
01684 }

size_t strlen_m_term_null ( const char *  s  ) 

util_str.c1691 行で定義されています。

参照先 lenstrlen_m().

01692 {
01693         size_t len;
01694         if (!s) {
01695                 return 0;
01696         }
01697         len = strlen_m(s);
01698         if (len == 0) {
01699                 return 0;
01700         }
01701 
01702         return len+1;
01703 }

char* binary_string_rfc2254 ( char *  buf,
int  len 
)

Return a RFC2254 binary string representation of a buffer.

Used in LDAP filters. Caller must free.

util_str.c1710 行で定義されています。

参照元 sid_binstring().

01711 {
01712         char *s;
01713         int i, j;
01714         const char *hex = "0123456789ABCDEF";
01715         s = (char *)SMB_MALLOC(len * 3 + 1);
01716         if (!s)
01717                 return NULL;
01718         for (j=i=0;i<len;i++) {
01719                 s[j] = '\\';
01720                 s[j+1] = hex[((unsigned char)buf[i]) >> 4];
01721                 s[j+2] = hex[((unsigned char)buf[i]) & 0xF];
01722                 j += 3;
01723         }
01724         s[j] = 0;
01725         return s;
01726 }

char* binary_string ( char *  buf,
int  len 
)

util_str.c1728 行で定義されています。

参照元 sid_binstring_hex().

01729 {
01730         char *s;
01731         int i, j;
01732         const char *hex = "0123456789ABCDEF";
01733         s = (char *)SMB_MALLOC(len * 2 + 1);
01734         if (!s)
01735                 return NULL;
01736         for (j=i=0;i<len;i++) {
01737                 s[j]   = hex[((unsigned char)buf[i]) >> 4];
01738                 s[j+1] = hex[((unsigned char)buf[i]) & 0xF];
01739                 j += 2;
01740         }
01741         s[j] = 0;
01742         return s;
01743 }

int pstr_sprintf ( pstring  s,
const char *  fmt,
  ... 
)

Just a typesafety wrapper for snprintf into a pstring.

util_str.c1748 行で定義されています。

参照先 vsnprintf().

参照元 add_new_domain_account_policies()add_new_domain_info()add_new_svc_name()call_trans2qfilepathinfo()cli_check_msdfs_proxy()cli_dfs_make_full_path()cli_resolve_path()cmd_spoolss_printercmp()copy_registry_tree()create_pipe_sock()cups_job_submit()delete_printer_hook()do_del()dump_registry_tree()elog_tdbname()enum_file_fn()eventlog_add_source()eventlog_init_keys()fetch_account_info_to_ldif()fetch_alias_info_to_ldif()fetch_group_info_to_ldif()fetch_groupmem_info_to_ldif()fill_service_values()find_fn()fork_child_dc_connect()form_junctions()get_dc_list()get_device_path()get_parm_translated()ldapsam_add_sam_account()ldapsam_enum_aliasmem()ldapsam_get_seq_num()ldapsam_getgrgid()ldapsam_getgrnam()ldapsam_getgrsid()ldapsam_modify_aliasmem()ldapsam_search_suffix_by_name()ldapsam_search_suffix_by_rid()ldapsam_search_suffix_by_sid()ldapsam_setsamgrent()ldapsam_setsampwent()lp_do_parameter()main()make_printer_tdbkey()make_printers_secdesc_tdbkey()manage_client_krb5_init()manage_gss_spnego_request()map_populate_groups()map_username()offer_gss_spnego_mechs()open_registry_key()pdb_init_tdbsam()popt_common_callback()popt_common_credentials_callback()rcinit_start()rcinit_status()rcinit_stop()read_init_file()reg_load_tree()reg_write_tree()regdb_fetch_values()regdb_store_keys()regdb_store_values()remote_completion()set_logfile()setup_domain_child()smbldap_search_domain_info()svcctl_fetch_regvalues()svcctl_get_secdesc()svcctl_lookup_description()svcctl_lookup_dispname()svcctl_set_secdesc()sync_eventlog_params()terminate()trustdom_keystr()validate_my_share_entries()write_registry_tree()xcvtcp_addport().

01749 {
01750         va_list ap;
01751         int ret;
01752 
01753         va_start(ap, fmt);
01754         ret = vsnprintf(s, PSTRING_LEN, fmt, ap);
01755         va_end(ap);
01756         return ret;
01757 }

int fstr_sprintf ( fstring  s,
const char *  fmt,
  ... 
)

Just a typesafety wrapper for snprintf into a fstring.

util_str.c1764 行で定義されています。

参照先 vsnprintf().

参照元 _net_logon_ctrl2()_reg_shutdown_ex()_samr_set_aliasinfo()add_new_domain_info()add_signature()ads_kinit_password()asn1_read_OID()cache_cleanup_response()cache_retrieve_response()cache_store_response()cli_session_setup_plaintext()cmd_srvsvc_net_remote_tod()counters_directory()create_builtin_administrators()current_version()display_time()do_ccache_ntlm_auth()do_log()dump_regval_type()fetch_cache_seqnum()fill_sam_account()get_common_service_dispname()get_objclass_filter()get_privileges()get_queue_status()get_user_sids()kerberos_standard_des_salt()lib_path()mailslot_name()main()map_nt_printer_info2_to_dsspooler()netsamlogon_clear_cached_user()procid_str_static()quota_str_static()reply_spnego_kerberos()rpccli_net_auth2()rpccli_netlogon_sam_logon()rpccli_netlogon_setup_creds()rpccli_svcctl_open_scm()run_error_map_extract()run_test()send_getdc_request()set_privileges()sid_to_name()smb_getpwnam()store_cache_seqnum()svc_status_string()systime()test_one()traverse_sessionid()trustdom_cache_store_timestamp()unparse_afs_acl()wcache_cached_creds_exist()wcache_remove_oldest_cached_creds().

01765 {
01766         va_list ap;
01767         int ret;
01768 
01769         va_start(ap, fmt);
01770         ret = vsnprintf(s, FSTRING_LEN, fmt, ap);
01771         va_end(ap);
01772         return ret;
01773 }

static char** str_list_make_internal ( TALLOC_CTX mem_ctx,
const char *  string,
const char *  sep 
) [static]

util_str.c1781 行で定義されています。

参照先 list()next_token()str_list_free()talloc_strdup().

参照元 str_list_make()str_list_make_talloc().

01782 {
01783         char **list, **rlist;
01784         const char *str;
01785         char *s;
01786         int num, lsize;
01787         pstring tok;
01788         
01789         if (!string || !*string)
01790                 return NULL;
01791         if (mem_ctx) {
01792                 s = talloc_strdup(mem_ctx, string);
01793         } else {
01794                 s = SMB_STRDUP(string);
01795         }
01796         if (!s) {
01797                 DEBUG(0,("str_list_make: Unable to allocate memory"));
01798                 return NULL;
01799         }
01800         if (!sep) sep = LIST_SEP;
01801         
01802         num = lsize = 0;
01803         list = NULL;
01804         
01805         str = s;
01806         while (next_token(&str, tok, sep, sizeof(tok))) {               
01807                 if (num == lsize) {
01808                         lsize += S_LIST_ABS;
01809                         if (mem_ctx) {
01810                                 rlist = TALLOC_REALLOC_ARRAY(mem_ctx, list, char *, lsize +1);
01811                         } else {
01812                                 /* We need to keep the old list on error so we can free the elements
01813                                    if the realloc fails. */
01814                                 rlist = SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR(list, char *, lsize +1);
01815                         }
01816                         if (!rlist) {
01817                                 DEBUG(0,("str_list_make: Unable to allocate memory"));
01818                                 str_list_free(&list);
01819                                 if (mem_ctx) {
01820                                         TALLOC_FREE(s);
01821                                 } else {
01822                                         SAFE_FREE(s);
01823                                 }
01824                                 return NULL;
01825                         } else {
01826                                 list = rlist;
01827                         }
01828                         memset (&list[num], 0, ((sizeof(char**)) * (S_LIST_ABS +1)));
01829                 }
01830 
01831                 if (mem_ctx) {
01832                         list[num] = talloc_strdup(mem_ctx, tok);
01833                 } else {
01834                         list[num] = SMB_STRDUP(tok);
01835                 }
01836                 
01837                 if (!list[num]) {
01838                         DEBUG(0,("str_list_make: Unable to allocate memory"));
01839                         str_list_free(&list);
01840                         if (mem_ctx) {
01841                                 TALLOC_FREE(s);
01842                         } else {
01843                                 SAFE_FREE(s);
01844                         }
01845                         return NULL;
01846                 }
01847         
01848                 num++;  
01849         }
01850 
01851         if (mem_ctx) {
01852                 TALLOC_FREE(s);
01853         } else {
01854                 SAFE_FREE(s);
01855         }
01856 
01857         return list;
01858 }

char** str_list_make_talloc ( TALLOC_CTX mem_ctx,
const char *  string,
const char *  sep 
)

util_str.c1860 行で定義されています。

参照先 str_list_make_internal().

参照元 ads_parse_gp_ext()ads_parse_gplink().

01861 {
01862         return str_list_make_internal(mem_ctx, string, sep);
01863 }

char** str_list_make ( const char *  string,
const char *  sep 
)

util_str.c1865 行で定義されています。

参照先 str_list_make_internal().

参照元 debug_parse_levels()handle_netbios_aliases()init_globals()lp_do_parameter()lp_parm_string_list()make_auth_context_subsystem()map_username()user_ok()web_set_lang().

01866 {
01867         return str_list_make_internal(NULL, string, sep);
01868 }

BOOL str_list_copy ( char ***  dest,
const char **  src 
)

util_str.c1870 行で定義されています。

参照先 list()str_list_free().

参照元 ads_do_paged_search_args()ads_do_search()copy_service()lp_save_defaults()make_auth_context_subsystem()user_ok().

01871 {
01872         char **list, **rlist;
01873         int num, lsize;
01874         
01875         *dest = NULL;
01876         if (!src)
01877                 return False;
01878         
01879         num = lsize = 0;
01880         list = NULL;
01881                 
01882         while (src[num]) {
01883                 if (num == lsize) {
01884                         lsize += S_LIST_ABS;
01885                         rlist = SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR(list, char *, lsize +1);
01886                         if (!rlist) {
01887                                 DEBUG(0,("str_list_copy: Unable to re-allocate memory"));
01888                                 str_list_free(&list);
01889                                 return False;
01890                         } else {
01891                                 list = rlist;
01892                         }
01893                         memset (&list[num], 0, ((sizeof(char **)) * (S_LIST_ABS +1)));
01894                 }
01895                 
01896                 list[num] = SMB_STRDUP(src[num]);
01897                 if (!list[num]) {
01898                         DEBUG(0,("str_list_copy: Unable to allocate memory"));
01899                         str_list_free(&list);
01900                         return False;
01901                 }
01902 
01903                 num++;
01904         }
01905         
01906         *dest = list;
01907         return True;    
01908 }

BOOL str_list_compare ( char **  list1,
char **  list2 
)

Return true if all the elements of the list match exactly.

util_str.c1913 行で定義されています。

参照先 strcsequal().

参照元 equal_parameter()is_default()show_parameters().

01914 {
01915         int num;
01916         
01917         if (!list1 || !list2)
01918                 return (list1 == list2); 
01919         
01920         for (num = 0; list1[num]; num++) {
01921                 if (!list2[num])
01922                         return False;
01923                 if (!strcsequal(list1[num], list2[num]))
01924                         return False;
01925         }
01926         if (list2[num])
01927                 return False; /* if list2 has more elements than list1 fail */
01928         
01929         return True;
01930 }

static void str_list_free_internal ( TALLOC_CTX mem_ctx,
char ***  list 
) [static]

util_str.c1932 行で定義されています。

参照元 str_list_free()str_list_free_talloc().

01933 {
01934         char **tlist;
01935         
01936         if (!list || !*list)
01937                 return;
01938         tlist = *list;
01939         for(; *tlist; tlist++) {
01940                 if (mem_ctx) {
01941                         TALLOC_FREE(*tlist);
01942                 } else {
01943                         SAFE_FREE(*tlist);
01944                 }
01945         }
01946         if (mem_ctx) {
01947                 TALLOC_FREE(*tlist);
01948         } else {
01949                 SAFE_FREE(*list);
01950         }
01951 }

void str_list_free_talloc ( TALLOC_CTX mem_ctx,
char ***  list 
)

util_str.c1953 行で定義されています。

参照先 str_list_free_internal().

参照元 ads_parse_gplink().

01954 {
01955         str_list_free_internal(mem_ctx, list);
01956 }

void str_list_free ( char ***  list  ) 

util_str.c1958 行で定義されています。

参照先 str_list_free_internal().

参照元 add_a_service()ads_do_paged_search_args()ads_do_search()copy_service()debug_parse_levels()free_service()handle_netbios_aliases()lp_do_parameter()make_auth_context_subsystem()map_username()str_list_copy()str_list_make_internal()user_ok()web_set_lang().

01959 {
01960         str_list_free_internal(NULL, list);
01961 }

int str_list_count ( const char **  list  ) 

util_str.c1966 行で定義されています。

参照元 init_service_op_table().

01967 {
01968         int i = 0;
01969 
01970         if ( ! list )
01971                 return 0;
01972 
01973         /* count the number of list members */
01974         
01975         for ( i=0; *list; i++, list++ );
01976         
01977         return i;
01978 }

BOOL str_list_sub_basic ( char **  list,
const char *  smb_name,
const char *  domain_name 
)

util_str.c1985 行で定義されています。

参照先 alloc_sub_basic().

参照元 user_ok().

01987 {
01988         char *s, *tmpstr;
01989         
01990         while ( *list ) {
01991                 s = *list;
01992                 tmpstr = alloc_sub_basic(smb_name, domain_name, s);
01993                 if ( !tmpstr ) {
01994                         DEBUG(0,("str_list_sub_basic: alloc_sub_basic() return NULL!\n"));
01995                         return False;
01996                 }
01997 
01998                 SAFE_FREE(*list);
01999                 *list = tmpstr;
02000                         
02001                 list++;
02002         }
02003 
02004         return True;
02005 }

BOOL str_list_substitute ( char **  list,
const char *  pattern,
const char *  insert 
)

util_str.c2011 行で定義されています。

参照先 strstr_m()t.

参照元 user_ok().

02012 {
02013         char *p, *s, *t;
02014         ssize_t ls, lp, li, ld, i, d;
02015 
02016         if (!list)
02017                 return False;
02018         if (!pattern)
02019                 return False;
02020         if (!insert)
02021                 return False;
02022 
02023         lp = (ssize_t)strlen(pattern);
02024         li = (ssize_t)strlen(insert);
02025         ld = li -lp;
02026                         
02027         while (*list) {
02028                 s = *list;
02029                 ls = (ssize_t)strlen(s);
02030 
02031                 while ((p = strstr_m(s, pattern))) {
02032                         t = *list;
02033                         d = p -t;
02034                         if (ld) {
02035                                 t = (char *) SMB_MALLOC(ls +ld +1);
02036                                 if (!t) {
02037                                         DEBUG(0,("str_list_substitute: Unable to allocate memory"));
02038                                         return False;
02039                                 }
02040                                 memcpy(t, *list, d);
02041                                 memcpy(t +d +li, p +lp, ls -d -lp +1);
02042                                 SAFE_FREE(*list);
02043                                 *list = t;
02044                                 ls += ld;
02045                                 s = t +d +li;
02046                         }
02047                         
02048                         for (i = 0; i < li; i++) {
02049                                 switch (insert[i]) {
02050                                         case '`':
02051                                         case '"':
02052                                         case '\'':
02053                                         case ';':
02054                                         case '$':
02055                                         case '%':
02056                                         case '\r':
02057                                         case '\n':
02058                                                 t[d +i] = '_';
02059                                                 break;
02060                                         default:
02061                                                 t[d +i] = insert[i];
02062                                 }
02063                         }       
02064                 }
02065                 
02066                 
02067                 list++;
02068         }
02069         
02070         return True;
02071 }

char* ipstr_list_add ( char **  ipstr_list,
const struct ip_service service 
)

Add ip string representation to ipstr list.

Used also as part of ipstr_list_make

引数:
ipstr_list pointer to string containing ip list; MUST BE already allocated and IS reallocated if necessary
ipstr_size pointer to current size of ipstr_list (might be changed as a result of reallocation)
ip IP address which is to be added to list
戻り値:
pointer to string appended with new ip and possibly reallocated to new length

util_str.c2090 行で定義されています。

参照先 asprintf()service.

参照元 ipstr_list_make().

02091 {
02092         char* new_ipstr = NULL;
02093         
02094         /* arguments checking */
02095         if (!ipstr_list || !service) return NULL;
02096 
02097         /* attempt to convert ip to a string and append colon separator to it */
02098         if (*ipstr_list) {
02099                 asprintf(&new_ipstr, "%s%s%s:%d", *ipstr_list, IPSTR_LIST_SEP,
02100                         inet_ntoa(service->ip), service->port);
02101                 SAFE_FREE(*ipstr_list);
02102         } else {
02103                 asprintf(&new_ipstr, "%s:%d", inet_ntoa(service->ip), service->port);
02104         }
02105         *ipstr_list = new_ipstr;
02106         return *ipstr_list;
02107 }

char* ipstr_list_make ( char **  ipstr_list,
const struct ip_service ip_list,
int  ip_count 
)

Allocate and initialise an ipstr list using ip adresses passed as arguments.

引数:
ipstr_list pointer to string meant to be allocated and set
ip_list array of ip addresses to place in the list
ip_count number of addresses stored in ip_list
戻り値:
pointer to allocated ip string

util_str.c2120 行で定義されています。

参照先 ipstr_list_add().

参照元 namecache_store().

02121 {
02122         int i;
02123         
02124         /* arguments checking */
02125         if (!ip_list || !ipstr_list) return 0;
02126 
02127         *ipstr_list = NULL;
02128         
02129         /* process ip addresses given as arguments */
02130         for (i = 0; i < ip_count; i++)
02131                 *ipstr_list = ipstr_list_add(ipstr_list, &ip_list[i]);
02132         
02133         return (*ipstr_list);
02134 }

int ipstr_list_parse ( const char *  ipstr_list,
struct ip_service **  ip_list 
)

Parse given ip string list into array of ip addresses (as ip_service structures) e.g.

192.168.1.100:389,192.168.1.78, ...

引数:
ipstr ip string list to be parsed
ip_list pointer to array of ip addresses which is allocated by this function and must be freed by caller
戻り値:
number of successfully parsed addresses

util_str.c2148 行で定義されています。

参照先 count_chars()next_token()port.

参照元 namecache_fetch().

02149 {
02150         fstring token_str;
02151         size_t count;
02152         int i;
02153 
02154         if (!ipstr_list || !ip_list) 
02155                 return 0;
02156         
02157         count = count_chars(ipstr_list, IPSTR_LIST_CHAR) + 1;
02158         if ( (*ip_list = SMB_MALLOC_ARRAY(struct ip_service, count)) == NULL ) {
02159                 DEBUG(0,("ipstr_list_parse: malloc failed for %lu entries\n", (unsigned long)count));
02160                 return 0;
02161         }
02162         
02163         for ( i=0; 
02164                 next_token(&ipstr_list, token_str, IPSTR_LIST_SEP, FSTRING_LEN) && i<count; 
02165                 i++ ) 
02166         {
02167                 struct in_addr addr;
02168                 unsigned port = 0;      
02169                 char *p = strchr(token_str, ':');
02170                 
02171                 if (p) {
02172                         *p = 0;
02173                         port = atoi(p+1);
02174                 }
02175 
02176                 /* convert single token to ip address */
02177                 if ( (addr.s_addr = inet_addr(token_str)) == INADDR_NONE )
02178                         break;
02179                                 
02180                 (*ip_list)[i].ip = addr;
02181                 (*ip_list)[i].port = port;
02182         }
02183         
02184         return count;
02185 }

void ipstr_list_free ( char *  ipstr_list  ) 

Safely free ip string list

引数:
ipstr_list ip string list to be freed

util_str.c2194 行で定義されています。

02195 {
02196         SAFE_FREE(ipstr_list);
02197 }

void rfc1738_unescape ( char *  buf  ) 

Unescape a URL encoded string, in place.

util_str.c2204 行で定義されています。

参照先 strchr_m().

参照元 cgi_load_variables()manage_squid_basic_request()uri_unescape_alloc().

02205 {
02206         char *p=buf;
02207 
02208         while (p && *p && (p=strchr_m(p,'%'))) {
02209                 int c1 = p[1];
02210                 int c2 = p[2];
02211 
02212                 if (c1 >= '0' && c1 <= '9')
02213                         c1 = c1 - '0';
02214                 else if (c1 >= 'A' && c1 <= 'F')
02215                         c1 = 10 + c1 - 'A';
02216                 else if (c1 >= 'a' && c1 <= 'f')
02217                         c1 = 10 + c1 - 'a';
02218                 else {p++; continue;}
02219 
02220                 if (c2 >= '0' && c2 <= '9')
02221                         c2 = c2 - '0';
02222                 else if (c2 >= 'A' && c2 <= 'F')
02223                         c2 = 10 + c2 - 'A';
02224                 else if (c2 >= 'a' && c2 <= 'f')
02225                         c2 = 10 + c2 - 'a';
02226                 else {p++; continue;}
02227                         
02228                 *p = (c1<<4) | c2;
02229 
02230                 memmove(p+1, p+3, strlen(p+3)+1);
02231                 p++;
02232         }
02233 }

DATA_BLOB base64_decode_data_blob ( const char *  s  ) 

Decode a base64 string into a DATA_BLOB - simple and slow algorithm

util_str.c2240 行で定義されています。

参照先 b64data_blob_::datadata_blob()data_blob_::lengthstrchr_m().

参照元 afs_decode_token()base64_decode_inplace()init_sam_user_info20A()init_sam_user_info21A()init_sam_user_info23A()manage_client_ntlmssp_request()manage_gss_spnego_client_request()manage_gss_spnego_request()manage_squid_ntlmssp_request().

02241 {
02242         int bit_offset, byte_offset, idx, i, n;
02243         DATA_BLOB decoded = data_blob(s, strlen(s)+1);
02244         unsigned char *d = decoded.data;
02245         char *p;
02246 
02247         n=i=0;
02248 
02249         while (*s && (p=strchr_m(b64,*s))) {
02250                 idx = (int)(p - b64);
02251                 byte_offset = (i*6)/8;
02252                 bit_offset = (i*6)%8;
02253                 d[byte_offset] &= ~((1<<(8-bit_offset))-1);
02254                 if (bit_offset < 3) {
02255                         d[byte_offset] |= (idx << (2-bit_offset));
02256                         n = byte_offset+1;
02257                 } else {
02258                         d[byte_offset] |= (idx >> (bit_offset-2));
02259                         d[byte_offset+1] = 0;
02260                         d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF;
02261                         n = byte_offset+2;
02262                 }
02263                 s++; i++;
02264         }
02265 
02266         if ((n > 0) && (*s == '=')) {
02267                 n -= 1;
02268         }
02269 
02270         /* fix up length */
02271         decoded.length = n;
02272         return decoded;
02273 }

void base64_decode_inplace ( char *  s  ) 

Decode a base64 string in-place - wrapper for the above

util_str.c2278 行で定義されています。

参照先 base64_decode_data_blob()data_blob_::datadata_blob_free()data_blob_::length.

参照元 cgi_handle_authorization()manage_ntlm_change_password_1_request()manage_ntlm_server_1_request().

02279 {
02280         DATA_BLOB decoded = base64_decode_data_blob(s);
02281 
02282         if ( decoded.length != 0 ) {
02283                 memcpy(s, decoded.data, decoded.length);
02284 
02285                 /* null terminate */
02286                 s[decoded.length] = '\0';
02287         } else {
02288                 *s = '\0';
02289         }
02290 
02291         data_blob_free(&decoded);
02292 }

char* base64_encode_data_blob ( DATA_BLOB  data  ) 

Encode a base64 string into a malloc()ed string caller to free.

From SQUID: adopted from http://ftp.sunet.se/pub2/gnu/vm/base64-encode.c with adjustments

util_str.c2299 行で定義されています。

参照先 b64cdata_blob_::datalendata_blob_::lengthresult.

参照元 afs_encode_token()copy_id20_to_sam_passwd()copy_id21_to_sam_passwd()copy_id23_to_sam_passwd()copy_id25_to_sam_passwd()fprintf_attr()manage_client_krb5_init()manage_client_ntlmssp_init()manage_client_ntlmssp_request()manage_client_ntlmssp_targ()manage_gss_spnego_request()manage_squid_ntlmssp_request()offer_gss_spnego_mechs()sam_account_from_delta().

02300 {
02301         int bits = 0;
02302         int char_count = 0;
02303         size_t out_cnt, len, output_len;
02304         char *result;
02305 
02306         if (!data.length || !data.data)
02307                 return NULL;
02308 
02309         out_cnt = 0;
02310         len = data.length;
02311         output_len = data.length * 2 + 4; /* Account for closing bytes. 4 is
02312                                            * random but should be enough for
02313                                            * the = and \0 */
02314         result = (char *)SMB_MALLOC(output_len); /* get us plenty of space */
02315 
02316         while (len-- && out_cnt < (data.length * 2) - 5) {
02317                 int c = (unsigned char) *(data.data++);
02318                 bits += c;
02319                 char_count++;
02320                 if (char_count == 3) {
02321                         result[out_cnt++] = b64[bits >> 18];
02322                         result[out_cnt++] = b64[(bits >> 12) & 0x3f];
02323                         result[out_cnt++] = b64[(bits >> 6) & 0x3f];
02324             result[out_cnt++] = b64[bits & 0x3f];
02325             bits = 0;
02326             char_count = 0;
02327         } else {
02328             bits <<= 8;
02329         }
02330     }
02331     if (char_count != 0) {
02332         bits <<= 16 - (8 * char_count);
02333         result[out_cnt++] = b64[bits >> 18];
02334         result[out_cnt++] = b64[(bits >> 12) & 0x3f];
02335         if (char_count == 1) {
02336             result[out_cnt++] = '=';
02337             result[out_cnt++] = '=';
02338         } else {
02339             result[out_cnt++] = b64[(bits >> 6) & 0x3f];
02340             result[out_cnt++] = '=';
02341         }
02342     }
02343     result[out_cnt] = '\0';     /* terminate */
02344     return result;
02345 }

SMB_BIG_UINT STR_TO_SMB_BIG_UINT ( const char *  nptr,
const char **  entptr 
)

util_str.c2348 行で定義されています。

参照元 command_get_quota()sys_disk_free().

02349 {
02350 
02351         SMB_BIG_UINT val = -1;
02352         const char *p = nptr;
02353         
02354         if (!p) {
02355                 if (entptr) {
02356                         *entptr = p;
02357                 }
02358                 return val;
02359         }
02360 
02361         while (*p && isspace(*p))
02362                 p++;
02363 
02364 #ifdef LARGE_SMB_OFF_T
02365         sscanf(p,"%llu",&val);  
02366 #else /* LARGE_SMB_OFF_T */
02367         sscanf(p,"%lu",&val);
02368 #endif /* LARGE_SMB_OFF_T */
02369         if (entptr) {
02370                 while (*p && isdigit(*p))
02371                         p++;
02372                 *entptr = p;
02373         }
02374 
02375         return val;
02376 }

SMB_OFF_T conv_str_size ( const char *  str  ) 

util_str.c2389 行で定義されています。

参照先 strwicmp().

参照元 commit_open()cprime_connect()prealloc_open()readahead_connect()recycle_maxsize()recycle_minsize().

02390 {
02391         SMB_OFF_T lval;
02392         char * end;
02393 
02394         if (str == NULL || *str == '\0') {
02395                 return 0;
02396         }
02397 
02398 #ifdef HAVE_STRTOULL
02399         if (sizeof(SMB_OFF_T) == 8) {
02400             lval = strtoull(str, &end, 10 /* base */);
02401         } else {
02402             lval = strtoul(str, &end, 10 /* base */);
02403         }
02404 #else
02405         lval = strtoul(str, &end, 10 /* base */);
02406 #endif
02407 
02408         if (end == NULL || end == str) {
02409                 return 0;
02410         }
02411 
02412         if (*end) {
02413                 SMB_OFF_T lval_orig = lval;
02414 
02415                 if (strwicmp(end, "K") == 0) {
02416                         lval *= (SMB_OFF_T)1024;
02417                 } else if (strwicmp(end, "M") == 0) {
02418                         lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024);
02419                 } else if (strwicmp(end, "G") == 0) {
02420                         lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
02421                                 (SMB_OFF_T)1024);
02422                 } else if (strwicmp(end, "T") == 0) {
02423                         lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
02424                                 (SMB_OFF_T)1024 * (SMB_OFF_T)1024);
02425                 } else if (strwicmp(end, "P") == 0) {
02426                         lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
02427                                 (SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
02428                                 (SMB_OFF_T)1024);
02429                 } else {
02430                         return 0;
02431                 }
02432 
02433                 /* Primitive attempt to detect wrapping on platforms with
02434                  * 4-byte SMB_OFF_T. It's better to let the caller handle
02435                  * a failure than some random number.
02436                  */
02437                 if (lval_orig <= lval) {
02438                         return 0;
02439                 }
02440         }
02441 
02442         return lval;
02443 }

void string_append ( char **  left,
const char *  right 
)

util_str.c2445 行で定義されています。

参照元 add_member()cli_resolve_path().

02446 {
02447         int new_len = strlen(right) + 1;
02448 
02449         if (*left == NULL) {
02450                 *left = (char *)SMB_MALLOC(new_len);
02451                 *left[0] = '\0';
02452         } else {
02453                 new_len += strlen(*left);
02454                 *left = (char *)SMB_REALLOC(*left, new_len);
02455         }
02456 
02457         if (*left == NULL) {
02458                 return;
02459         }
02460 
02461         safe_strcat(*left, right, new_len-1);
02462 }

BOOL add_string_to_array ( TALLOC_CTX mem_ctx,
const char *  str,
const char ***  strings,
int *  num 
)

util_str.c2464 行で定義されています。

参照先 talloc_strdup().

参照元 find_new_dc()init_r_enum_acct_rights().

02467 {
02468         char *dup_str = talloc_strdup(mem_ctx, str);
02469 
02470         *strings = TALLOC_REALLOC_ARRAY(mem_ctx, *strings, const char *, (*num)+1);
02471 
02472         if ((*strings == NULL) || (dup_str == NULL)) {
02473                 *num = 0;
02474                 return False;
02475         }
02476 
02477         (*strings)[*num] = dup_str;
02478         *num += 1;
02479         return True;
02480 }

void sprintf_append ( TALLOC_CTX mem_ctx,
char **  string,
ssize_t *  len,
size_t *  bufsize,
const char *  fmt,
  ... 
)

util_str.c2486 行で定義されています。

参照先 errorvasprintf().

参照元 main()msg_pool_usage_helper()print_sidlist()winbind_lookup_rids()winbindd_dual_lookuprids().

02488 {
02489         va_list ap;
02490         char *newstr;
02491         int ret;
02492         BOOL increased;
02493 
02494         /* len<0 is an internal marker that something failed */
02495         if (*len < 0)
02496                 goto error;
02497 
02498         if (*string == NULL) {
02499                 if (*bufsize == 0)
02500                         *bufsize = 128;
02501 
02502                 *string = TALLOC_ARRAY(mem_ctx, char, *bufsize);
02503                 if (*string == NULL)
02504                         goto error;
02505         }
02506 
02507         va_start(ap, fmt);
02508         ret = vasprintf(&newstr, fmt, ap);
02509         va_end(ap);
02510 
02511         if (ret < 0)
02512                 goto error;
02513 
02514         increased = False;
02515 
02516         while ((*len)+ret >= *bufsize) {
02517                 increased = True;
02518                 *bufsize *= 2;
02519                 if (*bufsize >= (1024*1024*256))
02520                         goto error;
02521         }
02522 
02523         if (increased) {
02524                 *string = TALLOC_REALLOC_ARRAY(mem_ctx, *string, char,
02525                                                *bufsize);
02526                 if (*string == NULL) {
02527                         goto error;
02528                 }
02529         }
02530 
02531         StrnCpy((*string)+(*len), newstr, ret);
02532         (*len) += ret;
02533         free(newstr);
02534         return;
02535 
02536  error:
02537         *len = -1;
02538         *string = NULL;
02539 }

char* sstring_sub ( const char *  src,
char  front,
char  back 
)

util_str.c2547 行で定義されています。

参照先 len.

参照元 fetch_account_info_to_ldif()fetch_alias_info_to_ldif()fetch_group_info_to_ldif()map_populate_groups()populate_ldap_for_ldif().

02548 {
02549         char *temp1, *temp2, *temp3;
02550         ptrdiff_t len;
02551 
02552         temp1 = strchr(src, front);
02553         if (temp1 == NULL) return NULL;
02554         temp2 = strchr(src, back);
02555         if (temp2 == NULL) return NULL;
02556         len = temp2 - temp1;
02557         if (len <= 0) return NULL;
02558         temp3 = (char*)SMB_MALLOC(len);
02559         if (temp3 == NULL) {
02560                 DEBUG(1,("Malloc failure in sstring_sub\n"));
02561                 return NULL;
02562         }
02563         memcpy(temp3, temp1+1, len-1);
02564         temp3[len-1] = '\0';
02565         return temp3;
02566 }

BOOL validate_net_name ( const char *  name,
const char *  invalid_chars,
int  max_len 
)

util_str.c2573 行で定義されています。

参照先 strchr_m().

参照元 _srv_net_name_validate()_srv_net_share_add()count_num_usershares()get_share_list()net_usershare_add()net_usershare_delete()process_usershare_file().

02574 {
02575         int i;
02576 
02577         for ( i=0; i<max_len && name[i]; i++ ) {
02578                 /* fail if strchr_m() finds one of the invalid characters */
02579                 if ( name[i] && strchr_m( invalid_chars, name[i] ) ) {
02580                         return False;
02581                 }
02582         }
02583 
02584         return True;
02585 }

size_t ascii_len_n ( const char *  src,
size_t  n 
)

return the number of bytes occupied by a buffer in ASCII format the result includes the null termination limited by 'n' bytes

util_str.c2593 行で定義されています。

参照先 len.

参照元 ndr_pull_string().

02594 {
02595         size_t len;
02596 
02597         len = strnlen(src, n);
02598         if (len+1 <= n) {
02599                 len += 1;
02600         }
02601 
02602         return len;
02603 }

size_t utf16_len ( const void *  buf  ) 

return the number of bytes occupied by a buffer in CH_UTF16 format the result includes the null termination

util_str.c2609 行で定義されています。

参照先 len.

02610 {
02611         size_t len;
02612 
02613         for (len = 0; SVAL(buf,len); len += 2) ;
02614 
02615         return len + 2;
02616 }

size_t utf16_len_n ( const void *  src,
size_t  n 
)

return the number of bytes occupied by a buffer in CH_UTF16 format the result includes the null termination limited by 'n' bytes

util_str.c2623 行で定義されています。

参照先 len.

参照元 ndr_pull_string().

02624 {
02625         size_t len;
02626 
02627         for (len = 0; (len+2 < n) && SVAL(src, len); len += 2) ;
02628 
02629         if (len+2 <= n) {
02630                 len += 2;
02631         }
02632 
02633         return len;
02634 }

char* escape_shell_string ( const char *  src  ) 

util_str.c2644 行で定義されています。

参照先 cnext_codepoint().

参照元 smbrun_internal().

02645 {
02646         size_t srclen = strlen(src);
02647         char *ret = SMB_MALLOC((srclen * 2) + 1);
02648         char *dest = ret;
02649         BOOL in_s_quote = False;
02650         BOOL in_d_quote = False;
02651         BOOL next_escaped = False;
02652 
02653         if (!ret) {
02654                 return NULL;
02655         }
02656 
02657         while (*src) {
02658                 size_t c_size;
02659                 codepoint_t c = next_codepoint(src, &c_size);
02660 
02661                 if (c == INVALID_CODEPOINT) {
02662                         SAFE_FREE(ret);
02663                         return NULL;
02664                 }
02665 
02666                 if (c_size > 1) {
02667                         memcpy(dest, src, c_size);
02668                         src += c_size;
02669                         dest += c_size;
02670                         next_escaped = False;
02671                         continue;
02672                 }
02673 
02674                 /*
02675                  * Deal with backslash escaped state.
02676                  * This only lasts for one character.
02677                  */
02678 
02679                 if (next_escaped) {
02680                         *dest++ = *src++;
02681                         next_escaped = False;
02682                         continue;
02683                 }
02684 
02685                 /*
02686                  * Deal with single quote state. The
02687                  * only thing we care about is exiting
02688                  * this state.
02689                  */
02690 
02691                 if (in_s_quote) {
02692                         if (*src == '\'') {
02693                                 in_s_quote = False;
02694                         }
02695                         *dest++ = *src++;
02696                         continue;
02697                 }
02698 
02699                 /* 
02700                  * Deal with double quote state. The most
02701                  * complex state. We must cope with \, meaning
02702                  * possibly escape next char (depending what it
02703                  * is), ", meaning exit this state, and possibly
02704                  * add an \ escape to any unprotected character
02705                  * (listed in INSIDE_DQUOTE_LIST).
02706                  */
02707 
02708                 if (in_d_quote) {
02709                         if (*src == '\\') {
02710                                 /* 
02711                                  * Next character might be escaped.
02712                                  * We have to peek. Inside double
02713                                  * quotes only INSIDE_DQUOTE_LIST
02714                                  * characters are escaped by a \.
02715                                  */
02716 
02717                                 char nextchar;
02718 
02719                                 c = next_codepoint(&src[1], &c_size);
02720                                 if (c == INVALID_CODEPOINT) {
02721                                         SAFE_FREE(ret);
02722                                         return NULL;
02723                                 }
02724                                 if (c_size > 1) {
02725                                         /*
02726                                          * Don't escape the next char.
02727                                          * Just copy the \.
02728                                          */
02729                                         *dest++ = *src++;
02730                                         continue;
02731                                 }
02732 
02733                                 nextchar = src[1];
02734 
02735                                 if (nextchar && strchr(INSIDE_DQUOTE_LIST, (int)nextchar)) {
02736                                         next_escaped = True;
02737                                 }
02738                                 *dest++ = *src++;
02739                                 continue;
02740                         }
02741 
02742                         if (*src == '\"') {
02743                                 /* Exit double quote state. */
02744                                 in_d_quote = False;
02745                                 *dest++ = *src++;
02746                                 continue;
02747                         }
02748 
02749                         /*
02750                          * We know the character isn't \ or ",
02751                          * so escape it if it's any of the other
02752                          * possible unprotected characters.
02753                          */
02754 
02755                         if (strchr(INSIDE_DQUOTE_LIST, (int)*src)) {
02756                                 *dest++ = '\\';
02757                         }
02758                         *dest++ = *src++;
02759                         continue;
02760                 }
02761 
02762                 /* 
02763                  * From here to the end of the loop we're
02764                  * not in the single or double quote state.
02765                  */
02766 
02767                 if (*src == '\\') {
02768                         /* Next character must be escaped. */
02769                         next_escaped = True;
02770                         *dest++ = *src++;
02771                         continue;
02772                 }
02773 
02774                 if (*src == '\'') {
02775                         /* Go into single quote state. */
02776                         in_s_quote = True;
02777                         *dest++ = *src++;
02778                         continue;
02779                 }
02780 
02781                 if (*src == '\"') {
02782                         /* Go into double quote state. */
02783                         in_d_quote = True;
02784                         *dest++ = *src++;
02785                         continue;
02786                 }
02787 
02788                 /* Check if we need to escape the character. */
02789 
02790                 if (!strchr(INCLUDE_LIST, (int)*src)) {
02791                         *dest++ = '\\';
02792                 }
02793                 *dest++ = *src++;
02794         }
02795         *dest++ = '\0';
02796         return ret;
02797 }


変数

const char* last_ptr = NULL [static]

This is like next_token but is not re-entrant and "remembers" the first parameter so you can pass NULL.

This is useful for user interface code but beware the fact that it is not re-entrant!

util_str.c116 行で定義されています。

参照元 next_token_nr()remove_from_freelist()set_first_token()tdb_allocate()tdb_do_delete()tdb_validate_freelist()toktocliplist().

uint16 tmpbuf[sizeof(pstring)] [static]

util_str.c129 行で定義されています。

参照元 catia_string_replace()push_ascii()push_utf8()strhaslower()strhasupper()wb_aix_getgrset().

const char* null_string = "" [static]

util_str.c926 行で定義されています。

参照元 cmd_fstat()cmd_lstat()cmd_stat()string_free()string_init().

const char* b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" [static]

util_str.c2235 行で定義されています。

参照元 base64_decode_data_blob()base64_encode_data_blob().


Sambaに対してSat Aug 29 21:23:40 2009に生成されました。  doxygen 1.4.7