X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/90edb255effd0d29d94e662ca5bf3e9eda7ed122..4b4ffd574ddde175987011dce7f5dd223f9cf2aa:/sbr/credentials.c diff --git a/sbr/credentials.c b/sbr/credentials.c index 9000e5ed..910e097d 100644 --- a/sbr/credentials.c +++ b/sbr/credentials.c @@ -1,12 +1,19 @@ -/* +/* credentials.c -- wrap configurable access to .netrc or similar files. + * * This code is Copyright (c) 2013, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. */ -#include -#include -#include +#include "h/mh.h" +#include "concat.h" +#include "ruserpass.h" +#include "credentials.h" +#include "context_find.h" +#include "error.h" +#include "h/utils.h" +#include "h/mts.h" +#include "m_maildir.h" struct nmh_creds { char *host; /* Hostname corresponding to credentials */ @@ -15,7 +22,8 @@ struct nmh_creds { }; void -init_credentials_file () { +init_credentials_file(void) +{ if (credentials_file == NULL) { char *cred_style = context_find ("credentials"); @@ -28,7 +36,8 @@ init_credentials_file () { struct stat st; char *filename = strchr(cred_style, ':') + 1; - while (*filename && isspace ((unsigned char) *filename)) ++filename; + while (isspace((unsigned char)*filename)) + filename++; if (*filename == '/') { credentials_file = filename; @@ -38,7 +47,7 @@ init_credentials_file () { credentials_file = concat (mypath ? mypath : ".", "/", filename, NULL); if (stat (credentials_file, &st) != OK) { - admonish (NULL, "unable to find credentials file %s", + inform("unable to find credentials file %s, continuing...", filename); } } @@ -61,12 +70,12 @@ nmh_get_credentials (const char *host, const char *user) creds = mh_xmalloc(sizeof(*creds)); - creds->host = getcpy(host); + creds->host = mh_xstrdup(host); creds->user = NULL; creds->pass = NULL; if (cred_style == NULL || ! strcmp (cred_style, "legacy")) { - creds->user = user == NULL ? getcpy(getusername ()) : getcpy(user); + creds->user = user == NULL ? mh_xstrdup(getusername ()) : mh_xstrdup(user); } else if (! strncasecmp (cred_style, "file:", 5) || ! strncasecmp (cred_style, "file-nopermcheck:", 17)) { /* @@ -77,9 +86,9 @@ nmh_get_credentials (const char *host, const char *user) * 3) interactively request from user (as long as the * credentials file didn't have a "default" token) */ - creds->user = user == NULL ? NULL : getcpy(user); + creds->user = user == NULL ? NULL : mh_xstrdup(user); } else { - admonish (NULL, "unknown credentials style %s", cred_style); + inform("unknown credentials style %s, continuing...", cred_style); return NULL; } @@ -125,11 +134,8 @@ nmh_cred_get_password(nmh_creds_t creds) void nmh_credentials_free(nmh_creds_t creds) { - if (creds->host) - free(creds->host); - - if (creds->user) - free(creds->user); + free(creds->host); + free(creds->user); if (creds->pass) { memset(creds->pass, 0, strlen(creds->pass));