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. 10 * 11 * Diagnostics are reported through syslog(3). 12 * 13 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. 14 * 15 * $FreeBSD$ 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#) update.c 1.1 94/12/28 17:42:56"; 20 #endif 21 22 /* System libraries */ 23 24 #include <stdio.h> 25 #include <syslog.h> 26 #include <string.h> 27 #include <unistd.h> 28 29 /* Local stuff. */ 30 31 #include "mystdarg.h" 32 #include "tcpd.h" 33 34 /* request_fill - request update engine */ 35 36 static struct request_info *request_fill(struct request_info *request, 37 va_list ap) 38 { 39 int key; 40 char *ptr; 41 42 while ((key = va_arg(ap, int)) > 0) { 43 switch (key) { 44 default: 45 tcpd_warn("request_fill: invalid key: %d", key); 46 return (request); 47 case RQ_FILE: 48 request->fd = va_arg(ap, int); 49 continue; 50 case RQ_CLIENT_SIN: 51 #ifdef INET6 52 request->client->sin = va_arg(ap, struct sockaddr *); 53 #else 54 request->client->sin = va_arg(ap, struct sockaddr_in *); 55 #endif 56 continue; 57 case RQ_SERVER_SIN: 58 #ifdef INET6 59 request->server->sin = va_arg(ap, struct sockaddr *); 60 #else 61 request->server->sin = va_arg(ap, struct sockaddr_in *); 62 #endif 63 continue; 64 65 /* 66 * All other fields are strings with the same maximal length. 67 */ 68 69 case RQ_DAEMON: 70 ptr = request->daemon; 71 break; 72 case RQ_USER: 73 ptr = request->user; 74 break; 75 case RQ_CLIENT_NAME: 76 ptr = request->client->name; 77 break; 78 case RQ_CLIENT_ADDR: 79 ptr = request->client->addr; 80 break; 81 case RQ_SERVER_NAME: 82 ptr = request->server->name; 83 break; 84 case RQ_SERVER_ADDR: 85 ptr = request->server->addr; 86 break; 87 } 88 STRN_CPY(ptr, va_arg(ap, char *), STRING_LENGTH); 89 } 90 return (request); 91 } 92 93 /* request_init - initialize request structure */ 94 95 struct request_info *VARARGS(request_init, struct request_info *, request) 96 { 97 static struct request_info default_info; 98 struct request_info *r; 99 va_list ap; 100 101 /* 102 * Initialize data members. We do not assign default function pointer 103 * members, to avoid pulling in the whole socket module when it is not 104 * really needed. 105 */ 106 VASTART(ap, struct request_info *, request); 107 *request = default_info; 108 request->fd = -1; 109 strcpy(request->daemon, unknown); 110 sprintf(request->pid, "%d", getpid()); 111 request->client->request = request; 112 request->server->request = request; 113 r = request_fill(request, ap); 114 VAEND(ap); 115 return (r); 116 } 117 118 /* request_set - update request structure */ 119 120 struct request_info *VARARGS(request_set, struct request_info *, request) 121 { 122 struct request_info *r; 123 va_list ap; 124 125 VASTART(ap, struct request_info *, request); 126 r = request_fill(request, ap); 127 VAEND(ap); 128 return (r); 129 } 130