2005-05-28 Erez Zadok <ezk@cs.sunysb.edu>
+ * amd/amq_svc.c (amqsvc_is_client_allowed): rewrite function to
+ avoid only use of alloca() in am-utils, and to use strdup
+ explicitly. This way we can avoid using alloca, a feature that's
+ not portable on various systems.
+
* amq/amq.c: remove unused lint/rcsid cruft.
2005-05-27 Erez Zadok <ezk@cs.sunysb.edu>
* SUCH DAMAGE.
*
*
- * $Id: amq_svc.c,v 1.16 2005/01/03 20:56:45 ezk Exp $
+ * $Id: amq_svc.c,v 1.17 2005/05/28 16:39:23 ezk Exp $
*
*/
amqsvc_is_client_allowed(const struct sockaddr_in *addr, char *remote)
{
struct hostent *h;
- char *name, **ad;
+ char *name = NULL, **ad;
+ int ret = 0; /* default is 0==denied */
/* Check IP address */
- if (hosts_ctl(AMD_SERVICE_NAME, "", remote, ""))
- return 1;
+ if (hosts_ctl(AMD_SERVICE_NAME, "", remote, "")) {
+ ret = 1;
+ goto out;
+ }
/* Get address */
if (!(h = gethostbyaddr((const char *)&(addr->sin_addr),
sizeof(addr->sin_addr),
AF_INET)))
- return 0;
- if (!(name = alloca(strlen(h->h_name)+1)))
- return 0;
- strcpy(name, h->h_name);
+ goto out;
+ if (!(name = strdup(h->h_name)))
+ goto out;
/* Paranoia check */
if (!(h = gethostbyname(name)))
- return 0;
+ goto out;
for (ad = h->h_addr_list; *ad; ad++)
if (!memcmp(*ad, &(addr->sin_addr), h->h_length))
break;
if (!*ad)
- return 0;
- if (hosts_ctl(AMD_SERVICE_NAME, "", h->h_name, ""))
+ goto out;
+ if (hosts_ctl(AMD_SERVICE_NAME, "", h->h_name, "")) {
return 1;
+ goto out;
+ }
/* Check aliases */
for (ad = h->h_aliases; *ad; ad++)
- if (hosts_ctl(AMD_SERVICE_NAME, "", *ad, ""))
+ if (hosts_ctl(AMD_SERVICE_NAME, "", *ad, "")) {
return 1;
- return 0;
+ goto out;
+ }
+
+ out:
+ if (name)
+ XFREE(name);
+ return ret;
}
#endif /* defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP) */