* Never returns NULL.
*/
const char *
-mh_oauth_cred_fn(mh_oauth_ctx *ctx);
+mh_oauth_cred_fn(const char *svc_name);
/*
* Serialize OAuth tokens to file.
mh_oauth_get_service_info(const char *svc_name, mh_oauth_service_info *svcinfo,
char *errbuf, size_t errbuflen);
-char *
-mh_oauth_node_name_for_svc(const char *entry, const char *svc_name);
+char *mh_oauth_get_svc_name(mh_oauth_ctx *ctx);
+void mh_oauth_set_cred_fn(mh_oauth_ctx *ctx, char *filename);
int sc_width(void);
int build_form (char *, char *, int *, char *, char *, char *, char *,
char *, char *);
-int sendsbr (char **, int, char *, char *, struct stat *, int);
+int sendsbr (char **, int, char *, char *, struct stat *, int, const char *);
int SOprintf (char *, ...);
int what_now (char *, int, int, char *, char *,
int, struct msgs *, char *, int, char *, int);
if (log != NULL) mh_oauth_log_to(stderr, ctx);
- fn = getcpy(mh_oauth_cred_fn(ctx));
+ fn = getcpy(mh_oauth_cred_fn(svc));
fp = lkfopendata(fn, "r+", &failed_to_lock);
if (fp == NULL) {
if (errno == ENOENT) {
free(cred);
}
-const char *
-mh_oauth_cred_fn(mh_oauth_ctx *ctx)
-{
- char *result, *result_if_allocated;
- const char *svc = ctx->svc.name;
-
- char *component = mh_oauth_node_name_for_svc("credential-file", svc);
- result = context_find(component);
- free(component);
-
- if (result == NULL) {
- result = mh_xmalloc(sizeof "oauth-" - 1
- + strlen(svc)
- + 1 /* '\0' */);
- sprintf(result, "oauth-%s", svc);
- result_if_allocated = result;
- } else {
- result_if_allocated = NULL;
- }
-
- if (result[0] != '/') {
- const char *tmp = m_maildir(result);
- free(result_if_allocated);
- result = getcpy(tmp);
- }
-
- free(ctx->cred_fn);
- return ctx->cred_fn = result;
-}
-
/* for loading multi-user cred files */
struct user_creds {
mh_oauth_cred *creds;
free(tokens);
return result;
}
-
#endif
return TRUE;
}
+
+const char *
+mh_oauth_cred_fn(const char *svc)
+{
+ char *result, *result_if_allocated;
+
+ char *component = mh_oauth_node_name_for_svc("credential-file", svc);
+ result = context_find(component);
+ free(component);
+
+ if (result == NULL) {
+ result = mh_xmalloc(sizeof "oauth-" - 1
+ + strlen(svc)
+ + 1 /* '\0' */);
+ sprintf(result, "oauth-%s", svc);
+ result_if_allocated = result;
+ } else {
+ result_if_allocated = NULL;
+ }
+
+ if (result[0] != '/') {
+ const char *tmp = m_maildir(result);
+ free(result_if_allocated);
+ result = getcpy(tmp);
+ }
+
+ return result;
+}
#endif
mh_oauth_log_to(stderr, ctx);
}
- fn = getcpy(mh_oauth_cred_fn(ctx));
+ fn = getcpy(mh_oauth_cred_fn(svc));
if ((url = mh_oauth_get_authorize_url(ctx)) == NULL) {
adios(NULL, mh_oauth_get_err_string(ctx));
if (user == NULL) {
adios (NULL, "must specify -user with -saslmech xoauth2");
}
-
- vec[vecp++] = "-authservice";
- if (saslmech && ! strcasecmp(saslmech, "xoauth2")) {
- vec[vecp++] = mh_oauth_do_xoauth (user, auth_svc, snoop ? stderr : NULL);
- } else {
- vec[vecp++] = auth_svc;
- }
}
#else
NMH_UNUSED(auth_svc);
closefds (3);
for (msgnum = 0; msgnum < msgp; msgnum++) {
- switch (sendsbr (vec, vecp, program, msgs[msgnum], &st, 1)) {
+ switch (sendsbr (vec, vecp, program, msgs[msgnum], &st, 1, auth_svc)) {
case DONE:
done (++status);
case NOTOK:
#ifdef OAUTH_SUPPORT
#include <h/oauth.h>
-static int setup_oauth_params(char *[], int *, const char **);
+static int setup_oauth_params(char *[], int *, const char *, const char **);
#endif /* OAUTH_SUPPORT */
int debugsw = 0; /* global */
static void annoaux (int);
static int splitmsg (char **, int, char *, char *, struct stat *, int);
static int sendaux (char **, int, char *, char *, struct stat *);
-static void handle_sendfrom(char **, int *, char *);
+static void handle_sendfrom(char **, int *, char *, const char *);
static int get_from_header_info(const char *, const char **, const char **, const char **);
static const char *get_message_header_info(FILE *, char *);
static void merge_profile_entry(const char *, const char *, char *[], int *);
int
sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
- int rename_drft)
+ int rename_drft, const char *auth_svc)
{
int status, i;
pid_t child;
drft = file;
}
+ /*
+ * Add in any necessary profile entries for xoauth
+ */
+
+ if (auth_svc) {
+ const char *errmsg;
+ if (!setup_oauth_params(vec, nvecsp, auth_svc, &errmsg))
+ adios(NULL, "%s", errmsg);
+ }
+
/*
* Rework the vec based on From: header in draft, as specified
* by sendfrom-address entries in profile.
*/
if (context_find_prefix("sendfrom-")) {
- handle_sendfrom(vec, nvecsp, draft);
+ handle_sendfrom(vec, nvecsp, draft, auth_svc);
}
/*
static
void
-handle_sendfrom(char **vec, int *vecp, char *draft) {
+handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc) {
const char *addr, *host;
const char *message;
for (vp = vec; *vp; ++vp) {
if (strcmp(*vp, "xoauth2") == 0) {
#ifdef OAUTH_SUPPORT
- if (setup_oauth_params(vec, vecp, &message) != OK) {
+ if (setup_oauth_params(vec, vecp, auth_svc, &message) != OK) {
adios(NULL, message);
}
break;
* For XOAUTH2, append profile entries so post can do the heavy lifting
*/
static int
-setup_oauth_params(char *vec[], int *vecp, const char **message) {
- const char *saslmech = NULL, *user = NULL, *auth_svc = NULL;
+setup_oauth_params(char *vec[], int *vecp, const char *auth_svc,
+ const char **message) {
+ const char *saslmech = NULL, *user = NULL;
mh_oauth_service_info svc;
char errbuf[256];
int i;
return NOTOK;
}
-
- vec[(*vecp)++] = getcpy("-authservice");
if (saslmech && ! strcasecmp(saslmech, "xoauth2")) {
- vec[(*vecp)++] = mh_oauth_do_xoauth(user, auth_svc, snoop ? stderr : NULL);
- } else {
- vec[(*vecp)++] = getcpy(auth_svc);
+ if (! mh_oauth_get_service_info(auth_svc, &svc, errbuf,
+ sizeof(errbuf)))
+ adios(NULL, "Unable to retrieve oauth profile entries: %s",
+ errbuf);
+
+ vec[(*vecp)++] = getcpy("-oauthcredfile");
+ vec[(*vecp)++] = getcpy(mh_oauth_cred_fn(auth_svc));
+ vec[(*vecp)++] = getcpy("-oauthclientid");
+ vec[(*vecp)++] = getcpy(svc.client_id);
+ vec[(*vecp)++] = getcpy("-oauthclientsecret");
+ vec[(*vecp)++] = getcpy(svc.client_secret);
+ vec[(*vecp)++] = getcpy("-oauthauthendpoint");
+ vec[(*vecp)++] = getcpy(svc.auth_endpoint);
+ vec[(*vecp)++] = getcpy("-oauthredirect");
+ vec[(*vecp)++] = getcpy(svc.redirect_uri);
+ vec[(*vecp)++] = getcpy("-oauthtokenendpoint");
+ vec[(*vecp)++] = getcpy(svc.token_endpoint);
+ vec[(*vecp)++] = getcpy("-oauthscope");
+ vec[(*vecp)++] = getcpy(svc.scope);
}
}
vec[vecp++] = cp;
}
- switch (sendsbr (vec, vecp, program, tmpfil, &st, 0)) {
+ switch (sendsbr (vec, vecp, program, tmpfil, &st, 0, NULL)) {
case DONE:
case NOTOK:
status++;
if (user == NULL) {
adios (NULL, "must specify -user with -saslmech xoauth2");
}
-
- vec[vecp++] = "-authservice";
- if (saslmech && ! strcasecmp(saslmech, "xoauth2")) {
- vec[vecp++] = mh_oauth_do_xoauth (user, auth_svc, snoop ? stderr : NULL);
- } else {
- vec[vecp++] = auth_svc;
- }
}
#else
NMH_UNUSED(saslmech);
closefds (3);
- if (sendsbr (vec, vecp, program, file, &st, 1) == OK)
+ if (sendsbr (vec, vecp, program, file, &st, 1, auth_svc) == OK)
done (0);
}