2 * Copyright (c) 1995 - 2000 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 RCSID("$Id: rcmd_util.c,v 1.19.2.1 2000/06/23 02:34:48 assar Exp $");
39 get_login_port(int kerberos, int encryption)
41 char *service="login";
44 if(kerberos && encryption){
49 if(kerberos && !encryption){
53 return k_getportbyname (service, "tcp", port);
57 get_shell_port(int kerberos, int encryption)
59 char *service="shell";
62 if(kerberos && encryption){
67 if(kerberos && !encryption){
72 return k_getportbyname (service, "tcp", port);
76 * On reasonable systems, `cf[gs]et[io]speed' use values of bit/s
77 * directly, and the following functions are just identity functions.
78 * This is however a slower way of doing those
79 * should-be-but-are-not-always idenity functions.
82 static struct { int speed; int bps; } conv[] = {
157 #define N (sizeof(conv)/sizeof(*conv))
160 speed_t2int (speed_t s)
168 if (conv[m].speed == s)
170 else if(conv[m].speed < s)
191 if (conv[m].bps == i)
192 return conv[m].speed;
193 else if(conv[m].bps < i)
202 * If there are any IP options on `sock', die.
206 ip_options_and_die (int sock, struct sockaddr_in *fromp)
208 #if defined(IP_OPTIONS) && defined(HAVE_GETSOCKOPT)
209 u_char optbuf[BUFSIZ/3], *cp;
210 char lbuf[BUFSIZ], *lp;
211 int optsize = sizeof(optbuf), ipproto;
214 if ((ip = getprotobyname("ip")) != NULL)
215 ipproto = ip->p_proto;
217 ipproto = IPPROTO_IP;
218 if (getsockopt(sock, ipproto, IP_OPTIONS,
219 (void *)optbuf, &optsize) == 0 &&
222 for (cp = optbuf; optsize > 0; cp++, optsize--, lp += 3)
223 snprintf(lp, sizeof(lbuf) - (lp - lbuf), " %2.2x", *cp);
225 "Connection received from %s using IP options (dead):%s",
226 inet_ntoa(fromp->sin_addr), lbuf);
233 warning(const char *fmt, ...)
235 char *rstar_no_warn = getenv("RSTAR_NO_WARN");
239 if (rstar_no_warn == NULL)
241 if (strncmp(rstar_no_warn, "yes", 3) != 0) {
243 fprintf(stderr, "%s: warning, using standard ", __progname);
250 * setuid but work-around Linux 2.2.15 bug with setuid and capabilities
254 paranoid_setuid (uid_t uid)
256 if (setuid (uid) < 0)
258 if (uid != 0 && setuid (0) == 0) {
259 syslog(LOG_ALERT | LOG_AUTH,
260 "Failed to drop privileges for uid %u", (unsigned)uid);