kernel -- Import virtio & virtio-block drivers.
[dragonfly.git] / contrib / tcp_wrappers / update.c
blobb31c53976d0bcc0142db45fb34daca7f0f1c4fac
1 /*
2 * Routines for controlled update/initialization of request structures.
3 *
4 * request_init() initializes its argument. Pointers and string-valued members
5 * are initialized to zero, to indicate that no lookup has been attempted.
6 *
7 * request_set() adds information to an already initialized request structure.
8 *
9 * Both functions take a variable-length name-value list.
11 * Diagnostics are reported through syslog(3).
13 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
15 * $FreeBSD: src/contrib/tcp_wrappers/update.c,v 1.2 2000/02/03 10:27:00 shin Exp $
16 * $DragonFly: src/contrib/tcp_wrappers/update.c,v 1.2 2003/06/17 04:24:06 dillon Exp $
19 #ifndef lint
20 static char sccsid[] = "@(#) update.c 1.1 94/12/28 17:42:56";
21 #endif
23 /* System libraries */
25 #include <stdio.h>
26 #include <syslog.h>
27 #include <string.h>
29 /* Local stuff. */
31 #include "mystdarg.h"
32 #include "tcpd.h"
34 /* request_fill - request update engine */
36 static struct request_info *request_fill(request, ap)
37 struct request_info *request;
38 va_list ap;
40 int key;
41 char *ptr;
43 while ((key = va_arg(ap, int)) > 0) {
44 switch (key) {
45 default:
46 tcpd_warn("request_fill: invalid key: %d", key);
47 return (request);
48 case RQ_FILE:
49 request->fd = va_arg(ap, int);
50 continue;
51 case RQ_CLIENT_SIN:
52 #ifdef INET6
53 request->client->sin = va_arg(ap, struct sockaddr *);
54 #else
55 request->client->sin = va_arg(ap, struct sockaddr_in *);
56 #endif
57 continue;
58 case RQ_SERVER_SIN:
59 #ifdef INET6
60 request->server->sin = va_arg(ap, struct sockaddr *);
61 #else
62 request->server->sin = va_arg(ap, struct sockaddr_in *);
63 #endif
64 continue;
67 * All other fields are strings with the same maximal length.
70 case RQ_DAEMON:
71 ptr = request->daemon;
72 break;
73 case RQ_USER:
74 ptr = request->user;
75 break;
76 case RQ_CLIENT_NAME:
77 ptr = request->client->name;
78 break;
79 case RQ_CLIENT_ADDR:
80 ptr = request->client->addr;
81 break;
82 case RQ_SERVER_NAME:
83 ptr = request->server->name;
84 break;
85 case RQ_SERVER_ADDR:
86 ptr = request->server->addr;
87 break;
89 STRN_CPY(ptr, va_arg(ap, char *), STRING_LENGTH);
91 return (request);
94 /* request_init - initialize request structure */
96 struct request_info *VARARGS(request_init, struct request_info *, request)
98 static struct request_info default_info;
99 struct request_info *r;
100 va_list ap;
103 * Initialize data members. We do not assign default function pointer
104 * members, to avoid pulling in the whole socket module when it is not
105 * really needed.
107 VASTART(ap, struct request_info *, request);
108 *request = default_info;
109 request->fd = -1;
110 strcpy(request->daemon, unknown);
111 sprintf(request->pid, "%d", getpid());
112 request->client->request = request;
113 request->server->request = request;
114 r = request_fill(request, ap);
115 VAEND(ap);
116 return (r);
119 /* request_set - update request structure */
121 struct request_info *VARARGS(request_set, struct request_info *, request)
123 struct request_info *r;
124 va_list ap;
126 VASTART(ap, struct request_info *, request);
127 r = request_fill(request, ap);
128 VAEND(ap);
129 return (r);