rcmd.c (929273386f6e688c008b15fd24932df2ed7e7172) | rcmd.c (42b4f28ebdf07192c1a09a8711cb7c31a09b9381) |
---|---|
1/* 2 * Copyright (c) 1983, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 45 unchanged lines hidden (view full) --- 54#include <ctype.h> 55#include <string.h> 56#ifdef YP 57#include <rpc/rpc.h> 58#include <rpcsvc/yp_prot.h> 59#include <rpcsvc/ypclnt.h> 60#endif 61 | 1/* 2 * Copyright (c) 1983, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 45 unchanged lines hidden (view full) --- 54#include <ctype.h> 55#include <string.h> 56#ifdef YP 57#include <rpc/rpc.h> 58#include <rpcsvc/yp_prot.h> 59#include <rpcsvc/ypclnt.h> 60#endif 61 |
62/* wrapper for KAME-special getnameinfo() */ 63#ifndef NI_WITHSCOPEID 64#define NI_WITHSCOPEID 0 65#endif 66 |
|
62extern int innetgr __P(( const char *, const char *, const char *, const char * )); 63 64#define max(a, b) ((a > b) ? a : b) 65 66int __ivaliduser __P((FILE *, u_int32_t, const char *, const char *)); | 67extern int innetgr __P(( const char *, const char *, const char *, const char * )); 68 69#define max(a, b) ((a > b) ? a : b) 70 71int __ivaliduser __P((FILE *, u_int32_t, const char *, const char *)); |
67static int __icheckhost __P((u_int32_t, char *)); | 72static int __icheckhost __P((void *, char *, int, int)); |
68 | 73 |
74char paddr[INET6_ADDRSTRLEN]; 75 |
|
69int 70rcmd(ahost, rport, locuser, remuser, cmd, fd2p) 71 char **ahost; 72 u_short rport; 73 const char *locuser, *remuser, *cmd; 74 int *fd2p; 75{ | 76int 77rcmd(ahost, rport, locuser, remuser, cmd, fd2p) 78 char **ahost; 79 u_short rport; 80 const char *locuser, *remuser, *cmd; 81 int *fd2p; 82{ |
76 struct hostent *hp; 77 struct sockaddr_in sin, from; | 83 struct addrinfo hints, *res, *ai; 84 struct sockaddr_storage from; |
78 fd_set reads; 79 long oldmask; 80 pid_t pid; | 85 fd_set reads; 86 long oldmask; 87 pid_t pid; |
81 int s, lport, timo; | 88 int s, aport, lport, timo, error; |
82 char c; | 89 char c; |
90 int refused; 91 char num[8]; |
|
83 84 pid = getpid(); | 92 93 pid = getpid(); |
85 hp = gethostbyname(*ahost); 86 if (hp == NULL) { 87 herror(*ahost); | 94 95 memset(&hints, 0, sizeof(hints)); 96 hints.ai_flags = AI_CANONNAME; 97 hints.ai_family = AF_UNSPEC; 98 hints.ai_socktype = SOCK_STREAM; 99 hints.ai_protocol = 0; 100 (void)snprintf(num, sizeof(num), "%d", ntohs(rport)); 101 error = getaddrinfo(*ahost, num, &hints, &res); 102 if (error) { 103 fprintf(stderr, "rcmd: getaddrinfo: %s\n", 104 gai_strerror(error)); 105 if (error == EAI_SYSTEM) 106 fprintf(stderr, "rcmd: getaddrinfo: %s\n", 107 strerror(errno)); |
88 return (-1); 89 } | 108 return (-1); 109 } |
90 *ahost = hp->h_name; | 110 if (res->ai_canonname) 111 *ahost = res->ai_canonname; 112 ai = res; 113 refused = 0; |
91 oldmask = sigblock(sigmask(SIGURG)); 92 for (timo = 1, lport = IPPORT_RESERVED - 1;;) { | 114 oldmask = sigblock(sigmask(SIGURG)); 115 for (timo = 1, lport = IPPORT_RESERVED - 1;;) { |
93 s = rresvport(&lport); | 116 s = rresvport_af(&lport, ai->ai_family); |
94 if (s < 0) { 95 if (errno == EAGAIN) 96 (void)fprintf(stderr, 97 "rcmd: socket: All ports in use\n"); 98 else 99 (void)fprintf(stderr, "rcmd: socket: %s\n", 100 strerror(errno)); 101 sigsetmask(oldmask); | 117 if (s < 0) { 118 if (errno == EAGAIN) 119 (void)fprintf(stderr, 120 "rcmd: socket: All ports in use\n"); 121 else 122 (void)fprintf(stderr, "rcmd: socket: %s\n", 123 strerror(errno)); 124 sigsetmask(oldmask); |
125 freeaddrinfo(res); |
|
102 return (-1); 103 } 104 _libc_fcntl(s, F_SETOWN, pid); | 126 return (-1); 127 } 128 _libc_fcntl(s, F_SETOWN, pid); |
105 bzero(&sin, sizeof sin); 106 sin.sin_len = sizeof(struct sockaddr_in); 107 sin.sin_family = hp->h_addrtype; 108 sin.sin_port = rport; 109 bcopy(hp->h_addr_list[0], &sin.sin_addr, MIN(hp->h_length, sizeof sin.sin_addr)); 110 if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) | 129 if (connect(s, ai->ai_addr, ai->ai_addrlen) >= 0) |
111 break; 112 (void)_libc_close(s); 113 if (errno == EADDRINUSE) { 114 lport--; 115 continue; 116 } | 130 break; 131 (void)_libc_close(s); 132 if (errno == EADDRINUSE) { 133 lport--; 134 continue; 135 } |
117 if (errno == ECONNREFUSED && timo <= 16) { 118 (void)_libc_sleep(timo); 119 timo *= 2; 120 continue; 121 } 122 if (hp->h_addr_list[1] != NULL) { | 136 if (errno == ECONNREFUSED) 137 refused = 1; 138 if (ai->ai_next != NULL) { |
123 int oerrno = errno; 124 | 139 int oerrno = errno; 140 |
141 getnameinfo(ai->ai_addr, ai->ai_addrlen, 142 paddr, sizeof(paddr), 143 NULL, 0, 144 NI_NUMERICHOST|NI_WITHSCOPEID); |
|
125 (void)fprintf(stderr, "connect to address %s: ", | 145 (void)fprintf(stderr, "connect to address %s: ", |
126 inet_ntoa(sin.sin_addr)); | 146 paddr); |
127 errno = oerrno; 128 perror(0); | 147 errno = oerrno; 148 perror(0); |
129 hp->h_addr_list++; 130 bcopy(hp->h_addr_list[0], &sin.sin_addr, MIN(hp->h_length, sizeof sin.sin_addr)); 131 (void)fprintf(stderr, "Trying %s...\n", 132 inet_ntoa(sin.sin_addr)); | 149 ai = ai->ai_next; 150 getnameinfo(ai->ai_addr, ai->ai_addrlen, 151 paddr, sizeof(paddr), 152 NULL, 0, 153 NI_NUMERICHOST|NI_WITHSCOPEID); 154 fprintf(stderr, "Trying %s...\n", paddr); |
133 continue; 134 } | 155 continue; 156 } |
135 (void)fprintf(stderr, "%s: %s\n", hp->h_name, strerror(errno)); | 157 if (refused && timo <= 16) { 158 (void)_libc_sleep(timo); 159 timo *= 2; 160 ai = res; 161 refused = 0; 162 continue; 163 } 164 freeaddrinfo(res); 165 (void)fprintf(stderr, "%s: %s\n", *ahost, strerror(errno)); |
136 sigsetmask(oldmask); 137 return (-1); 138 } 139 lport--; 140 if (fd2p == 0) { 141 _libc_write(s, "", 1); 142 lport = 0; 143 } else { 144 char num[8]; | 166 sigsetmask(oldmask); 167 return (-1); 168 } 169 lport--; 170 if (fd2p == 0) { 171 _libc_write(s, "", 1); 172 lport = 0; 173 } else { 174 char num[8]; |
145 int s2 = rresvport(&lport), s3; 146 int len = sizeof(from); | 175 int s2 = rresvport_af(&lport, ai->ai_family), s3; 176 int len = ai->ai_addrlen; |
147 int nfds; 148 149 if (s2 < 0) 150 goto bad; 151 listen(s2, 1); 152 (void)snprintf(num, sizeof(num), "%d", lport); 153 if (_libc_write(s, num, strlen(num)+1) != strlen(num)+1) { 154 (void)fprintf(stderr, --- 20 unchanged lines hidden (view full) --- 175 strerror(errno)); 176 else 177 (void)fprintf(stderr, 178 "select: protocol failure in circuit setup\n"); 179 (void)_libc_close(s2); 180 goto bad; 181 } 182 s3 = accept(s2, (struct sockaddr *)&from, &len); | 177 int nfds; 178 179 if (s2 < 0) 180 goto bad; 181 listen(s2, 1); 182 (void)snprintf(num, sizeof(num), "%d", lport); 183 if (_libc_write(s, num, strlen(num)+1) != strlen(num)+1) { 184 (void)fprintf(stderr, --- 20 unchanged lines hidden (view full) --- 205 strerror(errno)); 206 else 207 (void)fprintf(stderr, 208 "select: protocol failure in circuit setup\n"); 209 (void)_libc_close(s2); 210 goto bad; 211 } 212 s3 = accept(s2, (struct sockaddr *)&from, &len); |
213 switch (from.ss_family) { 214 case AF_INET: 215 aport = ntohs(((struct sockaddr_in *)&from)->sin_port); 216 break; 217#ifdef INET6 218 case AF_INET6: 219 aport = ntohs(((struct sockaddr_in6 *)&from)->sin6_port); 220 break; 221#endif 222 default: 223 aport = 0; /* error */ 224 break; 225 } |
|
183 /* 184 * XXX careful for ftp bounce attacks. If discovered, shut them 185 * down and check for the real auxiliary channel to connect. 186 */ | 226 /* 227 * XXX careful for ftp bounce attacks. If discovered, shut them 228 * down and check for the real auxiliary channel to connect. 229 */ |
187 if (from.sin_family == AF_INET && from.sin_port == htons(20)) { | 230 if (aport == 20) { |
188 _libc_close(s3); 189 goto again; 190 } 191 (void)_libc_close(s2); 192 if (s3 < 0) { 193 (void)fprintf(stderr, 194 "rcmd: accept: %s\n", strerror(errno)); 195 lport = 0; 196 goto bad; 197 } 198 *fd2p = s3; | 231 _libc_close(s3); 232 goto again; 233 } 234 (void)_libc_close(s2); 235 if (s3 < 0) { 236 (void)fprintf(stderr, 237 "rcmd: accept: %s\n", strerror(errno)); 238 lport = 0; 239 goto bad; 240 } 241 *fd2p = s3; |
199 from.sin_port = ntohs((u_short)from.sin_port); 200 if (from.sin_family != AF_INET || 201 from.sin_port >= IPPORT_RESERVED || 202 from.sin_port < IPPORT_RESERVED / 2) { | 242 if (aport >= IPPORT_RESERVED || aport < IPPORT_RESERVED / 2) { |
203 (void)fprintf(stderr, 204 "socket: protocol failure in circuit setup.\n"); 205 goto bad2; 206 } 207 } 208 (void)_libc_write(s, locuser, strlen(locuser)+1); 209 (void)_libc_write(s, remuser, strlen(remuser)+1); 210 (void)_libc_write(s, cmd, strlen(cmd)+1); --- 6 unchanged lines hidden (view full) --- 217 while (_libc_read(s, &c, 1) == 1) { 218 (void)_libc_write(STDERR_FILENO, &c, 1); 219 if (c == '\n') 220 break; 221 } 222 goto bad2; 223 } 224 sigsetmask(oldmask); | 243 (void)fprintf(stderr, 244 "socket: protocol failure in circuit setup.\n"); 245 goto bad2; 246 } 247 } 248 (void)_libc_write(s, locuser, strlen(locuser)+1); 249 (void)_libc_write(s, remuser, strlen(remuser)+1); 250 (void)_libc_write(s, cmd, strlen(cmd)+1); --- 6 unchanged lines hidden (view full) --- 257 while (_libc_read(s, &c, 1) == 1) { 258 (void)_libc_write(STDERR_FILENO, &c, 1); 259 if (c == '\n') 260 break; 261 } 262 goto bad2; 263 } 264 sigsetmask(oldmask); |
265 freeaddrinfo(res); |
|
225 return (s); 226bad2: 227 if (lport) 228 (void)_libc_close(*fd2p); 229bad: 230 (void)_libc_close(s); 231 sigsetmask(oldmask); | 266 return (s); 267bad2: 268 if (lport) 269 (void)_libc_close(*fd2p); 270bad: 271 (void)_libc_close(s); 272 sigsetmask(oldmask); |
273 freeaddrinfo(res); |
|
232 return (-1); 233} 234 235int | 274 return (-1); 275} 276 277int |
236rresvport(alport) 237 int *alport; | 278rresvport(port) 279 int *port; |
238{ | 280{ |
239 struct sockaddr_in sin; 240 int s; | 281 return rresvport_af(port, AF_INET); 282} |
241 | 283 |
242 bzero(&sin, sizeof sin); 243 sin.sin_len = sizeof(struct sockaddr_in); 244 sin.sin_family = AF_INET; 245 sin.sin_addr.s_addr = INADDR_ANY; 246 s = socket(AF_INET, SOCK_STREAM, 0); | 284int 285rresvport_af(alport, family) 286 int *alport, family; 287{ 288 int i, s, len, err; 289 struct sockaddr_storage ss; 290 u_short *sport; 291 292 memset(&ss, 0, sizeof(ss)); 293 ss.ss_family = family; 294 switch (family) { 295 case AF_INET: 296 ((struct sockaddr *)&ss)->sa_len = sizeof(struct sockaddr_in); 297 sport = &((struct sockaddr_in *)&ss)->sin_port; 298 ((struct sockaddr_in *)&ss)->sin_addr.s_addr = INADDR_ANY; 299 break; 300#ifdef INET6 301 case AF_INET6: 302 ((struct sockaddr *)&ss)->sa_len = sizeof(struct sockaddr_in6); 303 sport = &((struct sockaddr_in6 *)&ss)->sin6_port; 304 ((struct sockaddr_in6 *)&ss)->sin6_addr = in6addr_any; 305 break; 306#endif 307 default: 308 errno = EAFNOSUPPORT; 309 return -1; 310 } 311 312 s = socket(ss.ss_family, SOCK_STREAM, 0); |
247 if (s < 0) 248 return (-1); 249#if 0 /* compat_exact_traditional_rresvport_semantics */ 250 sin.sin_port = htons((u_short)*alport); 251 if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) 252 return (s); 253 if (errno != EADDRINUSE) { 254 (void)_libc_close(s); 255 return (-1); 256 } 257#endif | 313 if (s < 0) 314 return (-1); 315#if 0 /* compat_exact_traditional_rresvport_semantics */ 316 sin.sin_port = htons((u_short)*alport); 317 if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) 318 return (s); 319 if (errno != EADDRINUSE) { 320 (void)_libc_close(s); 321 return (-1); 322 } 323#endif |
258 sin.sin_port = 0; 259 if (bindresvport(s, &sin) == -1) { | 324 *sport = 0; 325 if (bindresvport2(s, (struct sockaddr *)&ss, 326 ((struct sockaddr *)&ss)->sa_len) == -1) { |
260 (void)_libc_close(s); 261 return (-1); 262 } | 327 (void)_libc_close(s); 328 return (-1); 329 } |
263 *alport = (int)ntohs(sin.sin_port); | 330 *alport = (int)ntohs(*sport); |
264 return (s); 265} 266 267int __check_rhosts_file = 1; 268char *__rcmd_errstr; 269 270int 271ruserok(rhost, superuser, ruser, luser) 272 const char *rhost, *ruser, *luser; 273 int superuser; 274{ | 331 return (s); 332} 333 334int __check_rhosts_file = 1; 335char *__rcmd_errstr; 336 337int 338ruserok(rhost, superuser, ruser, luser) 339 const char *rhost, *ruser, *luser; 340 int superuser; 341{ |
342 return ruserok_af(rhost, superuser, ruser, luser, AF_INET); 343} 344 345int 346ruserok_af(rhost, superuser, ruser, luser, af) 347 const char *rhost, *ruser, *luser; 348 int superuser, af; 349{ |
|
275 struct hostent *hp; | 350 struct hostent *hp; |
276 u_int32_t addr; | 351 union { 352 struct in_addr addr_in; 353 struct in6_addr addr_in6; 354 } addr; |
277 char **ap; | 355 char **ap; |
356 int ret, h_error; |
|
278 | 357 |
279 if ((hp = gethostbyname(rhost)) == NULL) | 358 if ((hp = getipnodebyname(rhost, af, AI_DEFAULT, &h_error)) == NULL) |
280 return (-1); | 359 return (-1); |
360 ret = -1; |
|
281 for (ap = hp->h_addr_list; *ap; ++ap) { | 361 for (ap = hp->h_addr_list; *ap; ++ap) { |
282 bcopy(*ap, &addr, sizeof(addr)); 283 if (iruserok(addr, superuser, ruser, luser) == 0) 284 return (0); | 362 bcopy(*ap, &addr, hp->h_length); 363 if (iruserok_af(&addr, superuser, ruser, luser, af) == 0) { 364 ret = 0; 365 break; 366 } |
285 } | 367 } |
286 return (-1); | 368 freehostent(hp); 369 return (ret); |
287} 288 289/* 290 * New .rhosts strategy: We are passed an ip address. We spin through 291 * hosts.equiv and .rhosts looking for a match. When the .rhosts only 292 * has ip addresses, we don't have to trust a nameserver. When it 293 * contains hostnames, we spin through the list of addresses the nameserver 294 * gives us and look for a match. 295 * 296 * Returns 0 if ok, -1 if not ok. 297 */ 298int 299iruserok(raddr, superuser, ruser, luser) 300 unsigned long raddr; 301 int superuser; 302 const char *ruser, *luser; 303{ | 370} 371 372/* 373 * New .rhosts strategy: We are passed an ip address. We spin through 374 * hosts.equiv and .rhosts looking for a match. When the .rhosts only 375 * has ip addresses, we don't have to trust a nameserver. When it 376 * contains hostnames, we spin through the list of addresses the nameserver 377 * gives us and look for a match. 378 * 379 * Returns 0 if ok, -1 if not ok. 380 */ 381int 382iruserok(raddr, superuser, ruser, luser) 383 unsigned long raddr; 384 int superuser; 385 const char *ruser, *luser; 386{ |
387 return iruserok_af(&raddr, superuser, ruser, luser, AF_INET); 388} 389 390int 391iruserok_af(raddr, superuser, ruser, luser, af) 392 void *raddr; 393 int superuser; 394 const char *ruser, *luser; 395 int af; 396{ |
|
304 register char *cp; 305 struct stat sbuf; 306 struct passwd *pwd; 307 FILE *hostf; 308 uid_t uid; 309 int first; 310 char pbuf[MAXPATHLEN]; | 397 register char *cp; 398 struct stat sbuf; 399 struct passwd *pwd; 400 FILE *hostf; 401 uid_t uid; 402 int first; 403 char pbuf[MAXPATHLEN]; |
404 int len = 0; |
|
311 | 405 |
406 switch (af) { 407 case AF_INET: 408 len = sizeof(struct in_addr); 409 break; 410#ifdef INET6 411 case AF_INET6: 412 len = sizeof(struct in6_addr); 413 break; 414#endif 415 } 416 |
|
312 first = 1; 313 hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r"); 314again: 315 if (hostf) { | 417 first = 1; 418 hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r"); 419again: 420 if (hostf) { |
316 if (__ivaliduser(hostf, (u_int32_t)raddr, luser, ruser) == 0) { | 421 if (__ivaliduser_af(hostf, raddr, luser, ruser, af, len) 422 == 0) { |
317 (void)fclose(hostf); 318 return (0); 319 } 320 (void)fclose(hostf); 321 } 322 if (first == 1 && (__check_rhosts_file || superuser)) { 323 first = 0; 324 if ((pwd = getpwnam(luser)) == NULL) --- 46 unchanged lines hidden (view full) --- 371 * Returns 0 if ok, -1 if not ok. 372 */ 373int 374__ivaliduser(hostf, raddr, luser, ruser) 375 FILE *hostf; 376 u_int32_t raddr; 377 const char *luser, *ruser; 378{ | 423 (void)fclose(hostf); 424 return (0); 425 } 426 (void)fclose(hostf); 427 } 428 if (first == 1 && (__check_rhosts_file || superuser)) { 429 first = 0; 430 if ((pwd = getpwnam(luser)) == NULL) --- 46 unchanged lines hidden (view full) --- 477 * Returns 0 if ok, -1 if not ok. 478 */ 479int 480__ivaliduser(hostf, raddr, luser, ruser) 481 FILE *hostf; 482 u_int32_t raddr; 483 const char *luser, *ruser; 484{ |
485 return __ivaliduser_af(hostf, &raddr, luser, ruser, AF_INET, 486 sizeof(raddr)); 487} 488 489int 490__ivaliduser_af(hostf, raddr, luser, ruser, af, len) 491 FILE *hostf; 492 void *raddr; 493 const char *luser, *ruser; 494 int af, len; 495{ |
|
379 register char *user, *p; 380 int ch; 381 char buf[MAXHOSTNAMELEN + 128]; /* host + login */ 382 char hname[MAXHOSTNAMELEN]; 383 struct hostent *hp; 384 /* Presumed guilty until proven innocent. */ 385 int userok = 0, hostok = 0; | 496 register char *user, *p; 497 int ch; 498 char buf[MAXHOSTNAMELEN + 128]; /* host + login */ 499 char hname[MAXHOSTNAMELEN]; 500 struct hostent *hp; 501 /* Presumed guilty until proven innocent. */ 502 int userok = 0, hostok = 0; |
503 int h_error; |
|
386#ifdef YP 387 char *ypdomain; 388 389 if (yp_get_default_domain(&ypdomain)) 390 ypdomain = NULL; 391#else 392#define ypdomain NULL 393#endif 394 /* We need to get the damn hostname back for netgroup matching. */ | 504#ifdef YP 505 char *ypdomain; 506 507 if (yp_get_default_domain(&ypdomain)) 508 ypdomain = NULL; 509#else 510#define ypdomain NULL 511#endif 512 /* We need to get the damn hostname back for netgroup matching. */ |
395 if ((hp = gethostbyaddr((char *)&raddr, sizeof(u_int32_t), 396 AF_INET)) == NULL) | 513 if ((hp = getipnodebyaddr((char *)raddr, len, af, &h_error)) == NULL) |
397 return (-1); 398 strncpy(hname, hp->h_name, sizeof(hname)); 399 hname[sizeof(hname) - 1] = '\0'; | 514 return (-1); 515 strncpy(hname, hp->h_name, sizeof(hname)); 516 hname[sizeof(hname) - 1] = '\0'; |
517 freehostent(hp); |
|
400 401 while (fgets(buf, sizeof(buf), hostf)) { 402 p = buf; 403 /* Skip lines that are too long. */ 404 if (strchr(p, '\n') == NULL) { 405 while ((ch = getc(hostf)) != '\n' && ch != EOF); 406 continue; 407 } --- 25 unchanged lines hidden (view full) --- 433 if (!buf[1]) { /* '+' matches all hosts */ 434 hostok = 1; 435 break; 436 } 437 if (buf[1] == '@') /* match a host by netgroup */ 438 hostok = innetgr((char *)&buf[2], 439 (char *)&hname, NULL, ypdomain); 440 else /* match a host by addr */ | 518 519 while (fgets(buf, sizeof(buf), hostf)) { 520 p = buf; 521 /* Skip lines that are too long. */ 522 if (strchr(p, '\n') == NULL) { 523 while ((ch = getc(hostf)) != '\n' && ch != EOF); 524 continue; 525 } --- 25 unchanged lines hidden (view full) --- 551 if (!buf[1]) { /* '+' matches all hosts */ 552 hostok = 1; 553 break; 554 } 555 if (buf[1] == '@') /* match a host by netgroup */ 556 hostok = innetgr((char *)&buf[2], 557 (char *)&hname, NULL, ypdomain); 558 else /* match a host by addr */ |
441 hostok = __icheckhost(raddr,(char *)&buf[1]); | 559 hostok = __icheckhost(raddr,(char *)&buf[1], 560 af, len); |
442 break; 443 case '-': /* reject '-' hosts and all their users */ 444 if (buf[1] == '@') { 445 if (innetgr((char *)&buf[2], 446 (char *)&hname, NULL, ypdomain)) 447 return(-1); 448 } else { | 561 break; 562 case '-': /* reject '-' hosts and all their users */ 563 if (buf[1] == '@') { 564 if (innetgr((char *)&buf[2], 565 (char *)&hname, NULL, ypdomain)) 566 return(-1); 567 } else { |
449 if (__icheckhost(raddr,(char *)&buf[1])) | 568 if (__icheckhost(raddr,(char *)&buf[1],af,len)) |
450 return(-1); 451 } 452 break; 453 default: /* if no '+' or '-', do a simple match */ | 569 return(-1); 570 } 571 break; 572 default: /* if no '+' or '-', do a simple match */ |
454 hostok = __icheckhost(raddr, buf); | 573 hostok = __icheckhost(raddr, buf, af, len); |
455 break; 456 } 457 switch(*user) { 458 case '+': 459 if (!*(user+1)) { /* '+' matches all users */ 460 userok = 1; 461 break; 462 } --- 26 unchanged lines hidden (view full) --- 489 } 490 return (-1); 491} 492 493/* 494 * Returns "true" if match, 0 if no match. 495 */ 496static int | 574 break; 575 } 576 switch(*user) { 577 case '+': 578 if (!*(user+1)) { /* '+' matches all users */ 579 userok = 1; 580 break; 581 } --- 26 unchanged lines hidden (view full) --- 608 } 609 return (-1); 610} 611 612/* 613 * Returns "true" if match, 0 if no match. 614 */ 615static int |
497__icheckhost(raddr, lhost) 498 u_int32_t raddr; | 616__icheckhost(raddr, lhost, af, len) 617 void *raddr; |
499 register char *lhost; | 618 register char *lhost; |
619 int af, len; |
|
500{ 501 register struct hostent *hp; | 620{ 621 register struct hostent *hp; |
502 register u_int32_t laddr; | 622 char laddr[BUFSIZ]; /* xxx */ |
503 register char **pp; | 623 register char **pp; |
624 int h_error; 625 int match; |
|
504 505 /* Try for raw ip address first. */ | 626 627 /* Try for raw ip address first. */ |
506 if (isdigit((unsigned char)*lhost) && (u_int32_t)(laddr = inet_addr(lhost)) != -1) 507 return (raddr == laddr); | 628 if (inet_pton(af, lhost, laddr) == 1) { 629 if (memcmp(raddr, laddr, len) == 0) 630 return (1); 631 else 632 return (0); 633 } |
508 509 /* Better be a hostname. */ | 634 635 /* Better be a hostname. */ |
510 if ((hp = gethostbyname(lhost)) == NULL) | 636 if ((hp = getipnodebyname(lhost, af, AI_DEFAULT, &h_error)) == NULL) |
511 return (0); 512 513 /* Spin through ip addresses. */ | 637 return (0); 638 639 /* Spin through ip addresses. */ |
640 match = 0; |
|
514 for (pp = hp->h_addr_list; *pp; ++pp) | 641 for (pp = hp->h_addr_list; *pp; ++pp) |
515 if (!bcmp(&raddr, *pp, sizeof(u_int32_t))) 516 return (1); | 642 if (!bcmp(raddr, *pp, len)) { 643 match = 1; 644 break; 645 } |
517 | 646 |
518 /* No match. */ 519 return (0); | 647 freehostent(hp); 648 return (match); |
520} | 649} |