]>
diplodocus.org Git - nmh/blob - sbr/credentials.c
2 * This code is Copyright (c) 2013, by the authors of nmh. See the
3 * COPYRIGHT file in the root directory of the nmh distribution for
4 * complete copyright information.
12 init_credentials_file () {
13 if (credentials_file
== NULL
) {
14 char *cred_style
= context_find ("credentials");
16 if (cred_style
== NULL
|| ! strcmp (cred_style
, "legacy")) {
17 char *hdir
= getenv ("HOME");
19 credentials_file
= concat (hdir
? hdir
: ".", "/.netrc", NULL
);
20 } else if (! strncasecmp (cred_style
, "file:", 5)) {
22 char *filename
= cred_style
+ 5;
24 while (*filename
&& isspace ((unsigned char) *filename
)) ++filename
;
26 if (*filename
== '/') {
27 credentials_file
= filename
;
29 credentials_file
= m_maildir (filename
);
30 if (stat (credentials_file
, &st
) != OK
) {
32 concat (mypath
? mypath
: ".", "/", filename
, NULL
);
33 if (stat (credentials_file
, &st
) != OK
) {
34 admonish (NULL
, "unable to find credentials file %s",
44 nmh_get_credentials (char *host
, char *user
, int sasl
, nmh_creds_t creds
) {
45 char *cred_style
= context_find ("credentials");
47 init_credentials_file ();
50 if (cred_style
== NULL
|| ! strcmp (cred_style
, "legacy")) {
51 creds
->user
= user
== NULL
? getusername () : user
;
54 /* This is what inc.c and msgchk.c used to contain. */
55 /* Only inc.c and msgchk.c do this. smtp.c doesn't. */
56 creds
->password
= getusername ();
58 } else if (! strncasecmp (cred_style
, "file:", 5)) {
60 * Determine user using the first of:
62 * 2) matching host entry with login in a credentials file
64 * 3) interactively request from user (as long as the
65 * credentials file didn't have a "default" token)
69 admonish (NULL
, "unknown credentials style %s", cred_style
);
73 ruserpass (host
, &creds
->user
, &creds
->password
);