-/*
+/* 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 <h/mh.h>
#include <h/utils.h>
#include <h/mts.h>
+#include "m_maildir.h"
struct nmh_creds {
char *host; /* Hostname corresponding to credentials */
};
void
-init_credentials_file () {
+init_credentials_file(void) {
if (credentials_file == NULL) {
char *cred_style = context_find ("credentials");
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);
}
}
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)) {
/*
* 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;
}
void
nmh_credentials_free(nmh_creds_t creds)
{
- if (creds->host)
- free(creds->host);
-
- if (creds->user)
- free(creds->user);
+ mh_xfree(creds->host);
+ mh_xfree(creds->user);
if (creds->pass) {
memset(creds->pass, 0, strlen(creds->pass));