/* return true if access should be allowed to a service for a socket */ BOOL check_access(int sock, char *allow_list, char *deny_list) { BOOL ret = False; BOOL only_ip = False; char *deny = NULL; char *allow = NULL; DEBUG(10,("check_access: allow = %s, deny = %s\n", allow_list ? allow_list : "NULL", deny_list ? deny_list : "NULL")); if (deny_list) deny = strdup(deny_list); if (allow_list) allow = strdup(allow_list); if ((!deny || *deny==0) && (!allow || *allow==0)) ret = True; if (!ret) { /* bypass gethostbyaddr() calls if the lists only contain IP addrs */ if (only_ipaddrs_in_list(allow) && only_ipaddrs_in_list(deny)) { only_ip = True; DEBUG (3, ("check_access: no hostnames in host allow/deny list.\n")); ret = allow_access(deny,allow, "", get_socket_addr(sock)); } else { DEBUG (3, ("check_access: hostnames in host allow/deny list.\n")); ret = allow_access(deny,allow, get_socket_name(sock), get_socket_addr(sock)); } if (ret) { DEBUG(2,("Allowed connection from %s (%s)\n", only_ip ? "" : get_socket_name(sock), get_socket_addr(sock))); } else { DEBUG(0,("Denied connection from %s (%s)\n", only_ip ? "" : get_socket_name(sock), get_socket_addr(sock))); } } SAFE_FREE(deny); SAFE_FREE(allow); return(ret); }
void sockmsg_done() { gchar *sockname; if (io_watch != -1) g_source_remove(io_watch); fd_close(sock); sockname = get_socket_name(); unlink(sockname); }
int zmq::tcp_listener_t::set_local_address (const char *addr_) { if (options.use_fd != -1) { // in this case, the addr_ passed is not used and ignored, since the // socket was already created by the application _s = options.use_fd; } else { if (create_socket (addr_) == -1) return -1; } _endpoint = get_socket_name (_s, socket_end_local); _socket->event_listening (make_unconnected_bind_endpoint_pair (_endpoint), _s); return 0; }
SockMsgInitResult sockmsg_init() { gchar *sockname; SockMsgInitResult result; sockname = get_socket_name(); sock = fd_connect_unix(sockname); if (sock < 0) { unlink(sockname); sock = fd_open_unix(sockname); if (sock < 0) result = SOCKMSG_ERROR; else result = SOCKMSG_CREATED; } else { result = SOCKMSG_OPENED; } return result; }
/*! *\brief put all the things here we can do before * letting the program die */ static void crash_cleanup_exit(void) { extern gchar *get_socket_name(void); const char *filename = get_socket_name(); unlink(filename); }