r5308: trimmed back a lot of the old macros from smb_macros.h
authorAndrew Tridgell <tridge@samba.org>
Thu, 10 Feb 2005 07:39:14 +0000 (07:39 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:09:40 +0000 (13:09 -0500)
(This used to be commit bf43c9bdcf9e654d123f6a2b29feb9189ca9e561)

13 files changed:
source4/client/client.c
source4/include/smb_macros.h
source4/lib/netif/interface.c
source4/lib/pidfile.c
source4/lib/util.c
source4/libcli/ldap/ldap_client.c
source4/param/loadparm.c
source4/rpc_server/netlogon/dcerpc_netlogon.c
source4/smb_server/conn.c
source4/smb_server/service.c
source4/torture/rpc/drsuapi.c
source4/torture/torture.c
source4/utils/net/net_time.c

index 986f35b9713cd3bfe34fcbdecbcac6bbd77e5ede..59311a35d85293b5de48163a4432947de7629fac 100644 (file)
@@ -216,7 +216,7 @@ static void send_message(void)
                int l=0;
                int c;
 
-               ZERO_ARRAY(msg);
+               ZERO_STRUCT(msg);
 
                for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
                        if (c == '\n')
index 0f1334182185dc7c394e7232ac677f96459aaa11..276076955f502b353ffbc551275d6fa0a233594d 100644 (file)
 #ifndef _SMB_MACROS_H
 #define _SMB_MACROS_H
 
-/* Misc bit macros */
-#define BOOLSTR(b) ((b) ? "Yes" : "No")
-#define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
-#define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
-
-/* for readability... */
-#define IS_DOS_READONLY(test_mode) (((test_mode) & aRONLY) != 0)
-#define IS_DOS_DIR(test_mode)      (((test_mode) & aDIR) != 0)
-#define IS_DOS_ARCHIVE(test_mode)  (((test_mode) & aARCH) != 0)
-#define IS_DOS_SYSTEM(test_mode)   (((test_mode) & aSYSTEM) != 0)
-#define IS_DOS_HIDDEN(test_mode)   (((test_mode) & aHIDDEN) != 0)
-
-#ifndef SAFE_FREE /* Oh no this is also defined in tdb.h */
-
-/**
- * Free memory if the pointer and zero the pointer.
- *
- * @note You are explicitly allowed to pass NULL pointers -- they will
- * always be ignored.
- **/
-#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
-#endif
-
 /* zero a structure */
 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
 
 /* zero a structure given a pointer to the structure - no zero check */
 #define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
 
-/* zero an array - note that sizeof(array) must work - ie. it must not be a 
-   pointer */
-#define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
-
 /* pointer difference macro */
 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
 
 
 #define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0])) >= (n))
 
-/* the service number for the [globals] defaults */ 
-#define GLOBAL_SECTION_SNUM    (-1)
-/* translates a connection number into a service number */
-#define SNUM(conn)             ((conn)?(conn)->service:GLOBAL_SECTION_SNUM)
-
-
-/* access various service details */
-#define SERVICE(snum)      (lp_servicename(snum))
-#define PRINTERNAME_NOTUSED(snum)  (lp_printername(snum))
-#define CAN_WRITE(conn)    (!conn->read_only)
-#define VALID_SNUM(snum)   (lp_snum_ok(snum))
-#define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
-
-/* these are the datagram types */
-#define DGRAM_DIRECT_UNIQUE 0x10
-
-
 /* REWRITE TODO: remove these smb_xxx macros */
 #define smb_buf(buf) (((char *)(buf)) + MIN_SMB_SIZE + CVAL(buf,HDR_WCT+4)*2)
 
 #define _smb_setlen(buf,len) do {(buf)[0] = 0; (buf)[1] = ((len)&0x10000)>>16; \
         (buf)[2] = ((len)&0xFF00)>>8; (buf)[3] = (len)&0xFF;} while (0)
 
-/*******************************************************************
-find the difference in milliseconds between two struct timeval
-values
-********************************************************************/
-
-#define TvalDiff(tvalold,tvalnew) \
-  (((tvalnew)->tv_sec - (tvalold)->tv_sec)*1000 +  \
-        ((int)(tvalnew)->tv_usec - (int)(tvalold)->tv_usec)/1000)
-
-/****************************************************************************
-true if two IP addresses are equal
-****************************************************************************/
-
-#define ip_equal(ip1,ip2) ((ip1).s_addr == (ip2).s_addr)
-#define ipv4_equal(ip1,ip2) ((ip1).addr == (ip2).addr)
-
-/*******************************************************************
-copy an IP address from one buffer to another
-********************************************************************/
-
-#define putip(dest,src) memcpy(dest,src,4)
-
-
 #ifndef MIN
 #define MIN(a,b) ((a)<(b)?(a):(b))
 #endif
@@ -132,5 +65,15 @@ copy an IP address from one buffer to another
 #define ABS(a) ((a)>0?(a):(-(a)))
 #endif
 
+#ifndef SAFE_FREE /* Oh no this is also defined in tdb.h */
+/**
+ * Free memory if the pointer and zero the pointer.
+ *
+ * @note You are explicitly allowed to pass NULL pointers -- they will
+ * always be ignored.
+ **/
+#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
+#endif
+
 
 #endif /* _SMB_MACROS_H */
index 31354e359a505aee1f9639258804db8ff7fd5575..2d90df43cf00bb973e78d299a68df0b6fd660ada 100644 (file)
@@ -272,8 +272,9 @@ BOOL interfaces_changed(void)
 BOOL ismyip(struct ipv4_addr ip)
 {
        struct interface *i;
-       for (i=local_interfaces;i;i=i->next)
-               if (ipv4_equal(i->ip,ip)) return True;
+       for (i=local_interfaces;i;i=i->next) {
+               if (i->ip.addr == ip.addr) return True;
+       }
        return False;
 }
 
index ff05c0606e411272a72640d85279c6abc5a74f7e..b1866ee6af060be235a38576e315000fab6fad25 100644 (file)
@@ -44,7 +44,7 @@ pid_t pidfile_pid(const char *name)
                return 0;
        }
 
-       ZERO_ARRAY(pidstr);
+       ZERO_STRUCT(pidstr);
 
        if (read(fd, pidstr, sizeof(pidstr)-1) <= 0) {
                goto noproc;
index d95924670f6facdbe0b640296fb7001e761d4dfb..93559d9518e6693641688a24a67852cecc2a9069 100644 (file)
@@ -410,7 +410,7 @@ uint32_t interpret_addr(const char *str)
                        DEBUG(3,("sys_gethostbyname: host address is invalid for host %s\n",str));
                        return 0;
                }
-               putip((char *)&res,(char *)hp->h_addr);
+               memcpy((char *)&res,(char *)hp->h_addr, 4);
        }
 
        if (res == (uint32_t)-1)
@@ -436,9 +436,7 @@ struct ipv4_addr interpret_addr2(const char *str)
 
 BOOL is_zero_ip(struct ipv4_addr ip)
 {
-       uint32_t a;
-       putip((char *)&a,(char *)&ip);
-       return(a == 0);
+       return ip.addr == 0;
 }
 
 /*******************************************************************
index 11815ddd6d465fa1aff6ec9493f12e203fcb6613..e3904c7a6b4d907308f35fe41b304451cad22db9 100644 (file)
@@ -223,7 +223,7 @@ static int open_socket_out(int type, struct ipv4_addr *addr, int port, int timeo
        if (type != SOCK_STREAM) return(res);
        
        memset((char *)&sock_out,'\0',sizeof(sock_out));
-       putip((char *)&sock_out.sin_addr,(char *)addr);
+       sock_out.sin_addr.s_addr = addr->addr;
        
        sock_out.sin_port = htons( port );
        sock_out.sin_family = PF_INET;
@@ -385,7 +385,7 @@ struct ldap_connection *ldap_connect(TALLOC_CTX *mem_ctx, const char *url)
                return NULL;
        }
 
-       putip((char *)&ip, (char *)hp->h_addr);
+       memcpy((char *)&ip, (char *)hp->h_addr, 4);
 
        conn->sock = open_socket_out(SOCK_STREAM, &ip, conn->port, LDAP_CONNECTION_TIMEOUT);
        if (conn->sock < 0) {
index 121821b54234e0b987c244fe3707f7fd9855e25d..bd4bb8af043e940ef26afd811c69dfefb8fcfe4f 100644 (file)
@@ -2506,6 +2506,8 @@ BOOL lp_set_option(const char *option)
 }
 
 
+#define BOOLSTR(b) ((b) ? "Yes" : "No")
+
 /***************************************************************************
  Print a parameter of the specified type.
 ***************************************************************************/
index 67048e4a3def36944f6a65be0d393916ef0100e2..bb16ed54c6b4fc7a05143c253e7712b8eb29bbab 100644 (file)
@@ -535,7 +535,7 @@ static NTSTATUS netr_LogonSamLogonEx(struct dcesrv_call_state *dce_call, TALLOC_
        NT_STATUS_HAVE_NO_MEMORY(sam->domain_sid);
        sam->domain_sid->num_auths--;
 
-       ZERO_ARRAY(sam->unknown);
+       ZERO_STRUCT(sam->unknown);
 
        ZERO_STRUCT(sam->key);
        if (server_info->user_session_key.length == sizeof(sam->key.key)) {
@@ -1101,7 +1101,7 @@ static NTSTATUS netr_ServerPasswordSet2(struct dcesrv_call_state *dce_call, TALL
                                       False, /* This is not considered a password change */
                                       False, /* don't restrict this password change (match w2k3) */
                                       NULL);
-       ZERO_ARRAY(new_pass);
+       ZERO_STRUCT(new_pass);
        NT_STATUS_NOT_OK_RETURN(nt_status);
 
        ret = samdb_replace(sam_ctx, mem_ctx, mod);
index 45c5376e25ffade4a8424f02f1bec15d40085a5e..6ca8e4286cc8e84945e4b589be030e7c2a4cbdfb 100644 (file)
@@ -52,7 +52,7 @@ static int smbsrv_tcon_destructor(void *ptr)
 
        DEBUG(3,("%s closed connection to service %s\n",
                 socket_get_peer_addr(tcon->smb_conn->connection->socket, tcon),
-                lp_servicename(SNUM(tcon))));
+                lp_servicename(tcon->service)));
 
        /* tell the ntvfs backend that we are disconnecting */
        ntvfs_disconnect(tcon);
index 180deaf8c53b125174270b1dc177b6bdaafaad1a..bb74a5c2d963254bb102a2445d6c431dff870220 100644 (file)
@@ -73,7 +73,7 @@ static int find_service(const char *service)
 
        iService = lp_servicenumber(service);
 
-       if (iService >= 0 && !VALID_SNUM(iService)) {
+       if (iService >= 0 && !lp_snum_ok(iService)) {
                DEBUG(0,("Invalid snum %d for %s\n",iService, service));
                iService = -1;
        }
@@ -117,7 +117,8 @@ static NTSTATUS make_connection_snum(struct smbsrv_request *req,
        /* init ntvfs function pointers */
        status = ntvfs_init_connection(req, type);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("ntvfs_init_connection failed for service %s\n", lp_servicename(SNUM(tcon))));
+               DEBUG(0, ("ntvfs_init_connection failed for service %s\n", 
+                         lp_servicename(tcon->service)));
                return status;
        }
 
index f386c84a91e3e957869c03e900b84916021167e0..e10c088e36e5dd31181cbbbf0fdd0fe3f84766b0 100644 (file)
@@ -790,7 +790,7 @@ static BOOL test_DsReplicaSync(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                        r.in.req.req1.info->unknown1            = 32;
                        r.in.req.req1.info->unknown2            = 120;
                        ZERO_STRUCT(r.in.req.req1.info->guid1);
-                       ZERO_ARRAY(r.in.req.req1.info->unknown3);
+                       ZERO_STRUCT(r.in.req.req1.info->unknown3);
                        r.in.req.req1.info->nc_dn               = priv->domain_obj_dn?priv->domain_obj_dn:"";
                        r.in.req.req1.guid1                     = priv->dcinfo.ntds_guid;
                        r.in.req.req1.string1                   = NULL;
index b7ca730d1f316b8abd7560be1a2effc10fe0a70b..6b92bce691caa9fce705d539add2859f12c90152 100644 (file)
@@ -527,6 +527,8 @@ static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
        return correct;
 }
 
+#define BOOLSTR(b) ((b) ? "Yes" : "No")
+
 static BOOL run_readwritetest(void)
 {
        struct smbcli_state *cli1, *cli2;
index d2df76bc5d0333cd6aca8956021fb4a7a0cc1613..ec3bc0519fa09e21fa8daa7082700915001bde18 100644 (file)
@@ -64,7 +64,7 @@ int net_time(struct net_context *ctx, int argc, const char **argv)
                return -1;
        }
 
-       ZERO_ARRAY(timestr);
+       ZERO_STRUCT(timestr);
        tm = localtime(&r.generic.out.time);
        strftime(timestr, sizeof(timestr)-1, "%c %Z",tm);