NeoMutt  2025-12-11-435-g4ac674
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
  • Alejandro Colomar

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 302 of file auth.c.

303{
304 char *p1 = NULL, *p2 = NULL;
305
306 FREE(&adata->timestamp);
307
308 if ((p1 = strchr(buf, '<')) && (p2 = strchr(p1, '>')))
309 {
310 p2[1] = '\0';
311 adata->timestamp = mutt_str_dup(p1);
312 }
313}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
char * timestamp
APOP timestamp.
Definition adata.h:55
+ 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 503 of file auth.c.

504{
505 for (size_t i = 0; i < countof(PopAuthenticators); i++)
506 {
507 const struct PopAuth *auth = &PopAuthenticators[i];
508 if (auth->method && mutt_istr_equal(auth->method, authenticator))
509 return true;
510 }
511
512 return false;
513}
#define countof(x)
Definition memory.h:49
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition string.c:674
static const struct PopAuth PopAuthenticators[]
Accepted authentication methods.
Definition auth.c:480
POP authentication multiplexor.
Definition private.h:76
const char * method
Name of authentication method supported, NULL means variable.
Definition private.h:87
+ 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 524 of file auth.c.

525{
526 struct ConnAccount *cac = &adata->conn->account;
527 const struct PopAuth *authenticator = NULL;
528 int attempts = 0;
529 int rc = POP_A_UNAVAIL;
530
531 if ((mutt_account_getuser(cac) < 0) || (cac->user[0] == '\0'))
532 {
533 return -3;
534 }
535
536 const struct Slist *c_pop_authenticators = cs_subset_slist(NeoMutt->sub, "pop_authenticators");
537 const bool c_pop_auth_try_all = cs_subset_bool(NeoMutt->sub, "pop_auth_try_all");
538 if (c_pop_authenticators && (c_pop_authenticators->count > 0))
539 {
540 /* Try user-specified list of authentication methods */
541 struct ListNode *np = NULL;
542 STAILQ_FOREACH(np, &c_pop_authenticators->head, entries)
543 {
544 mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
545 authenticator = PopAuthenticators;
546
547 while (authenticator->authenticate)
548 {
549 if (!authenticator->method || mutt_istr_equal(authenticator->method, np->data))
550 {
551 rc = authenticator->authenticate(adata, np->data);
552 if (rc == POP_A_SOCKET)
553 {
554 switch (pop_connect(adata))
555 {
556 case 0:
557 {
558 rc = authenticator->authenticate(adata, np->data);
559 break;
560 }
561 case -2:
562 rc = POP_A_FAILURE;
563 }
564 }
565
566 if (rc != POP_A_UNAVAIL)
567 attempts++;
568 if ((rc == POP_A_SUCCESS) || (rc == POP_A_SOCKET) ||
569 ((rc == POP_A_FAILURE) && !c_pop_auth_try_all))
570 {
571 break;
572 }
573 }
574 authenticator++;
575 }
576 }
577 }
578 else
579 {
580 /* Fall back to default: any authenticator */
581 mutt_debug(LL_DEBUG2, "Using any available method\n");
582 authenticator = PopAuthenticators;
583
584 while (authenticator->authenticate)
585 {
586 rc = authenticator->authenticate(adata, NULL);
587 if (rc == POP_A_SOCKET)
588 {
589 switch (pop_connect(adata))
590 {
591 case 0:
592 {
593 rc = authenticator->authenticate(adata, NULL);
594 break;
595 }
596 case -2:
597 rc = POP_A_FAILURE;
598 }
599 }
600
601 if (rc != POP_A_UNAVAIL)
602 attempts++;
603 if ((rc == POP_A_SUCCESS) || (rc == POP_A_SOCKET) ||
604 ((rc == POP_A_FAILURE) && !c_pop_auth_try_all))
605 {
606 break;
607 }
608
609 authenticator++;
610 }
611 }
612
613 switch (rc)
614 {
615 case POP_A_SUCCESS:
616 return 0;
617 case POP_A_SOCKET:
618 return -1;
619 case POP_A_UNAVAIL:
620 if (attempts == 0)
621 mutt_error(_("No authenticators available"));
622 }
623
624 return -2;
625}
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:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
#define _(a)
Definition message.h:28
int pop_connect(struct PopAccountData *adata)
Open connection.
Definition lib.c:281
@ POP_A_UNAVAIL
No valid authentication method.
Definition private.h:60
@ POP_A_SUCCESS
Authenticated successfully.
Definition private.h:57
@ POP_A_FAILURE
Authentication failed.
Definition private.h:59
@ POP_A_SOCKET
Connection lost.
Definition private.h:58
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
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:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
struct Connection * conn
Connection to POP server.
Definition adata.h:38
enum PopAuthRes(* authenticate)(struct PopAccountData *adata, const char *method)
Definition private.h:85
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:367
static enum PopAuthRes pop_auth_apop(struct PopAccountData *adata, const char *method)
APOP authenticator - Implements PopAuth::authenticate() -.
Definition auth.c:318
static enum PopAuthRes pop_auth_oauth(struct PopAccountData *adata, const char *method)
Authenticate a POP connection using OAUTHBEARER - Implements PopAuth::authenticate() -.
Definition auth.c:425

Accepted authentication methods.

Definition at line 480 of file auth.c.

480 {
481 // clang-format off
482 { pop_auth_oauth, "oauthbearer" },
483#ifdef USE_SASL_CYRUS
484 { pop_auth_sasl, NULL },
485#endif
486#ifdef USE_SASL_GNU
487 { pop_auth_gsasl, NULL },
488#endif
489 { pop_auth_apop, "apop" },
490 { pop_auth_user, "user" },
491 { NULL, NULL },
492 // clang-format on
493};