]> git.saurik.com Git - apple/network_cmds.git/blame - bootparams/bootparamd.tproj/bootparam_proc.c
network_cmds-176.2.1.tar.gz
[apple/network_cmds.git] / bootparams / bootparamd.tproj / bootparam_proc.c
CommitLineData
b7080c8e
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
921c0aec
A
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
b7080c8e
A
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
921c0aec
A
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
b7080c8e
A
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25 * BOOTPARAMS server
26 * Copyright 1998, Apple Computer Inc. Unpublished.
27 *
28 * Written by Marc Majka
29 */
30
31#include <rpc/rpc.h>
32#include "bootparam_prot.h"
33#include <stdio.h>
34#include <string.h>
35#include <unistd.h>
36#include <stdlib.h>
37#include <sys/types.h>
38#include <sys/socket.h>
39#include <netdb.h>
40#include <bootparams.h>
41#include <syslog.h>
42
43extern int debug;
44extern unsigned long route_addr;
45extern char domain_name[];
46
47struct hostent *h;
48static char hostname[MAXHOSTNAMELEN];
49
50bp_whoami_res *
51bootparamproc_whoami_1_svc(whoami, req)
52bp_whoami_arg *whoami;
53struct svc_req *req;
54{
55 long haddr;
56 static bp_whoami_res res;
57 struct bootparamsent *bp;
58
59 if (debug)
60 {
61 fprintf(stderr,"whoami %d.%d.%d.%d\n",
62 255 & whoami->client_address.bp_address_u.ip_addr.net,
63 255 & whoami->client_address.bp_address_u.ip_addr.host,
64 255 & whoami->client_address.bp_address_u.ip_addr.lh,
65 255 & whoami->client_address.bp_address_u.ip_addr.impno);
66 }
67
68 bcopy((char *)&whoami->client_address.bp_address_u.ip_addr,
69 (char *)&haddr, sizeof(haddr));
70 h = gethostbyaddr((char *)&haddr, sizeof(haddr), AF_INET);
71 if (h == NULL)
72 {
73 if (debug) fprintf(stderr,"whoami failed: gethostbyaddr\n");
74 return NULL;
75 }
76
77 /* check whether subsequent bpgetfile requests would succeed */
78 bp = bootparams_getbyname(h->h_name);
79 if (bp == NULL) {
80 if (debug)
81 fprintf(stderr, "whoami failed: bootparams_getbyname\n");
82 return NULL;
83 }
84
85 sprintf(hostname, "%s", h->h_name);
86 res.client_name = hostname;
87
88 res.domain_name = domain_name;
89
90 res.router_address.address_type = IP_ADDR_TYPE;
91 bcopy(&route_addr, &res.router_address.bp_address_u.ip_addr, 4);
92
93 if (debug)
94 {
95 fprintf(stderr, "whoami name=%s domain=%s router=%d.%d.%d.%d\n",
96 res.client_name,
97 res.domain_name,
98 255 & res.router_address.bp_address_u.ip_addr.net,
99 255 & res.router_address.bp_address_u.ip_addr.host,
100 255 & res.router_address.bp_address_u.ip_addr.lh,
101 255 & res.router_address.bp_address_u.ip_addr.impno);
102 }
103
104 return (&res);
105}
106
107bp_getfile_res *
108bootparamproc_getfile_1_svc(getfile, req)
109bp_getfile_arg *getfile;
110struct svc_req *req;
111{
112 static bp_getfile_res res;
113 struct bootparamsent *bp;
114 static char s[1024];
115 char *p;
116 int i, len;
117
118 if (debug)
119 {
120 fprintf(stderr, "getfile %s %s\n",
121 getfile->client_name, getfile->file_id);
122 }
123
124 bp = bootparams_getbyname(getfile->client_name);
125 if (bp == NULL)
126 {
127 if (debug)
128 {
129 fprintf(stderr, "can't find bootparams for %s\n",
130 getfile->client_name);
131 fprintf(stderr, "getfile failed\n");
132 }
133 return NULL;
134 }
135
136 len = strlen(getfile->file_id) + 1;
137 sprintf(s, "%s=", getfile->file_id);
138
139 for (i = 0; bp->bp_bootparams[i] != NULL; i++)
140 {
141 if (!strncmp(s, bp->bp_bootparams[i], len)) break;
142 }
143
144 if (bp->bp_bootparams[i] == NULL)
145 {
146 if (debug)
147 {
148 fprintf(stderr, "can't find bootparam %s\n", getfile->file_id);
149 fprintf(stderr, "getfile failed\n");
150 }
151 return NULL;
152 }
153
154 sprintf(s, bp->bp_bootparams[i] + len);
155 p = strchr(s, ':');
156 if (p == NULL)
157 {
158 hostname[0] = '\0';
159 res.server_name = hostname;
160 res.server_address.bp_address_u.ip_addr.net = 0;
161 res.server_address.bp_address_u.ip_addr.host = 0;
162 res.server_address.bp_address_u.ip_addr.lh = 0;
163 res.server_address.bp_address_u.ip_addr.impno = 0;
164 res.server_address.address_type = 1;
165 res.server_path = s;
166
167 if (debug)
168 {
169 fprintf(stderr, "getfile server=%s (%d.%d.%d.%d) path=%s\n",
170 res.server_name,
171 255 & res.server_address.bp_address_u.ip_addr.net,
172 255 & res.server_address.bp_address_u.ip_addr.host,
173 255 & res.server_address.bp_address_u.ip_addr.lh,
174 255 & res.server_address.bp_address_u.ip_addr.impno,
175 res.server_path);
176 }
177 return (&res);
178 }
179
180 *p = '\0';
181 p++;
182 h = gethostbyname(s);
183 if (h == NULL)
184 {
185 if (debug)
186 {
187 fprintf(stderr, "can't find server %s\n", s);
188 fprintf(stderr, "getfile failed\n");
189 }
190 return NULL;
191 }
192
193 res.server_name = s;
194 res.server_path = p;
195 bcopy(h->h_addr, &res.server_address.bp_address_u.ip_addr, h->h_length);
196 res.server_address.address_type = IP_ADDR_TYPE;
197
198 if (debug)
199 {
200 fprintf(stderr, "getfile server=%s (%d.%d.%d.%d) path=%s\n",
201 res.server_name,
202 255 & res.server_address.bp_address_u.ip_addr.net,
203 255 & res.server_address.bp_address_u.ip_addr.host,
204 255 & res.server_address.bp_address_u.ip_addr.lh,
205 255 & res.server_address.bp_address_u.ip_addr.impno,
206 res.server_path);
207 }
208
209 return (&res);
210}