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