Copyright (C) Andrew Tridgell 1992-1998
Copyright (C) Jeremy Allison 2001-2002
Copyright (C) Simo Sorce 2001
+ Copyright (C) Anthony Liguori 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
return True;
}
+/*********************************************************************
+ Ensure scope is never null string.
+*********************************************************************/
+
const char *global_scope(void)
{
+ if (!smb_scope)
+ set_global_scope("");
return smb_scope;
}
int n;
if (global_myname() == NULL || *global_myname() == '\0') {
- fstring name;
-
- fstrcpy( name, myhostname() );
- p = strchr( name, '.' );
- if (p)
- *p = 0;
- if (!set_global_myname(name)) {
+ if (!set_global_myname(myhostname())) {
DEBUG( 0, ( "init_structs: malloc fail.\n" ) );
return False;
}
Like atoi but gets the value up to the separator character.
****************************************************************************/
-static char *Atoic(char *p, int *n, char *c)
+static const char *Atoic(const char *p, int *n, const char *c)
{
- if (!isdigit((int)*p)) {
+ if (!isdigit((const int)*p)) {
DEBUG(5, ("Atoic: malformed number\n"));
return NULL;
}
Reads a list of numbers.
*************************************************************************/
-char *get_numlist(char *p, uint32 **num, int *count)
+const char *get_numlist(const char *p, uint32 **num, int *count)
{
int val;
Make a dir struct.
****************************************************************************/
-void make_dir_struct(char *buf,char *mask,char *fname,SMB_OFF_T size,int mode,time_t date)
+void make_dir_struct(char *buf, const char *mask, const char *fname,SMB_OFF_T size,int mode,time_t date)
{
char *p;
pstring mask2;
void close_low_fds(BOOL stderr_too)
{
+#ifndef VALGRIND
int fd;
int i;
return;
}
}
+#endif
}
/****************************************************************************
Become a daemon, discarding the controlling terminal.
****************************************************************************/
-void become_daemon(void)
+void become_daemon(BOOL Fork)
{
- if (sys_fork())
- _exit(0);
+ if (Fork) {
+ if (sys_fork()) {
+ _exit(0);
+ }
+ }
/* detach from the terminal */
#ifdef HAVE_SETSID
Get my own domain name.
****************************************************************************/
-BOOL get_mydomname(char *my_domname)
+BOOL get_mydomname(fstring my_domname)
{
pstring hostname;
char *p;
+ struct hostent *hp;
*hostname = 0;
/* get my host name */
/* Ensure null termination. */
hostname[sizeof(hostname)-1] = '\0';
+
p = strchr_m(hostname, '.');
- if (!p)
- return False;
+ if (p) {
+ p++;
+
+ if (my_domname)
+ fstrcpy(my_domname, p);
+ }
- p++;
+ if (!(hp = sys_gethostbyname(hostname))) {
+ return False;
+ }
- if (my_domname)
- fstrcpy(my_domname, p);
+ p = strchr_m(hp->h_name, '.');
- return True;
+ if (p) {
+ p++;
+
+ if (my_domname)
+ fstrcpy(my_domname, p);
+ return True;
+ }
+
+ return False;
}
/****************************************************************************
Interpret a protocol description string, with a default.
****************************************************************************/
-int interpret_protocol(char *str,int def)
+int interpret_protocol(const char *str,int def)
{
if (strequal(str,"NT1"))
return(PROTOCOL_NT1);
Something really nasty happened - panic !
********************************************************************/
-void smb_panic(char *why)
+void smb_panic(const char *why)
{
- char *cmd = lp_panic_action();
+ char *cmd;
int result;
+ size_t i;
+#ifdef HAVE_BACKTRACE_SYMBOLS
+ void *backtrace_stack[BACKTRACE_STACK_SIZE];
+ size_t backtrace_size;
+ char **backtrace_strings;
+#endif
+#ifdef DEVELOPER
+ {
+ extern char *global_clobber_region_function;
+ extern unsigned int global_clobber_region_line;
+
+ if (global_clobber_region_function) {
+ DEBUG(0,("smb_panic: clobber_region() last called from [%s(%u)]\n",
+ global_clobber_region_function,
+ global_clobber_region_line));
+ }
+ }
+#endif
+
+ cmd = lp_panic_action();
if (cmd && *cmd) {
DEBUG(0, ("smb_panic(): calling panic action [%s]\n", cmd));
result = system(cmd);
if (result == -1)
DEBUG(0, ("smb_panic(): fork failed in panic action: %s\n",
- strerror(errno)));
+ strerror(errno)));
else
DEBUG(0, ("smb_panic(): action returned status %d\n",
- WEXITSTATUS(result)));
+ WEXITSTATUS(result)));
}
DEBUG(0,("PANIC: %s\n", why));
+
+#ifdef HAVE_BACKTRACE_SYMBOLS
+ /* get the backtrace (stack frames) */
+ backtrace_size = backtrace(backtrace_stack,BACKTRACE_STACK_SIZE);
+ backtrace_strings = backtrace_symbols(backtrace_stack, backtrace_size);
+
+ DEBUG(0, ("BACKTRACE: %d stack frames:\n", backtrace_size));
+
+ if (backtrace_strings) {
+ for (i = 0; i < backtrace_size; i++)
+ DEBUGADD(0, (" #%u %s\n", i, backtrace_strings[i]));
+
+ SAFE_FREE(backtrace_strings);
+ }
+
+#endif
+
dbgflush();
abort();
}
/*******************************************************************
- A readdir wrapper which just returns the file name.
-********************************************************************/
+ A readdir wrapper which just returns the file name.
+ ********************************************************************/
-char *readdirname(DIR *p)
+const char *readdirname(DIR *p)
{
SMB_STRUCT_DIRENT *ptr;
char *dname;
of a path matches a (possibly wildcarded) entry in a namelist.
********************************************************************/
-BOOL is_in_path(char *name, name_compare_entry *namelist)
+BOOL is_in_path(const char *name, name_compare_entry *namelist)
{
pstring last_component;
char *p;
void free_namearray(name_compare_entry *name_array)
{
+ int i;
+
if(name_array == NULL)
return;
- SAFE_FREE(name_array->name);
+ for(i=0; name_array[i].name!=NULL; i++)
+ SAFE_FREE(name_array[i].name);
SAFE_FREE(name_array);
}
return False;
}
+/*******************************************************************
+ Is the name specified our workgroup/domain.
+ Returns true if it is equal, false otherwise.
+********************************************************************/
+
+BOOL is_myworkgroup(const char *s)
+{
+ BOOL ret = False;
+
+ if (strequal(s, lp_workgroup())) {
+ ret=True;
+ }
+
+ DEBUG(8, ("is_myworkgroup(\"%s\") returns %d\n", s, ret));
+ return(ret);
+}
+
+/*******************************************************************
+ we distinguish between 2K and XP by the "Native Lan Manager" string
+ WinXP => "Windows 2002 5.1"
+ Win2k => "Windows 2000 5.0"
+ NT4 => "Windows NT 4.0"
+ Win9x => "Windows 4.0"
+********************************************************************/
+
+void ra_lanman_string( const char *native_lanman )
+{
+ if ( 0 == strcmp( native_lanman, "Windows 2002 5.1" ) )
+ set_remote_arch( RA_WINXP );
+ else if ( 0 == strcmp( native_lanman, "Windows .NET 5.2" ) )
+ set_remote_arch( RA_WIN2K3 );
+}
+
/*******************************************************************
Set the horrid remote_arch string based on an enum.
********************************************************************/
case RA_WIN2K:
fstrcpy(remote_arch, "Win2K");
return;
+ case RA_WINXP:
+ fstrcpy(remote_arch, "WinXP");
+ return;
+ case RA_WIN2K3:
+ fstrcpy(remote_arch, "Win2K3");
+ return;
case RA_SAMBA:
fstrcpy(remote_arch,"Samba");
return;
return ra_type;
}
-
-void out_ascii(FILE *f, unsigned char *buf,int len)
-{
- int i;
- for (i=0;i<len;i++)
- fprintf(f, "%c", isprint(buf[i])?buf[i]:'.');
-}
-
-void out_data(FILE *f,char *buf1,int len, int per_line)
-{
- unsigned char *buf = (unsigned char *)buf1;
- int i=0;
- if (len<=0) {
- return;
- }
-
- fprintf(f, "[%03X] ",i);
- for (i=0;i<len;) {
- fprintf(f, "%02X ",(int)buf[i]);
- i++;
- if (i%(per_line/2) == 0) fprintf(f, " ");
- if (i%per_line == 0) {
- out_ascii(f,&buf[i-per_line ],per_line/2); fprintf(f, " ");
- out_ascii(f,&buf[i-per_line/2],per_line/2); fprintf(f, "\n");
- if (i<len) fprintf(f, "[%03X] ",i);
- }
- }
- if ((i%per_line) != 0) {
- int n;
-
- n = per_line - (i%per_line);
- fprintf(f, " ");
- if (n>(per_line/2)) fprintf(f, " ");
- while (n--) {
- fprintf(f, " ");
- }
- n = MIN(per_line/2,i%per_line);
- out_ascii(f,&buf[i-(i%per_line)],n); fprintf(f, " ");
- n = (i%per_line) - n;
- if (n>0) out_ascii(f,&buf[i-n],n);
- fprintf(f, "\n");
- }
-}
-
void print_asc(int level, const unsigned char *buf,int len)
{
int i;
void *p;
if (size == 0)
smb_panic("smb_xmalloc: called with zero size.\n");
- if ((p = malloc(size)) == NULL)
+ if ((p = malloc(size)) == NULL) {
+ DEBUG(0, ("smb_xmalloc() failed to allocate %lu bytes\n", (unsigned long)size));
smb_panic("smb_xmalloc: malloc fail.\n");
+ }
return p;
}
vasprintf that aborts on malloc fail
*/
-int smb_xvasprintf(char **ptr, const char *format, va_list ap)
+ int smb_xvasprintf(char **ptr, const char *format, va_list ap)
{
int n;
va_list ap2;
return fname;
}
+/**
+ * @brief Returns the platform specific shared library extension.
+ *
+ * @retval Pointer to a static #fstring containing the extension.
+ **/
+
+const char *shlib_ext(void)
+{
+ return dyn_SHLIBEXT;
+}
+
/*******************************************************************
Given a filename - get its directory name
NB: Returned in static storage. Caveats:
of the ".." name.
*******************************************************************/
-BOOL mask_match(char *string, char *pattern, BOOL is_case_sensitive)
+BOOL mask_match(const char *string, char *pattern, BOOL is_case_sensitive)
{
fstring p2, s2;
Simple case insensitive interface to a UNIX wildcard matcher.
*******************************************************************/
-BOOL unix_wild_match(char *pattern, char *string)
+BOOL unix_wild_match(const char *pattern, const char *string)
{
pstring p2, s2;
char *p;