/*
- * Copyright (c) 1995-1997, Index Data
+ * Copyright (c) 1995-1998, Index Data
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: comstack.c,v $
- * Revision 1.4 1997-09-29 07:16:14 adam
+ * Revision 1.5 1998-06-22 11:32:35 adam
+ * Added 'conditional cs_listen' feature.
+ *
+ * Revision 1.4 1997/09/29 07:16:14 adam
* Array cs_errlist no longer global.
*
* Revision 1.3 1997/09/01 08:49:14 adam
"System (lower-layer) error",
"Operation out of state",
"No data (operation would block)",
- "New data while half of old buffer is on the line (flow control)"
+ "New data while half of old buffer is on the line (flow control)",
+ "Permission denied"
};
const char *cs_errmsg(int n)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: tcpip.c,v $
- * Revision 1.21 1998-05-20 09:55:32 adam
+ * Revision 1.22 1998-06-22 11:32:36 adam
+ * Added 'conditional cs_listen' feature.
+ *
+ * Revision 1.21 1998/05/20 09:55:32 adam
* Function tcpip_get treats EINPROGRESS error in the same way as
* EWOULDBLOCK. EINPROGRESS shouldn't be returned - but it is on
* Solaris in some cases.
int tcpip_more(COMSTACK h);
int tcpip_rcvconnect(COMSTACK h);
int tcpip_bind(COMSTACK h, void *address, int mode);
-int tcpip_listen(COMSTACK h, char *addrp, int *addrlen);
+int tcpip_listen(COMSTACK h, char *raddr, int *addrlen,
+ int (*check_ip)(void *cd, const char *a, int len, int type),
+ void *cd);
+
COMSTACK tcpip_accept(COMSTACK h);
char *tcpip_addrstr(COMSTACK h);
void *tcpip_straddr(COMSTACK h, const char *str);
/*int completeBER(unsigned char *buf, int len); */ /* from the ODR module */
int completeWAIS(unsigned char *buf, int len); /* from waislen.c */
+#undef TRACE_TCPIP
#ifdef TRACE_TCPIP
#define TRC(x) x
#else
return 0;
}
-int tcpip_listen(COMSTACK h, char *raddr, int *addrlen)
+#if 0
+void tcpip_get_ip(COMSTACK h, char *ip_buf)
+{
+ struct tcpip_state *sp = (tcpip_state *)h->cprivate;
+ const char *ip_addr = (const char *) (&sp->addr->sin_addr.s_addr);
+ int i;
+
+ for (i = 0; i<4; i++)
+ TRC (fprintf (stderr, "%u ", ip_addr[i]));
+ TRC (fprintf (stderr, "\n"));
+}
+#endif
+
+int tcpip_listen(COMSTACK h, char *raddr, int *addrlen,
+ int (*check_ip)(void *cd, const char *a, int len, int type),
+ void *cd)
{
struct sockaddr_in addr;
int len = sizeof(addr);
- TRC(fprintf(stderr, "tcpip_listen\n"));
+ TRC(fprintf(stderr, "tcpip_listen pid=%d\n", getpid()));
if (h->state != CS_IDLE)
{
h->cerrno = CSOUTSTATE;
h->cerrno = CSYSERR;
return -1;
}
- if (addrlen && *addrlen > sizeof(struct sockaddr_in))
+ if (addrlen && *addrlen >= sizeof(struct sockaddr_in))
memcpy(raddr, &addr, *addrlen = sizeof(struct sockaddr_in));
else if (addrlen)
*addrlen = 0;
+
+#if 1
+ if (check_ip && (*check_ip)(cd, &addr.sin_addr, sizeof(addr.sin_addr),
+ AF_INET))
+ {
+ h->cerrno = CSDENY;
+ close (h->newfd);
+ return -1;
+ }
+#endif
h->state = CS_INCON;
return 0;
}
* OF THIS SOFTWARE.
*
* $Log: comstack.h,v $
- * Revision 1.21 1998-05-20 09:52:39 adam
+ * Revision 1.22 1998-06-22 11:32:37 adam
+ * Added 'conditional cs_listen' feature.
+ *
+ * Revision 1.21 1998/05/20 09:52:39 adam
* Removed 'dead' definition.
*
* Revision 1.20 1998/05/18 13:06:55 adam
int (*f_bind)(COMSTACK handle, void *address, int mode);
#define CS_CLIENT 0
#define CS_SERVER 1
- int (*f_listen)(COMSTACK handle, char *addrp, int *addrlen);
+ int (*f_listen)(COMSTACK h, char *raddr, int *addrlen,
+ int (*check_ip)(void *cd, const char *a, int len, int type),
+ void *cd);
COMSTACK (*f_accept)(COMSTACK handle);
int (*f_close)(COMSTACK handle);
char *(*f_addrstr)(COMSTACK handle);
#define cs_connect(handle, address) ((*(handle)->f_connect)(handle, address))
#define cs_rcvconnect(handle) ((*(handle)->f_rcvconnect)(handle))
#define cs_bind(handle, ad, mo) ((*(handle)->f_bind)(handle, ad, mo))
-#define cs_listen(handle, ap, al) ((*(handle)->f_listen)(handle, ap, al))
+#define cs_listen(handle, ap, al) ((*(handle)->f_listen)(handle, ap, al, 0, 0))
+#define cs_listen_check(handle, ap, al, cf, cd) ((*(handle)->f_listen)(handle, ap, al, cf, cd))
#define cs_accept(handle) ((*(handle)->f_accept)(handle))
#define cs_close(handle) ((*(handle)->f_close)(handle))
#define cs_create(type, blocking, proto) ((*type)(-1, blocking, proto))
#define CSOUTSTATE 2
#define CSNODATA 3
#define CSWRONGBUF 4
+#define CSDENY 5
/* backwards compatibility */
#define CS_SR PROTO_SR
* OF THIS SOFTWARE.
*
* $Log: tcpip.h,v $
- * Revision 1.10 1998-05-18 13:07:01 adam
+ * Revision 1.11 1998-06-22 11:32:38 adam
+ * Added 'conditional cs_listen' feature.
+ *
+ * Revision 1.10 1998/05/18 13:07:01 adam
* Changed the way attribute sets are handled by the retriaval module.
* Extended Explain conversion / schema.
* Modified server and client to work with ASN.1 compiled protocol handlers.
#endif
YAZ_EXPORT struct sockaddr_in *tcpip_strtoaddr(const char *str);
-
YAZ_EXPORT COMSTACK tcpip_type(int s, int blocking, int protocol);
#ifdef __cplusplus
* Chas Woodfield, Fretwell Downing Datasystems.
*
* $Log: statserv.c,v $
- * Revision 1.49 1998-02-27 14:04:55 adam
+ * Revision 1.50 1998-06-22 11:32:39 adam
+ * Added 'conditional cs_listen' feature.
+ *
+ * Revision 1.49 1998/02/27 14:04:55 adam
* Fixed bug in statserv_remove.
*
* Revision 1.48 1998/02/11 11:53:36 adam
{
if ((res = cs_listen(line, 0, 0)) < 0)
{
- logf(LOG_FATAL, "cs_listen failed.");
+ logf(LOG_FATAL, "cs_listen failed");
return;
}
else if (res == 1)
iochan_destroy(p);
}
+static int check_ip(void *cd, const char *addr, int len, int type)
+{
+ const unsigned char *ip = (const unsigned char *) addr;
+ int i;
+ char str[64];
+
+ sprintf (str, "%u", *ip);
+ for (i = 1; i<4; i++)
+ sprintf (str + strlen(str), ".%u", ip[i]);
+ logf (LOG_DEBUG, "ip %s", str);
+ return 0;
+}
+
static void listener(IOCHAN h, int event)
{
COMSTACK line = (COMSTACK) iochan_getdata(h);
return;
}
}
- if ((res = cs_listen(line, 0, 0)) < 0)
+ if ((res = cs_listen_check(line, 0, 0, check_ip, 0)) < 0)
{
- logf(LOG_FATAL, "cs_listen failed.");
+ logf(LOG_WARN, "cs_listen failed");
return;
}
else if (res == 1)