Magellan Linux

Annotation of /trunk/netkit-rsh/netkit-rsh-0.17-rexec-netrc.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (hide annotations) (download)
Fri Jan 19 23:50:26 2007 UTC (17 years, 4 months ago) by niro
File size: 6850 byte(s)
new files

1 niro 97 --- netkit-rsh-0.17/rexec/ruserpass.c.netrc 2004-10-14 12:02:04.000000000 -0500
2     +++ netkit-rsh-0.17/rexec/ruserpass.c 2004-10-14 12:14:14.000000000 -0500
3     @@ -0,0 +1,214 @@
4     +/*
5     + * Copyright (c) 1985 Regents of the University of California.
6     + * All rights reserved.
7     + *
8     + * Redistribution and use in source and binary forms, with or without
9     + * modification, are permitted provided that the following conditions
10     + * are met:
11     + * 1. Redistributions of source code must retain the above copyright
12     + * 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.
16     + * 3. All advertising materials mentioning features or use of this software
17     + * must display the following acknowledgement:
18     + * This product includes software developed by the University of
19     + * California, Berkeley and its contributors.
20     + * 4. Neither the name of the University nor the names of its contributors
21     + * may be used to endorse or promote products derived from this software
22     + * without specific prior written permission.
23     + *
24     + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25     + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26     + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27     + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28     + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29     + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30     + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31     + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32     + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33     + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34     + * SUCH DAMAGE.
35     + */
36     +
37     +/*
38     + * from: @(#)ruserpass.c 5.3 (Berkeley) 3/1/91
39     + */
40     +char ruserpass_rcsid[] =
41     + "$Id: netkit-rsh-0.17-rexec-netrc.patch,v 1.1 2007-01-19 23:50:26 niro Exp $";
42     +
43     +#include <stdio.h>
44     +#include <stdlib.h>
45     +#include <utmp.h>
46     +#include <ctype.h>
47     +#include <sys/stat.h>
48     +#include <sys/param.h>
49     +#include <errno.h>
50     +#include <string.h>
51     +#include <unistd.h>
52     +
53     +static FILE *cfile;
54     +static int token(void);
55     +
56     +#define MACBUF_LEN 4096
57     +
58     +#define DEFAULT 1
59     +#define LOGIN 2
60     +#define PASSWD 3
61     +#define ACCOUNT 4
62     +#define MACDEF 5
63     +#define ID 10
64     +#define MACH 11
65     +
66     +static char tokval[100];
67     +
68     +static struct toktab {
69     + const char *tokstr;
70     + int tval;
71     +} toktab[]= {
72     + { "default", DEFAULT },
73     + { "login", LOGIN },
74     + { "password", PASSWD },
75     + { "passwd", PASSWD },
76     + { "account", ACCOUNT },
77     + { "machine", MACH },
78     + { "macdef", MACDEF },
79     + { NULL, 0 }
80     +};
81     +
82     +int
83     +xruserpass(const char *host, char **aname, char **apass)
84     +{
85     + const char *hdir;
86     + char buf[BUFSIZ], *tmp;
87     + char myname[MAXHOSTNAMELEN];
88     + const char *mydomain;
89     + int t, usedefault = 0;
90     + struct stat stb;
91     +
92     + hdir = getenv("HOME");
93     + if (hdir == NULL)
94     + hdir = ".";
95     + snprintf(buf, sizeof(buf), "%s/.netrc", hdir);
96     + cfile = fopen(buf, "r");
97     + if (cfile == NULL) {
98     + if (errno != ENOENT)
99     + perror(buf);
100     + return(0);
101     + }
102     + if (gethostname(myname, sizeof(myname)) < 0)
103     + myname[0] = '\0';
104     + if ((mydomain = strchr(myname, '.')) == NULL)
105     + mydomain = "";
106     +next:
107     + while ((t = token())) switch(t) {
108     +
109     + case DEFAULT:
110     + usedefault = 1;
111     + /* FALL THROUGH */
112     +
113     + case MACH:
114     + if (!usedefault) {
115     + if (token() != ID)
116     + continue;
117     + /*
118     + * Allow match of incompletely-specified host in
119     + * local domain.
120     + */
121     + if (strcasecmp(host, tokval) == 0)
122     + goto match;
123     + if ((tmp = index(host, '.')) != NULL &&
124     + strcasecmp(tmp, mydomain) == 0 &&
125     + strncasecmp(host, tokval, tmp - host) == 0 &&
126     + tokval[tmp - host] == '\0')
127     + goto match;
128     + continue;
129     + }
130     + match:
131     + while ((t = token()) && t != MACH && t != DEFAULT) switch(t) {
132     +
133     + case LOGIN:
134     + if (token()) {
135     + if (*aname == 0) {
136     + *aname = malloc((unsigned) strlen(tokval) + 1);
137     + (void) strcpy(*aname, tokval);
138     + } else {
139     + if (strcmp(*aname, tokval))
140     + goto next;
141     + }
142     + }
143     + break;
144     + case PASSWD:
145     + if (*aname==NULL) {
146     + fprintf(stderr, "Error: `password' must follow `login' in .netrc\n");
147     + goto bad;
148     + }
149     + if (strcmp(*aname, "anonymous") &&
150     + fstat(fileno(cfile), &stb) >= 0 &&
151     + (stb.st_mode & 077) != 0) {
152     + fprintf(stderr, "Error - .netrc file not correct permissions.\n");
153     + fprintf(stderr, "Remove password or correct mode (should be 600).\n");
154     + goto bad;
155     + }
156     + if (token() && *apass == 0) {
157     + *apass = malloc((unsigned) strlen(tokval) + 1);
158     + (void) strcpy(*apass, tokval);
159     + }
160     + break;
161     + case ACCOUNT:
162     + break;
163     + case MACDEF:
164     + break;
165     + default:
166     + fprintf(stderr, "Unknown .netrc keyword %s\n", tokval);
167     + break;
168     + }
169     + goto done;
170     + }
171     +done:
172     + (void) fclose(cfile);
173     + return(0);
174     +bad:
175     + (void) fclose(cfile);
176     + return(-1);
177     +}
178     +
179     +static
180     +int
181     +token(void)
182     +{
183     + char *cp;
184     + int c;
185     + struct toktab *t;
186     +
187     + if (feof(cfile))
188     + return (0);
189     + while ((c = getc(cfile)) != EOF &&
190     + (c == '\n' || c == '\t' || c == ' ' || c == ','))
191     + continue;
192     + if (c == EOF)
193     + return (0);
194     + cp = tokval;
195     + if (c == '"') {
196     + while ((c = getc(cfile)) != EOF && c != '"') {
197     + if (c == '\\')
198     + c = getc(cfile);
199     + *cp++ = c;
200     + }
201     + } else {
202     + *cp++ = c;
203     + while ((c = getc(cfile)) != EOF
204     + && c != '\n' && c != '\t' && c != ' ' && c != ',') {
205     + if (c == '\\')
206     + c = getc(cfile);
207     + *cp++ = c;
208     + }
209     + }
210     + *cp = 0;
211     + if (tokval[0] == 0)
212     + return (0);
213     + for (t = toktab; t->tokstr; t++)
214     + if (!strcmp(t->tokstr, tokval))
215     + return (t->tval);
216     + return (ID);
217     +}
218     --- netkit-rsh-0.17/rexec/rexec.c.netrc 2004-10-14 12:02:04.000000000 -0500
219     +++ netkit-rsh-0.17/rexec/rexec.c 2004-10-14 12:16:46.000000000 -0500
220     @@ -100,6 +100,8 @@
221     void echo_sig(int sig);
222     void safe_write_error(const char *message);
223    
224     +int xruserpass(const char *host, char **aname, char **apass);
225     +
226     /* These need to be global for signal passing. */
227     int aux_sock=-1; /* Socket for auxiliary channel. */
228     int extra_error = 1; /* Setup special channel for standard error? */
229     @@ -165,7 +167,10 @@
230     a newline. */
231     passwd = getpass("Password: ");
232     } else {
233     -
234     + if (xruserpass(host, &user_name, &passwd) < 0) {
235     + user_name = NULL;
236     + passwd = NULL;
237     + }
238     if ( user_name == NULL )
239     user_name = getenv("REXEC_USER");
240     if ( user_name == NULL ) {
241     --- netkit-rsh-0.17/rexec/Makefile.netrc 2004-10-14 12:15:30.000000000 -0500
242     +++ netkit-rsh-0.17/rexec/Makefile 2004-10-14 12:03:37.000000000 -0500
243     @@ -11,7 +11,7 @@
244    
245     all: rexec
246    
247     -rexec: rexec.c
248     +rexec: rexec.o ruserpass.o
249    
250     rexec.1:
251