fix: fixed capitalisation bugs in command parsing
This commit is contained in:
parent
81a1c7447c
commit
9418c7b9a4
7 changed files with 107 additions and 5 deletions
4
Makefile
4
Makefile
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
SRC = sis.c imap.c utils.c
|
SRC = sis.c imap.c auth.c utils.c
|
||||||
HDR = config.def.h imap.h utils.h imap.routines
|
HDR = config.def.h imap.h auth.h utils.h imap.routines
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
|
|
||||||
all: options sis
|
all: options sis
|
||||||
|
|
|
||||||
37
auth.c
Normal file
37
auth.c
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2024, Lorenzo Torres
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the <organization> nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef AUTH_PAM
|
||||||
|
|
||||||
|
int pam_conv_func(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) {
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t auth_pam(char *username, char *password)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
43
auth.h
Normal file
43
auth.h
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2024, Lorenzo Torres
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the <organization> nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef AUTH_H
|
||||||
|
#define AUTH_H
|
||||||
|
|
||||||
|
#define AUTH_OK 0x1
|
||||||
|
#define AUTH_FAIL 0x1 << 1
|
||||||
|
|
||||||
|
#ifdef AUTH_PAM
|
||||||
|
#include <security/pam_appl.h>
|
||||||
|
#include <security/pam_modules.h>
|
||||||
|
#include <security/pam_ext.h>
|
||||||
|
|
||||||
|
uint8_t auth_pam(char *username, char *password);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -21,6 +21,11 @@
|
||||||
* modify this.
|
* modify this.
|
||||||
*/
|
*/
|
||||||
#define CMD_MAX_SIZE 8000
|
#define CMD_MAX_SIZE 8000
|
||||||
|
/*-
|
||||||
|
* Use pam (Pluggable Authentication Modules)
|
||||||
|
* as an authentication method
|
||||||
|
*/
|
||||||
|
#define AUTH_PAM
|
||||||
|
|
||||||
static char *imap_capabilities[] = {
|
static char *imap_capabilities[] = {
|
||||||
"IMAP4rev1",
|
"IMAP4rev1",
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ INCS = -I.
|
||||||
LIBS = -lssl -lcrypto
|
LIBS = -lssl -lcrypto
|
||||||
# flags
|
# flags
|
||||||
CPPFLAGS = -DVERSION=\"${VERSION}\"
|
CPPFLAGS = -DVERSION=\"${VERSION}\"
|
||||||
CFLAGS := -std=c99 -pedantic -Wall -O0 -Wno-gnu-label-as-value -Wno-gnu-zero-variadic-macro-arguments ${INCS} ${CPPFLAGS}
|
CFLAGS := -std=gnu99 -pedantic -Wall -O0 -Wno-gnu-label-as-value -Wno-gnu-zero-variadic-macro-arguments ${INCS} ${CPPFLAGS}
|
||||||
CFLAGS := ${CFLAGS} -g
|
CFLAGS := ${CFLAGS} -g
|
||||||
LDFLAGS = ${LIBS}
|
LDFLAGS = ${LIBS}
|
||||||
|
|
||||||
|
|
|
||||||
7
imap.c
7
imap.c
|
|
@ -35,6 +35,7 @@
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include <imap.h>
|
#include <imap.h>
|
||||||
|
|
||||||
|
|
@ -370,10 +371,11 @@ uint8_t imap_match_cmd(char *cmd, size_t len)
|
||||||
|
|
||||||
imap_cmd imap_parse_cmd(char *s)
|
imap_cmd imap_parse_cmd(char *s)
|
||||||
{
|
{
|
||||||
|
char *cpy;
|
||||||
imap_cmd cmd;
|
imap_cmd cmd;
|
||||||
strstrip(s);
|
strstrip(s);
|
||||||
size_t params = 0, id_len = 0, i = 0;
|
size_t params = 0, id_len = 0, i = 0;
|
||||||
char *cpy;
|
|
||||||
printf("%s\n", s);
|
printf("%s\n", s);
|
||||||
|
|
||||||
cmd.params = NULL;
|
cmd.params = NULL;
|
||||||
|
|
@ -393,6 +395,9 @@ imap_cmd imap_parse_cmd(char *s)
|
||||||
|
|
||||||
id_len -= 1;
|
id_len -= 1;
|
||||||
s -= id_len+1;
|
s -= id_len+1;
|
||||||
|
|
||||||
|
cpy = s;
|
||||||
|
for (; (cpy-s) <= id_len; ++cpy) *cpy = tolower(*cpy);
|
||||||
cmd.id = imap_match_cmd(s, id_len);
|
cmd.id = imap_match_cmd(s, id_len);
|
||||||
s += id_len+2;
|
s += id_len+2;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ name: { \
|
||||||
#define IMAP_ROUTINE_END imap_flush(node, ssl);
|
#define IMAP_ROUTINE_END imap_flush(node, ssl);
|
||||||
#define IMAP_ROUTINE_OK(routine) \
|
#define IMAP_ROUTINE_OK(routine) \
|
||||||
imap_write(node, ssl, "%s OK " #routine " completed\n", cmd.tag);
|
imap_write(node, ssl, "%s OK " #routine " completed\n", cmd.tag);
|
||||||
|
#define IMAP_ROUTINE_NO(routine) \
|
||||||
|
imap_write(node, ssl, "%s NO " #routine " completed\n", cmd.tag);
|
||||||
#define IMAP_STRING(fmt, ...) \
|
#define IMAP_STRING(fmt, ...) \
|
||||||
imap_write(node, ssl, fmt, ##__VA_ARGS__);
|
imap_write(node, ssl, fmt, ##__VA_ARGS__);
|
||||||
#define IMAP_NLINE imap_write(node, ssl, "\n");
|
#define IMAP_NLINE imap_write(node, ssl, "\n");
|
||||||
|
|
@ -77,7 +79,7 @@ static inline uint8_t imap_routine_auth(imap_cmd cmd, client_list *node, uint8_t
|
||||||
|
|
||||||
int bytes;
|
int bytes;
|
||||||
|
|
||||||
if (strcmp(cmd.params[0], "PLAIN") == 0) {
|
if (strcmp(cmd.params[0], "plain") == 0) {
|
||||||
IMAP_STRING("+\n");
|
IMAP_STRING("+\n");
|
||||||
if ((bytes = imap_read(node, buf, CMD_MAX_SIZE, ssl)) < 0) {
|
if ((bytes = imap_read(node, buf, CMD_MAX_SIZE, ssl)) < 0) {
|
||||||
perror("recv");
|
perror("recv");
|
||||||
|
|
@ -98,5 +100,15 @@ static inline uint8_t imap_routine_auth(imap_cmd cmd, client_list *node, uint8_t
|
||||||
|
|
||||||
static inline uint8_t imap_routine_login(imap_cmd cmd, client_list *node, uint8_t ssl, uint8_t state)
|
static inline uint8_t imap_routine_login(imap_cmd cmd, client_list *node, uint8_t ssl, uint8_t state)
|
||||||
{
|
{
|
||||||
|
IMAP_CHECK_STATE(NO_AUTH)
|
||||||
|
IMAP_CHECK_ARGS(2)
|
||||||
|
|
||||||
|
if ((strcmp(cmd.params[0], "lorenzo") == 0) && (strcmp(cmd.params[1], "lorenzo06") == 0)) {
|
||||||
|
IMAP_ROUTINE_OK(LOGIN)
|
||||||
|
} else {
|
||||||
|
IMAP_ROUTINE_NO(LOGIN)
|
||||||
|
}
|
||||||
|
|
||||||
|
IMAP_ROUTINE_END
|
||||||
return IMAP_SUCCESS;
|
return IMAP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue