4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
39 #pragma ident "%Z%%M% %I% %E% SMI"
45 static int rnetrc(char *host
, char **aname
, char **apass
, char **aacct
);
46 static int token(void);
49 ruserpass(char *host
, char **aname
, char **apass
, char **aacct
)
52 renv(host
, aname
, apass
, aacct
);
53 if (*aname
== 0 || *apass
== 0)
55 return (rnetrc(host
, aname
, apass
, aacct
));
67 static char tokval
[100];
69 static struct toktab
{
84 rnetrc(char *host
, char **aname
, char **apass
, char **aacct
)
86 char *hdir
, buf
[PATH_MAX
+1], *tmp
;
91 hdir
= getenv("HOME");
94 if (snprintf(buf
, sizeof (buf
), "%s/.netrc", hdir
) >= sizeof (buf
)) {
95 fprintf(stderr
, ".netrc: %s\n", strerror(ENAMETOOLONG
));
99 cfile
= fopen(buf
, "r");
106 while ((t
= token()))
110 if (token() != ID
|| strcmp(host
, tokval
))
112 /* "machine name" matches host */
116 /* "default" matches any host */
117 while (((t
= token()) != 0) && t
!= MACHINE
&& t
!= DEFAULT
)
123 *aname
= malloc((unsigned)
125 if (*aname
== NULL
) {
127 "Error - out of VM\n");
130 (void) strcpy(*aname
, tokval
);
132 if (strcmp(*aname
, tokval
))
137 if (fstat(fileno(cfile
), &stb
) >= 0 &&
138 (stb
.st_mode
& 077) != 0) {
139 fprintf(stderr
, "Error - .netrc file not "
141 fprintf(stderr
, "Remove password or correct "
145 if (token() && *apass
== 0) {
146 *apass
= malloc((unsigned)strlen(tokval
) + 1);
147 if (*apass
== NULL
) {
148 fprintf(stderr
, "Error - out of VM\n");
151 (void) strcpy(*apass
, tokval
);
155 if (fstat(fileno(cfile
), &stb
) >= 0 &&
156 (stb
.st_mode
& 077) != 0) {
157 fprintf(stderr
, "Error - .netrc file not "
159 fprintf(stderr
, "Remove account or correct "
163 if (token() && *aacct
== 0) {
164 *aacct
= malloc((unsigned)strlen(tokval
) + 1);
165 if (*aacct
== NULL
) {
166 fprintf(stderr
, "Error - out of VM\n");
169 (void) strcpy(*aacct
, tokval
);
176 while ((c
= getc(cfile
)) != EOF
&& c
== ' ' ||
178 if (c
== EOF
|| c
== '\n') {
179 printf("Missing macdef name argument.\n");
183 printf("Limit of 16 macros have already "
187 tmp
= macros
[macnum
].mac_name
;
189 for (i
= 0; i
< 8 && (c
= getc(cfile
)) != EOF
&&
194 printf("Macro definition for `%s` missing "
195 "null line terminator.\n",
196 macros
[macnum
].mac_name
);
201 while ((c
= getc(cfile
)) != EOF
&& c
!= '\n');
204 printf("Macro definition for `%s` missing "
205 "null line terminator.\n",
206 macros
[macnum
].mac_name
);
210 macros
[macnum
].mac_start
= macbuf
;
212 macros
[macnum
].mac_start
=
213 macros
[macnum
-1].mac_end
+ 1;
215 tmp
= macros
[macnum
].mac_start
;
216 while (tmp
!= macbuf
+ 4096) {
217 if ((c
= getc(cfile
)) == EOF
) {
218 printf("Macro definition for `%s` missing "
219 "null line terminator.\n",
220 macros
[macnum
].mac_name
);
225 if (*(tmp
-1) == '\0') {
226 macros
[macnum
++].mac_end
=
234 if (tmp
== macbuf
+ 4096) {
235 printf("4K macro buffer exceeded\n");
238 if (*macros
[macnum
- 1].mac_start
== '\n') {
239 printf("Macro definition for `%s` is empty, "
240 "macro not stored.\n",
241 macros
[--macnum
].mac_name
);
248 fprintf(stderr
, "Unknown .netrc keyword %s\n", tokval
);
254 (void) fclose(cfile
);
268 while ((c
= fgetwc(cfile
)) != EOF
&&
269 (c
== '\n' || c
== '\t' || c
== ' ' || c
== ','))
275 while ((c
= fgetwc(cfile
)) != EOF
&& c
!= '"') {
278 if ((len
= wctomb(cp
, c
)) <= 0) {
280 *cp
= (unsigned char)c
;
285 if ((len
= wctomb(cp
, c
)) <= 0) {
286 *cp
= (unsigned char)c
;
290 while ((c
= fgetwc(cfile
)) != EOF
&& c
!= '\n' && c
!= '\t' &&
291 c
!= ' ' && c
!= ',') {
294 if ((len
= wctomb(cp
, c
)) <= 0) {
296 *cp
= (unsigned char)c
;
304 for (t
= toktab
; t
->tokstr
; t
++)
305 if (strcmp(t
->tokstr
, tokval
) == 0)