mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 16:18:48 -05:00
sasl: use 'unsigned short' to store mechanism
... saves a few bytes of struct size in memory and it only uses 10 bits anyway. Closes #7045
This commit is contained in:
parent
fa050ffd27
commit
a9bc819c89
@ -58,7 +58,7 @@
|
|||||||
static const struct {
|
static const struct {
|
||||||
const char *name; /* Name */
|
const char *name; /* Name */
|
||||||
size_t len; /* Name length */
|
size_t len; /* Name length */
|
||||||
unsigned int bit; /* Flag bit */
|
unsigned short bit; /* Flag bit */
|
||||||
} mechtable[] = {
|
} mechtable[] = {
|
||||||
{ "LOGIN", 5, SASL_MECH_LOGIN },
|
{ "LOGIN", 5, SASL_MECH_LOGIN },
|
||||||
{ "PLAIN", 5, SASL_MECH_PLAIN },
|
{ "PLAIN", 5, SASL_MECH_PLAIN },
|
||||||
@ -128,7 +128,8 @@ void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused)
|
|||||||
*
|
*
|
||||||
* Returns the SASL mechanism token or 0 if no match.
|
* Returns the SASL mechanism token or 0 if no match.
|
||||||
*/
|
*/
|
||||||
unsigned int Curl_sasl_decode_mech(const char *ptr, size_t maxlen, size_t *len)
|
unsigned short Curl_sasl_decode_mech(const char *ptr, size_t maxlen,
|
||||||
|
size_t *len)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char c;
|
char c;
|
||||||
@ -173,7 +174,7 @@ CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
|
|||||||
if(!strncmp(value, "*", len))
|
if(!strncmp(value, "*", len))
|
||||||
sasl->prefmech = SASL_AUTH_DEFAULT;
|
sasl->prefmech = SASL_AUTH_DEFAULT;
|
||||||
else {
|
else {
|
||||||
unsigned int mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
|
unsigned short mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
|
||||||
if(mechbit && mechlen == len)
|
if(mechbit && mechlen == len)
|
||||||
sasl->prefmech |= mechbit;
|
sasl->prefmech |= mechbit;
|
||||||
else
|
else
|
||||||
|
@ -42,7 +42,7 @@ struct connectdata;
|
|||||||
|
|
||||||
/* Authentication mechanism values */
|
/* Authentication mechanism values */
|
||||||
#define SASL_AUTH_NONE 0
|
#define SASL_AUTH_NONE 0
|
||||||
#define SASL_AUTH_ANY ~0U
|
#define SASL_AUTH_ANY 0xffff
|
||||||
#define SASL_AUTH_DEFAULT (SASL_AUTH_ANY & ~SASL_MECH_EXTERNAL)
|
#define SASL_AUTH_DEFAULT (SASL_AUTH_ANY & ~SASL_MECH_EXTERNAL)
|
||||||
|
|
||||||
/* Authentication mechanism strings */
|
/* Authentication mechanism strings */
|
||||||
@ -108,9 +108,9 @@ struct SASLproto {
|
|||||||
struct SASL {
|
struct SASL {
|
||||||
const struct SASLproto *params; /* Protocol dependent parameters */
|
const struct SASLproto *params; /* Protocol dependent parameters */
|
||||||
saslstate state; /* Current machine state */
|
saslstate state; /* Current machine state */
|
||||||
unsigned int authmechs; /* Accepted authentication mechanisms */
|
unsigned short authmechs; /* Accepted authentication mechanisms */
|
||||||
unsigned int prefmech; /* Preferred authentication mechanism */
|
unsigned short prefmech; /* Preferred authentication mechanism */
|
||||||
unsigned int authused; /* Auth mechanism used for the connection */
|
unsigned short authused; /* Auth mechanism used for the connection */
|
||||||
bool resetprefs; /* For URL auth option parsing. */
|
bool resetprefs; /* For URL auth option parsing. */
|
||||||
bool mutual_auth; /* Mutual authentication enabled (GSSAPI only) */
|
bool mutual_auth; /* Mutual authentication enabled (GSSAPI only) */
|
||||||
bool force_ir; /* Protocol always supports initial response */
|
bool force_ir; /* Protocol always supports initial response */
|
||||||
@ -126,8 +126,8 @@ struct SASL {
|
|||||||
void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused);
|
void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused);
|
||||||
|
|
||||||
/* Convert a mechanism name to a token */
|
/* Convert a mechanism name to a token */
|
||||||
unsigned int Curl_sasl_decode_mech(const char *ptr,
|
unsigned short Curl_sasl_decode_mech(const char *ptr,
|
||||||
size_t maxlen, size_t *len);
|
size_t maxlen, size_t *len);
|
||||||
|
|
||||||
/* Parse the URL login options */
|
/* Parse the URL login options */
|
||||||
CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
|
CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
|
||||||
|
@ -919,7 +919,7 @@ static CURLcode imap_state_capability_resp(struct Curl_easy *data,
|
|||||||
/* Do we have a SASL based authentication mechanism? */
|
/* Do we have a SASL based authentication mechanism? */
|
||||||
else if(wordlen > 5 && !memcmp(line, "AUTH=", 5)) {
|
else if(wordlen > 5 && !memcmp(line, "AUTH=", 5)) {
|
||||||
size_t llen;
|
size_t llen;
|
||||||
unsigned int mechbit;
|
unsigned short mechbit;
|
||||||
|
|
||||||
line += 5;
|
line += 5;
|
||||||
wordlen -= 5;
|
wordlen -= 5;
|
||||||
|
@ -709,7 +709,7 @@ static CURLcode pop3_state_capa_resp(struct Curl_easy *data, int pop3code,
|
|||||||
for(;;) {
|
for(;;) {
|
||||||
size_t llen;
|
size_t llen;
|
||||||
size_t wordlen;
|
size_t wordlen;
|
||||||
unsigned int mechbit;
|
unsigned short mechbit;
|
||||||
|
|
||||||
while(len &&
|
while(len &&
|
||||||
(*line == ' ' || *line == '\t' ||
|
(*line == ' ' || *line == '\t' ||
|
||||||
|
@ -894,7 +894,7 @@ static CURLcode smtp_state_ehlo_resp(struct Curl_easy *data,
|
|||||||
for(;;) {
|
for(;;) {
|
||||||
size_t llen;
|
size_t llen;
|
||||||
size_t wordlen;
|
size_t wordlen;
|
||||||
unsigned int mechbit;
|
unsigned short mechbit;
|
||||||
|
|
||||||
while(len &&
|
while(len &&
|
||||||
(*line == ' ' || *line == '\t' ||
|
(*line == ' ' || *line == '\t' ||
|
||||||
|
Loading…
Reference in New Issue
Block a user