From 75ddf59ea110117578acd3a7b889549bfb40473c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2005 07:39:14 +0000 Subject: r5308: trimmed back a lot of the old macros from smb_macros.h (This used to be commit bf43c9bdcf9e654d123f6a2b29feb9189ca9e561) --- source4/client/client.c | 2 +- source4/include/smb_macros.h | 77 ++++----------------------- source4/lib/netif/interface.c | 5 +- source4/lib/pidfile.c | 2 +- source4/lib/util.c | 6 +-- source4/libcli/ldap/ldap_client.c | 4 +- source4/param/loadparm.c | 2 + source4/rpc_server/netlogon/dcerpc_netlogon.c | 4 +- source4/smb_server/conn.c | 2 +- source4/smb_server/service.c | 5 +- source4/torture/rpc/drsuapi.c | 2 +- source4/torture/torture.c | 2 + source4/utils/net/net_time.c | 2 +- 13 files changed, 31 insertions(+), 84 deletions(-) diff --git a/source4/client/client.c b/source4/client/client.c index 986f35b971..59311a35d8 100644 --- a/source4/client/client.c +++ b/source4/client/client.c @@ -216,7 +216,7 @@ static void send_message(void) int l=0; int c; - ZERO_ARRAY(msg); + ZERO_STRUCT(msg); for (l=0;l= (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) @@ -97,29 +53,6 @@ #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 */ diff --git a/source4/lib/netif/interface.c b/source4/lib/netif/interface.c index 31354e359a..2d90df43cf 100644 --- a/source4/lib/netif/interface.c +++ b/source4/lib/netif/interface.c @@ -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; } diff --git a/source4/lib/pidfile.c b/source4/lib/pidfile.c index ff05c0606e..b1866ee6af 100644 --- a/source4/lib/pidfile.c +++ b/source4/lib/pidfile.c @@ -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; diff --git a/source4/lib/util.c b/source4/lib/util.c index d95924670f..93559d9518 100644 --- a/source4/lib/util.c +++ b/source4/lib/util.c @@ -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; } /******************************************************************* diff --git a/source4/libcli/ldap/ldap_client.c b/source4/libcli/ldap/ldap_client.c index 11815ddd6d..e3904c7a6b 100644 --- a/source4/libcli/ldap/ldap_client.c +++ b/source4/libcli/ldap/ldap_client.c @@ -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) { diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c index 121821b542..bd4bb8af04 100644 --- a/source4/param/loadparm.c +++ b/source4/param/loadparm.c @@ -2506,6 +2506,8 @@ BOOL lp_set_option(const char *option) } +#define BOOLSTR(b) ((b) ? "Yes" : "No") + /*************************************************************************** Print a parameter of the specified type. ***************************************************************************/ diff --git a/source4/rpc_server/netlogon/dcerpc_netlogon.c b/source4/rpc_server/netlogon/dcerpc_netlogon.c index 67048e4a3d..bb16ed54c6 100644 --- a/source4/rpc_server/netlogon/dcerpc_netlogon.c +++ b/source4/rpc_server/netlogon/dcerpc_netlogon.c @@ -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); diff --git a/source4/smb_server/conn.c b/source4/smb_server/conn.c index 45c5376e25..6ca8e4286c 100644 --- a/source4/smb_server/conn.c +++ b/source4/smb_server/conn.c @@ -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); diff --git a/source4/smb_server/service.c b/source4/smb_server/service.c index 180deaf8c5..bb74a5c2d9 100644 --- a/source4/smb_server/service.c +++ b/source4/smb_server/service.c @@ -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; } diff --git a/source4/torture/rpc/drsuapi.c b/source4/torture/rpc/drsuapi.c index f386c84a91..e10c088e36 100644 --- a/source4/torture/rpc/drsuapi.c +++ b/source4/torture/rpc/drsuapi.c @@ -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; diff --git a/source4/torture/torture.c b/source4/torture/torture.c index b7ca730d1f..6b92bce691 100644 --- a/source4/torture/torture.c +++ b/source4/torture/torture.c @@ -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; diff --git a/source4/utils/net/net_time.c b/source4/utils/net/net_time.c index d2df76bc5d..ec3bc0519f 100644 --- a/source4/utils/net/net_time.c +++ b/source4/utils/net/net_time.c @@ -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); -- cgit