]>
diplodocus.org Git - nmh/blob - sbr/ruserpass.c
2 * Portions of this code are
3 * Copyright (c) 1985 Regents of the University of California.
6 * Redistribution and use in source and binary forms are permitted
7 * provided that the above copyright notice and this paragraph are
8 * duplicated in all such forms and that any documentation,
9 * advertising materials, and other materials related to such
10 * distribution and use acknowledge that the software was developed
11 * by the University of California, Berkeley. The name of the
12 * University may not be used to endorse or promote products derived
13 * from this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 * Portions of this code are Copyright (c) 2013, by the authors of
19 * nmh. See the COPYRIGHT file in the root directory of the nmh
20 * distribution for complete copyright information.
37 static char tokval
[100];
44 static struct toktab toktabs
[] = {
45 { "default", DEFAULT
},
47 { "password", PASSWD
},
49 { "account", ACCOUNT
},
58 static int token(void);
62 ruserpass(char *host
, char **aname
, char **apass
)
64 int t
, usedefault
= 0;
67 init_credentials_file ();
69 cfile
= fopen (credentials_file
, "r");
72 perror (credentials_file
);
74 while ((t
= token())) {
85 * Allow match either for user's host name.
87 if (strcasecmp(host
, tokval
) == 0)
92 while ((t
= token()) && t
!= MACH
&& t
!= DEFAULT
) {
95 if (token() && *aname
== 0) {
96 *aname
= mh_xmalloc((size_t) strlen(tokval
) + 1);
97 strcpy(*aname
, tokval
);
102 if (fstat(fileno(cfile
), &stb
) >= 0 &&
103 (stb
.st_mode
& 077) != 0) {
104 /* We make this a fatal error to force the
105 user to correct it. */
106 advise(NULL
, "Error - file %s must not be world or "
107 "group readable.", credentials_file
);
108 adios(NULL
, "Remove password or correct file "
111 if (token() && *apass
== 0) {
112 *apass
= mh_xmalloc((size_t) strlen(tokval
) + 1);
113 strcpy(*apass
, tokval
);
126 "Unknown keyword %s in credentials file %s\n",
127 tokval
, credentials_file
);
140 if ((myname
= getlogin()) == NULL
) {
143 if ((pp
= getpwuid (getuid())) != NULL
)
144 myname
= pp
->pw_name
;
146 printf("Name (%s:%s): ", host
, myname
);
148 fgets(tmp
, sizeof(tmp
) - 1, stdin
);
149 tmp
[strlen(tmp
) - 1] = '\0';
154 *aname
= mh_xmalloc((size_t) strlen(myname
) + 1);
155 strcpy (*aname
, myname
);
162 snprintf(prompt
, sizeof(prompt
), "Password (%s:%s): ", host
, *aname
);
163 mypass
= nmh_getpass(prompt
);
165 if (*mypass
== '\0') {
169 *apass
= mh_xmalloc((size_t) strlen(mypass
) + 1);
170 strcpy (*apass
, mypass
);
184 while ((c
= getc(cfile
)) != EOF
&&
185 (c
== '\n' || c
== '\t' || c
== ' ' || c
== ','))
191 while ((c
= getc(cfile
)) != EOF
&& c
!= '"') {
198 while ((c
= getc(cfile
)) != EOF
199 && c
!= '\n' && c
!= '\t' && c
!= ' ' && c
!= ',') {
208 for (t
= toktabs
; t
->tokstr
; t
++)
209 if (!strcmp(t
->tokstr
, tokval
))