This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[ira/wip.git] / source3 / lib / util.c
index ec967e4abf028edb24c204a7a0505be2149e14ae..4f564b332a097bd4f487c637fe6faf6fd18b8530 100644 (file)
@@ -4,6 +4,7 @@
    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
@@ -248,13 +249,7 @@ BOOL init_names(void)
        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;
                }
@@ -314,9 +309,9 @@ BOOL in_group(gid_t group, gid_t current_gid, int ngroups, const gid_t *groups)
  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;
        }
@@ -338,7 +333,7 @@ static char *Atoic(char *p, int *n, char *c)
  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;
 
@@ -1013,7 +1008,7 @@ BOOL get_myfullname(char *my_name)
  Get my own domain name.
 ****************************************************************************/
 
-BOOL get_mydomname(char *my_domname)
+BOOL get_mydomname(fstring my_domname)
 {
        pstring hostname;
        char *p;
@@ -1403,9 +1398,23 @@ gid_t nametogid(const char *name)
 
 void smb_panic(const char *why)
 {
-       char *cmd = lp_panic_action();
+       char *cmd;
        int result;
 
+#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);
@@ -1426,7 +1435,7 @@ void smb_panic(const char *why)
  A readdir wrapper which just returns the file name.
 ********************************************************************/
 
-char *readdirname(DIR *p)
+const char *readdirname(DIR *p)
 {
        SMB_STRUCT_DIRENT *ptr;
        char *dname;
@@ -1599,10 +1608,13 @@ void set_namearray(name_compare_entry **ppname_array, char *namelist)
 
 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);
 }
 
@@ -1725,6 +1737,39 @@ BOOL is_myname_or_ipaddr(const char *s)
        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.
 ********************************************************************/
@@ -1749,6 +1794,12 @@ void set_remote_arch(enum remote_arch_types type)
        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;
@@ -2038,8 +2089,10 @@ void *smb_xmalloc(size_t size)
        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;
 }
 
@@ -2179,6 +2232,17 @@ char *lib_path(const char *name)
        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:
@@ -2374,7 +2438,7 @@ static BOOL unix_do_match(char *regexp, char *str)
  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;