tsocket: Fixed documentation for tsocket_address_bsd_sockaddr().
[ira/wip.git] / lib / util / util.c
index 1f31f55e8b2fd1a39e3c545fe733cf4370682d04..67b166b4212f01d85be7c61c9c9d7c78b8a91fbd 100644 (file)
@@ -133,8 +133,13 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid,
                        umask(old_umask);
                        return false;
                }
-               if ((st.st_uid != uid) || 
-                   ((st.st_mode & 0777) != dir_perms)) {
+               if (st.st_uid != uid && !uwrap_enabled()) {
+                       DEBUG(0, ("invalid ownership on directory "
+                                 "%s\n", dname));
+                       umask(old_umask);
+                       return false;
+               }
+               if ((st.st_mode & 0777) != dir_perms) {
                        DEBUG(0, ("invalid permissions on directory "
                                  "%s\n", dname));
                        umask(old_umask);
@@ -145,37 +150,6 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid,
 }       
 
 
-/**
- Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available,
- else
-  if SYSV use O_NDELAY
-  if BSD use FNDELAY
-**/
-
-_PUBLIC_ int set_blocking(int fd, bool set)
-{
-       int val;
-#ifdef O_NONBLOCK
-#define FLAG_TO_SET O_NONBLOCK
-#else
-#ifdef SYSV
-#define FLAG_TO_SET O_NDELAY
-#else /* BSD */
-#define FLAG_TO_SET FNDELAY
-#endif
-#endif
-
-       if((val = fcntl(fd, F_GETFL, 0)) == -1)
-               return -1;
-       if(set) /* Turn blocking on - ie. clear nonblock flag */
-               val &= ~FLAG_TO_SET;
-       else
-               val |= FLAG_TO_SET;
-       return fcntl( fd, F_SETFL, val);
-#undef FLAG_TO_SET
-}
-
-
 /**
  Sleep for a specified number of milliseconds.
 **/
@@ -296,15 +270,13 @@ static void _dump_data(int level, const uint8_t *buf, int len,
                       bool omit_zero_bytes)
 {
        int i=0;
-       const uint8_t empty[16];
+       static const uint8_t empty[16] = { 0, };
        bool skipped = false;
 
        if (len<=0) return;
 
        if (!DEBUGLVL(level)) return;
 
-       memset(&empty, '\0', 16);
-
        for (i=0;i<len;) {
 
                if (i%16 == 0) {
@@ -541,21 +513,6 @@ void *malloc_array(size_t el_size, unsigned int count)
        return realloc_array(NULL, el_size, count, false);
 }
 
-_PUBLIC_ void *talloc_check_name_abort(const void *ptr, const char *name)
-{
-        void *result;
-
-        result = talloc_check_name(ptr, name);
-        if (result != NULL)
-                return result;
-
-        DEBUG(0, ("Talloc type mismatch, expected %s, got %s\n",
-                  name, talloc_get_name(ptr)));
-        smb_panic("talloc type mismatch");
-        /* Keep the compiler happy */
-        return NULL;
-}
-
 /**
  Trim the specified elements off the front and back of a string.
 **/
@@ -622,18 +579,18 @@ _PUBLIC_ _PURE_ size_t count_chars(const char *s, char c)
 **/
 _PUBLIC_ size_t strhex_to_str(char *p, size_t p_len, const char *strhex, size_t strhex_len)
 {
-       size_t i;
+       size_t i = 0;
        size_t num_chars = 0;
        uint8_t   lonybble, hinybble;
        const char     *hexchars = "0123456789ABCDEF";
        char           *p1 = NULL, *p2 = NULL;
 
-       for (i = 0; i < strhex_len && strhex[i] != 0; i++) {
-               if (strncasecmp(hexchars, "0x", 2) == 0) {
-                       i++; /* skip two chars */
-                       continue;
-               }
+       /* skip leading 0x prefix */
+       if (strncasecmp(strhex, "0x", 2) == 0) {
+               i += 2; /* skip two chars */
+       }
 
+       for (; i < strhex_len && strhex[i] != 0; i++) {
                if (!(p1 = strchr(hexchars, toupper((unsigned char)strhex[i]))))
                        break;
 
@@ -709,46 +666,6 @@ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_
        return hex_buffer;
 }
 
-/**
- Unescape a URL encoded string, in place.
-**/
-
-_PUBLIC_ void rfc1738_unescape(char *buf)
-{
-       char *p=buf;
-
-       while ((p=strchr(p,'+')))
-               *p = ' ';
-
-       p = buf;
-
-       while (p && *p && (p=strchr(p,'%'))) {
-               int c1 = p[1];
-               int c2 = p[2];
-
-               if (c1 >= '0' && c1 <= '9')
-                       c1 = c1 - '0';
-               else if (c1 >= 'A' && c1 <= 'F')
-                       c1 = 10 + c1 - 'A';
-               else if (c1 >= 'a' && c1 <= 'f')
-                       c1 = 10 + c1 - 'a';
-               else {p++; continue;}
-
-               if (c2 >= '0' && c2 <= '9')
-                       c2 = c2 - '0';
-               else if (c2 >= 'A' && c2 <= 'F')
-                       c2 = 10 + c2 - 'A';
-               else if (c2 >= 'a' && c2 <= 'f')
-                       c2 = 10 + c2 - 'a';
-               else {p++; continue;}
-                       
-               *p = (c1<<4) | c2;
-
-               memmove(p+1, p+3, strlen(p+3)+1);
-               p++;
-       }
-}
-
 /**
   varient of strcmp() that handles NULL ptrs
 **/
@@ -847,8 +764,8 @@ static bool next_token_internal_talloc(TALLOC_CTX *ctx,
                                 const char *sep,
                                 bool ltrim)
 {
-       char *s;
-       char *saved_s;
+       const char *s;
+       const char *saved_s;
        char *pbuf;
        bool quoted;
        size_t len=1;
@@ -858,7 +775,7 @@ static bool next_token_internal_talloc(TALLOC_CTX *ctx,
                return(false);
        }
 
-       s = (char *)*ptr;
+       s = *ptr;
 
        /* default to simple separators */
        if (!sep) {