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