4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <sys/types.h>
54 #define NTOKENS (MAXTOKEN - 1 + 2 + 1) /* two duplicates and null, minus id */
56 static void rnetrc(char *, char **, char **);
57 static int token(void);
59 static struct ruserdata
{
66 } *ruserdata
, *_ruserdata(void);
69 static struct ruserdata
*
72 struct ruserdata
*d
= ruserdata
;
76 if ((d
= (struct ruserdata
*)
77 calloc(1, sizeof(struct ruserdata
))) == NULL
) {
82 t
->tokstr
= "default"; t
++->tval
= DEFAULT
;
83 t
->tokstr
= "login"; t
++->tval
= LOGIN
;
84 t
->tokstr
= "password"; t
++->tval
= PASSWD
;
85 t
->tokstr
= "notify"; t
++->tval
= NOTIFY
;
86 t
->tokstr
= "write"; t
++->tval
= WRITE
;
87 t
->tokstr
= "yes"; t
++->tval
= YES
;
88 t
->tokstr
= "y"; t
++->tval
= YES
;
89 t
->tokstr
= "no"; t
++->tval
= NO
;
90 t
->tokstr
= "n"; t
++->tval
= NO
;
91 t
->tokstr
= "command"; t
++->tval
= COMMAND
;
92 t
->tokstr
= "force"; t
++->tval
= FORCE
;
93 t
->tokstr
= "machine"; t
++->tval
= MACHINE
;
94 t
->tokstr
= 0; t
->tval
= 0;
100 _ruserpass(char *host
, char **aname
, char **apass
)
103 if (*aname
== 0 || *apass
== 0)
104 rnetrc(host
, aname
, apass
);
106 char *myname
= getlogin();
108 printf("Name (%s:%s): ", host
, myname
);
110 if (read(2, *aname
, 16) <= 0)
112 if ((*aname
)[0] == '\n')
115 if (index(*aname
, '\n'))
116 *index(*aname
, '\n') = 0;
118 if (*aname
&& *apass
== 0) {
119 printf("Password (%s:%s): ", host
, *aname
);
121 *apass
= getpass("");
127 rnetrc(char *host
, char **aname
, char **apass
)
129 struct ruserdata
*d
= _ruserdata();
130 char *hdir
, buf
[BUFSIZ
];
137 hdir
= getenv("HOME");
140 sprintf(buf
, "%s/.netrc", hdir
);
141 d
->cfile
= fopen(buf
, "r");
142 if (d
->cfile
== NULL
) {
148 while ((t
= token())) switch(t
) {
155 if (token() != ID
|| strcmp(host
, d
->tokval
))
157 while ((t
= token()) && t
!= MACHINE
) switch(t
) {
162 *aname
= malloc(strlen(d
->tokval
) + 1);
163 strcpy(*aname
, d
->tokval
);
165 if (strcmp(*aname
, d
->tokval
))
170 if (fstat(fileno(d
->cfile
), &stb
) >= 0
171 && (stb
.st_mode
& 077) != 0) {
172 fprintf(stderr
, "Error - .netrc file not correct mode.\n");
173 fprintf(stderr
, "Remove password or correct mode.\n");
176 if (token() && *apass
== 0) {
177 *apass
= malloc(strlen(d
->tokval
) + 1);
178 strcpy(*apass
, d
->tokval
);
188 fprintf(stderr
, "Unknown .netrc option %s\n", d
->tokval
);
200 struct ruserdata
*d
= _ruserdata();
210 while ((c
= getc(d
->cfile
)) != EOF
&&
211 (c
== '\n' || c
== '\t' || c
== ' ' || c
== ','))
217 while ((c
= getc(d
->cfile
)) != EOF
&& c
!= '"') {
224 while ((c
= getc(d
->cfile
)) != EOF
225 && c
!= '\n' && c
!= '\t' && c
!= ' ' && c
!= ',') {
232 if (d
->tokval
[0] == 0)
234 for (t
= d
->toktab
; t
->tokstr
; t
++)
235 if (!strcmp(t
->tokstr
, d
->tokval
))