NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
auth.c File Reference

POP authentication. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "private.h"
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "conn/lib.h"
#include "adata.h"
+ Include dependency graph for auth.c:

Go to the source code of this file.

Functions

void pop_apop_timestamp (struct PopAccountData *adata, char *buf)
 Get the server timestamp for APOP authentication.
 
static enum PopAuthRes pop_auth_apop (struct PopAccountData *adata, const char *method)
 APOP authenticator - Implements PopAuth::authenticate() -.
 
static enum PopAuthRes pop_auth_user (struct PopAccountData *adata, const char *method)
 USER authenticator - Implements PopAuth::authenticate() -.
 
static enum PopAuthRes pop_auth_oauth (struct PopAccountData *adata, const char *method)
 Authenticate a POP connection using OAUTHBEARER - Implements PopAuth::authenticate() -.
 
bool pop_auth_is_valid (const char *authenticator)
 Check if string is a valid pop authentication method.
 
int pop_authenticate (struct PopAccountData *adata)
 Authenticate with a POP server.
 

Variables

static const struct PopAuth PopAuthenticators []
 Accepted authentication methods.
 

Detailed Description

POP authentication.

Authors
  • Vsevolod Volkov
  • Richard Russon
  • Pietro Cerutti
  • Yousef Akbar

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file auth.c.

Function Documentation

◆ pop_apop_timestamp()

void pop_apop_timestamp ( struct PopAccountData adata,
char *  buf 
)

Get the server timestamp for APOP authentication.

Parameters
adataPOP Account data
bufTimestamp string

Definition at line 301 of file auth.c.

302{
303 char *p1 = NULL, *p2 = NULL;
304
305 FREE(&adata->timestamp);
306
307 if ((p1 = strchr(buf, '<')) && (p2 = strchr(p1, '>')))
308 {
309 p2[1] = '\0';
310 adata->timestamp = mutt_str_dup(p1);
311 }
312}
#define FREE(x)
Definition: memory.h:55
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
char * timestamp
Definition: adata.h:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_auth_is_valid()

bool pop_auth_is_valid ( const char *  authenticator)

Check if string is a valid pop authentication method.

Parameters
authenticatorAuthenticator string to check
Return values
trueArgument is a valid auth method

Validate whether an input string is an accepted pop authentication method as defined by PopAuthenticators.

Definition at line 502 of file auth.c.

503{
504 for (size_t i = 0; i < mutt_array_size(PopAuthenticators); i++)
505 {
506 const struct PopAuth *auth = &PopAuthenticators[i];
507 if (auth->method && mutt_istr_equal(auth->method, authenticator))
508 return true;
509 }
510
511 return false;
512}
#define mutt_array_size(x)
Definition: memory.h:38
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
static const struct PopAuth PopAuthenticators[]
Accepted authentication methods.
Definition: auth.c:479
POP authentication multiplexor.
Definition: private.h:78
const char * method
Name of authentication method supported, NULL means variable.
Definition: private.h:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_authenticate()

int pop_authenticate ( struct PopAccountData adata)

Authenticate with a POP server.

Parameters
adataPOP Account data
Return values
numResult, e.g. POP_A_SUCCESS
0Successful
-1Connection lost
-2Login failed
-3Authentication cancelled

Definition at line 523 of file auth.c.

524{
525 struct ConnAccount *cac = &adata->conn->account;
526 const struct PopAuth *authenticator = NULL;
527 int attempts = 0;
528 int rc = POP_A_UNAVAIL;
529
530 if ((mutt_account_getuser(cac) < 0) || (cac->user[0] == '\0'))
531 {
532 return -3;
533 }
534
535 const struct Slist *c_pop_authenticators = cs_subset_slist(NeoMutt->sub, "pop_authenticators");
536 const bool c_pop_auth_try_all = cs_subset_bool(NeoMutt->sub, "pop_auth_try_all");
537 if (c_pop_authenticators && (c_pop_authenticators->count > 0))
538 {
539 /* Try user-specified list of authentication methods */
540 struct ListNode *np = NULL;
541 STAILQ_FOREACH(np, &c_pop_authenticators->head, entries)
542 {
543 mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
544 authenticator = PopAuthenticators;
545
546 while (authenticator->authenticate)
547 {
548 if (!authenticator->method || mutt_istr_equal(authenticator->method, np->data))
549 {
550 rc = authenticator->authenticate(adata, np->data);
551 if (rc == POP_A_SOCKET)
552 {
553 switch (pop_connect(adata))
554 {
555 case 0:
556 {
557 rc = authenticator->authenticate(adata, np->data);
558 break;
559 }
560 case -2:
561 rc = POP_A_FAILURE;
562 }
563 }
564
565 if (rc != POP_A_UNAVAIL)
566 attempts++;
567 if ((rc == POP_A_SUCCESS) || (rc == POP_A_SOCKET) ||
568 ((rc == POP_A_FAILURE) && !c_pop_auth_try_all))
569 {
570 break;
571 }
572 }
573 authenticator++;
574 }
575 }
576 }
577 else
578 {
579 /* Fall back to default: any authenticator */
580 mutt_debug(LL_DEBUG2, "Using any available method\n");
581 authenticator = PopAuthenticators;
582
583 while (authenticator->authenticate)
584 {
585 rc = authenticator->authenticate(adata, NULL);
586 if (rc == POP_A_SOCKET)
587 {
588 switch (pop_connect(adata))
589 {
590 case 0:
591 {
592 rc = authenticator->authenticate(adata, NULL);
593 break;
594 }
595 case -2:
596 rc = POP_A_FAILURE;
597 }
598 }
599
600 if (rc != POP_A_UNAVAIL)
601 attempts++;
602 if ((rc == POP_A_SUCCESS) || (rc == POP_A_SOCKET) ||
603 ((rc == POP_A_FAILURE) && !c_pop_auth_try_all))
604 {
605 break;
606 }
607
608 authenticator++;
609 }
610 }
611
612 switch (rc)
613 {
614 case POP_A_SUCCESS:
615 return 0;
616 case POP_A_SOCKET:
617 return -1;
618 case POP_A_UNAVAIL:
619 if (attempts == 0)
620 mutt_error(_("No authenticators available"));
621 }
622
623 return -2;
624}
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:242
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition: connaccount.c:51
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
#define _(a)
Definition: message.h:28
int pop_connect(struct PopAccountData *adata)
Open connection.
Definition: lib.c:282
@ POP_A_UNAVAIL
No valid authentication method.
Definition: private.h:62
@ POP_A_SUCCESS
Authenticated successfully.
Definition: private.h:59
@ POP_A_FAILURE
Authentication failed.
Definition: private.h:61
@ POP_A_SOCKET
Connection lost.
Definition: private.h:60
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
Login details for a remote server.
Definition: connaccount.h:53
char user[128]
Username.
Definition: connaccount.h:56
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:49
A List node for strings.
Definition: list.h:37
char * data
String.
Definition: list.h:38
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
struct Connection * conn
Connection to POP server.
Definition: adata.h:38
enum PopAuthRes(* authenticate)(struct PopAccountData *adata, const char *method)
Definition: private.h:87
String list.
Definition: slist.h:37
struct ListHead head
List containing values.
Definition: slist.h:38
size_t count
Number of values in list.
Definition: slist.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ PopAuthenticators

const struct PopAuth PopAuthenticators[]
static
Initial value:
= {
{ pop_auth_oauth, "oauthbearer" },
{ pop_auth_apop, "apop" },
{ pop_auth_user, "user" },
{ NULL, NULL },
}
static enum PopAuthRes pop_auth_user(struct PopAccountData *adata, const char *method)
USER authenticator - Implements PopAuth::authenticate() -.
Definition: auth.c:366
static enum PopAuthRes pop_auth_apop(struct PopAccountData *adata, const char *method)
APOP authenticator - Implements PopAuth::authenticate() -.
Definition: auth.c:317
static enum PopAuthRes pop_auth_oauth(struct PopAccountData *adata, const char *method)
Authenticate a POP connection using OAUTHBEARER - Implements PopAuth::authenticate() -.
Definition: auth.c:424

Accepted authentication methods.

Definition at line 479 of file auth.c.