xref: /onnv-gate/usr/src/lib/libwrap/update.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
7*0Sstevel@tonic-gate 
8*0Sstevel@tonic-gate  /*
9*0Sstevel@tonic-gate   * Routines for controlled update/initialization of request structures.
10*0Sstevel@tonic-gate   *
11*0Sstevel@tonic-gate   * request_init() initializes its argument. Pointers and string-valued members
12*0Sstevel@tonic-gate   * are initialized to zero, to indicate that no lookup has been attempted.
13*0Sstevel@tonic-gate   *
14*0Sstevel@tonic-gate   * request_set() adds information to an already initialized request structure.
15*0Sstevel@tonic-gate   *
16*0Sstevel@tonic-gate   * Both functions take a variable-length name-value list.
17*0Sstevel@tonic-gate   *
18*0Sstevel@tonic-gate   * Diagnostics are reported through syslog(3).
19*0Sstevel@tonic-gate   *
20*0Sstevel@tonic-gate   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
21*0Sstevel@tonic-gate   */
22*0Sstevel@tonic-gate 
23*0Sstevel@tonic-gate #ifndef lint
24*0Sstevel@tonic-gate static char sccsid[] = "@(#) update.c 1.1 94/12/28 17:42:56";
25*0Sstevel@tonic-gate #endif
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /* System libraries */
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <stdlib.h>
31*0Sstevel@tonic-gate #include <unistd.h>
32*0Sstevel@tonic-gate #include <syslog.h>
33*0Sstevel@tonic-gate #include <string.h>
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate /* Local stuff. */
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #include "mystdarg.h"
38*0Sstevel@tonic-gate #include "tcpd.h"
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate /* request_fill - request update engine */
41*0Sstevel@tonic-gate 
request_fill(request,ap)42*0Sstevel@tonic-gate static struct request_info *request_fill(request, ap)
43*0Sstevel@tonic-gate struct request_info *request;
44*0Sstevel@tonic-gate va_list ap;
45*0Sstevel@tonic-gate {
46*0Sstevel@tonic-gate     int     key;
47*0Sstevel@tonic-gate     char   *ptr;
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate     while ((key = va_arg(ap, int)) > 0) {
50*0Sstevel@tonic-gate 	switch (key) {
51*0Sstevel@tonic-gate 	default:
52*0Sstevel@tonic-gate 	    tcpd_warn("request_fill: invalid key: %d", key);
53*0Sstevel@tonic-gate 	    return (request);
54*0Sstevel@tonic-gate 	case RQ_FILE:
55*0Sstevel@tonic-gate 	    request->fd = va_arg(ap, int);
56*0Sstevel@tonic-gate 	    continue;
57*0Sstevel@tonic-gate 	case RQ_CLIENT_SIN:
58*0Sstevel@tonic-gate 	    request->client->sin = va_arg(ap, struct sockaddr_gen *);
59*0Sstevel@tonic-gate 	    continue;
60*0Sstevel@tonic-gate 	case RQ_SERVER_SIN:
61*0Sstevel@tonic-gate 	    request->server->sin = va_arg(ap, struct sockaddr_gen *);
62*0Sstevel@tonic-gate 	    continue;
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate 	    /*
65*0Sstevel@tonic-gate 	     * All other fields are strings with the same maximal length.
66*0Sstevel@tonic-gate 	     */
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate 	case RQ_DAEMON:
69*0Sstevel@tonic-gate 	    ptr = request->daemon;
70*0Sstevel@tonic-gate 	    break;
71*0Sstevel@tonic-gate 	case RQ_USER:
72*0Sstevel@tonic-gate 	    ptr = request->user;
73*0Sstevel@tonic-gate 	    break;
74*0Sstevel@tonic-gate 	case RQ_CLIENT_NAME:
75*0Sstevel@tonic-gate 	    ptr = request->client->name;
76*0Sstevel@tonic-gate 	    break;
77*0Sstevel@tonic-gate 	case RQ_CLIENT_ADDR:
78*0Sstevel@tonic-gate 	    ptr = request->client->addr;
79*0Sstevel@tonic-gate 	    break;
80*0Sstevel@tonic-gate 	case RQ_SERVER_NAME:
81*0Sstevel@tonic-gate 	    ptr = request->server->name;
82*0Sstevel@tonic-gate 	    break;
83*0Sstevel@tonic-gate 	case RQ_SERVER_ADDR:
84*0Sstevel@tonic-gate 	    ptr = request->server->addr;
85*0Sstevel@tonic-gate 	    break;
86*0Sstevel@tonic-gate 	}
87*0Sstevel@tonic-gate 	STRN_CPY(ptr, va_arg(ap, char *), STRING_LENGTH);
88*0Sstevel@tonic-gate     }
89*0Sstevel@tonic-gate     return (request);
90*0Sstevel@tonic-gate }
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate /* request_init - initialize request structure */
93*0Sstevel@tonic-gate 
VARARGS(request_init,struct request_info *,request)94*0Sstevel@tonic-gate struct request_info *VARARGS(request_init, struct request_info *, request)
95*0Sstevel@tonic-gate {
96*0Sstevel@tonic-gate     static struct request_info default_info;
97*0Sstevel@tonic-gate     struct request_info *r;
98*0Sstevel@tonic-gate     va_list ap;
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate     /*
101*0Sstevel@tonic-gate      * Initialize data members. We do not assign default function pointer
102*0Sstevel@tonic-gate      * members, to avoid pulling in the whole socket module when it is not
103*0Sstevel@tonic-gate      * really needed.
104*0Sstevel@tonic-gate      */
105*0Sstevel@tonic-gate     VASTART(ap, struct request_info *, request);
106*0Sstevel@tonic-gate     *request = default_info;
107*0Sstevel@tonic-gate     request->fd = -1;
108*0Sstevel@tonic-gate     strcpy(request->daemon, unknown);
109*0Sstevel@tonic-gate     sprintf(request->pid, "%d", getpid());
110*0Sstevel@tonic-gate     request->client->request = request;
111*0Sstevel@tonic-gate     request->server->request = request;
112*0Sstevel@tonic-gate     r = request_fill(request, ap);
113*0Sstevel@tonic-gate     VAEND(ap);
114*0Sstevel@tonic-gate     return (r);
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate /* request_set - update request structure */
118*0Sstevel@tonic-gate 
VARARGS(request_set,struct request_info *,request)119*0Sstevel@tonic-gate struct request_info *VARARGS(request_set, struct request_info *, request)
120*0Sstevel@tonic-gate {
121*0Sstevel@tonic-gate     struct request_info *r;
122*0Sstevel@tonic-gate     va_list ap;
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate     VASTART(ap, struct request_info *, request);
125*0Sstevel@tonic-gate     r = request_fill(request, ap);
126*0Sstevel@tonic-gate     VAEND(ap);
127*0Sstevel@tonic-gate     return (r);
128*0Sstevel@tonic-gate }
129