mirror of
https://gitlab.kit.edu/kit/scc/sys/mail/exim-encrypt-dlfunc.git
synced 2025-12-06 10:13:56 +01:00
Add option to suppress a newline at the end of the output.
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <sodium.h>
|
||||
#include <stdbool.h>
|
||||
#include "common.c"
|
||||
|
||||
#define ENVVAR_PASSWORD_NAME "LIBEXIM_PASSWORD"
|
||||
@ -13,12 +14,16 @@ void print_usage(char * progname) {
|
||||
printf("Password:\n");
|
||||
printf(" -p, --password PASSWORD decrypt using PASSWORD\n");
|
||||
printf("\n");
|
||||
printf(" If the environment variable LIBEXIM_PASSWORD is set the password is read from it.\n");
|
||||
printf(" If the environment variable LIBEXIM_PASSWORD is set the password is read from there.\n");
|
||||
printf(" Setting a password with -p/--password overwrites this mechanism.\n");
|
||||
printf("\n");
|
||||
printf("Select input:\n");
|
||||
printf(" -c, --input STRING decrypt contents of STRING\n");
|
||||
printf(" -f, --infile FILE decrypt contents of the first line of file FILE\n");
|
||||
printf("\n");
|
||||
printf("Output:\n");
|
||||
printf(" -n, --no-newline Do not add a newline to the output\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
@ -36,6 +41,7 @@ int main(int argc, char *argv[]) {
|
||||
size_t password_len;
|
||||
char *password;
|
||||
char *password_env;
|
||||
bool add_newline = true;
|
||||
|
||||
seen_args mode = NONE;
|
||||
seen_args input = NONE;
|
||||
@ -46,11 +52,12 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// define arguments
|
||||
const char *shortargs = "p:ef:";
|
||||
const char *shortargs = "p:ef:n";
|
||||
static struct option long_options[] = {
|
||||
{"password", required_argument, NULL, 'p'},
|
||||
{"pass-from-env", no_argument, NULL, 'e'},
|
||||
{"infile", required_argument, NULL, 'f'},
|
||||
{"no-newline", no_argument, NULL, 'n'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
@ -78,6 +85,9 @@ int main(int argc, char *argv[]) {
|
||||
cipherstring = read_first_line(optarg);
|
||||
input |= INFILE;
|
||||
break;
|
||||
case 'n':
|
||||
add_newline = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,5 +146,9 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// print cleartext to stdout
|
||||
fprintf(stdout, "%s", (const char *) cleartext);
|
||||
if (add_newline == true) {
|
||||
fprintf(stdout, "%s\n", (const char *) cleartext);
|
||||
} else {
|
||||
fprintf(stdout, "%s", (const char *) cleartext);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user