Added handling of messages

Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
Tyrolyean 2020-04-25 01:37:15 +02:00
parent 72ed7e3741
commit d1c580e287
No known key found for this signature in database
GPG key ID: 81EC9BAC5E9667C6
6 changed files with 97 additions and 5 deletions

26
include/attach.h Normal file
View file

@ -0,0 +1,26 @@
/*
* attach.h - Core mechanix behind attachment replacing
* The author licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef ATTACH_H
#define ATTACH_H
#include <stdint.h>
char* attach_files(const unsigned char* original_message,
size_t original_length);
#endif /* ATTACH_H */

View file

@ -1,5 +1,5 @@
/*
* detect.h - Licensed
* detect.h - Content detection
* The author licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
@ -20,6 +20,6 @@
#include <stdbool.h>
bool detect_pgp(const FILE* message);
bool detect_pgp(const char* message);
#endif /* DETECT_H */

32
src/attach.c Normal file
View file

@ -0,0 +1,32 @@
/*
* attach.c - Core mechanix behind attachment replacing
* I know how mechanics is spelt, let me have my fun :D
* The author licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include <string.h>
#include <stdlib.h>
char* attach_files(const unsigned char* original_message,
size_t original_length){
const char* new_body = malloc(original_length + 1);
if(new_body == NULL){
return NULL;
}
memset(new_body,0, original_length + 1);
}

View file

@ -1,5 +1,5 @@
/*
* config.h - Configuration loading and data storage
* config.c - Configuration loading and data storage
* The author licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance

24
src/detect.c Normal file
View file

@ -0,0 +1,24 @@
/*
* detect.c - Detect content
* The author licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "detect.h"
bool detect_pgp(const char* message){
return false;
}

View file

@ -19,7 +19,7 @@
#include "version.h"
#include "config.h"
#include "detect.h"
#include "attach.h"
struct mlfiPriv
{
@ -126,7 +126,17 @@ sfsistat mlfi_body(SMFICTX* ctx, unsigned char * bodyp, size_t bodylen) {
(void) mlfi_cleanup(ctx, false);
return SMFIS_TEMPFAIL;
}
char* new_body = attach_files(bodyp, bodylen);
if(new_body != NULL){
size_t new_bodylen = strlen(new_body)+1;
unsigned char * replacement = malloc(new_bodylen+1);
memset(replacement, 0, new_bodylen+1);
memcpy(replacement, replacement, new_bodylen+1);
free(new_body);
printf("Replacing body of mail message\n");
smfi_replacebody(ctx, replacement, new_bodylen);
}
/* continue processing */
return SMFIS_CONTINUE;
}