commit 5b2d51ff64270788966fc59436ab71f498c42a44
parent 4038e852c1e13726ddb3e3e7394e237188b0bfe6
Author: Santtu Lakkala <santtu.lakkala@digital14.com>
Date: Wed, 13 Sep 2023 13:28:16 +0300
Fix indents
Diffstat:
M | main.c | | | 213 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
1 file changed, 106 insertions(+), 107 deletions(-)
diff --git a/main.c b/main.c
@@ -30,8 +30,8 @@
char *argv0;
static void (*digest_hmacs[])(const void *key, size_t keylen,
- const void *data, size_t datalen,
- void *h) = {
+ const void *data, size_t datalen,
+ void *h) = {
sha1_hmac,
sha224_hmac,
sha256_hmac,
@@ -114,9 +114,9 @@ void print_keyuri(struct token *token,
print_uriencode(stream, token->issuer, true);
}
fprintf(stream, "&algorithm=%s&digits=%" PRIu8 "&period=%" PRIu8 "\n",
- digest_names[token->digest],
- token->digits,
- token->period);
+ digest_names[token->digest],
+ token->digits,
+ token->period);
}
struct generate_data {
@@ -227,40 +227,41 @@ int main(int argc, char *argv[])
uint8_t keybuf[AES_KEYLEN + AES_BLOCKLEN];
size_t keylen = 0;
struct generate_data gd = { NULL, false };
+ struct token token;
char *t;
ARGBEGIN {
- case 'l':
- cmd = CMD_LIST;
- break;
- case 'a':
- cmd = CMD_ADD;
- totpuri = EARGF(usage());
- break;
- case 'd':
- cmd = CMD_DEL;
- keyquery = EARGF(usage());
- break;
- case 't':
- cmd = CMD_TOK;
- keyquery = EARGF(usage());
- break;
- case 'e':
- cmd = CMD_EXP;
- break;
- case 'k':
- key = EARGF(usage());
- break;
- case 'K':
- keyfile = EARGF(usage());
- break;
- case 'f':
- secretfile = EARGF(usage());
- free_secretfile = false;
- break;
- default:
- usage();
- break;
+ case 'l':
+ cmd = CMD_LIST;
+ break;
+ case 'a':
+ cmd = CMD_ADD;
+ totpuri = EARGF(usage());
+ break;
+ case 'd':
+ cmd = CMD_DEL;
+ keyquery = EARGF(usage());
+ break;
+ case 't':
+ cmd = CMD_TOK;
+ keyquery = EARGF(usage());
+ break;
+ case 'e':
+ cmd = CMD_EXP;
+ break;
+ case 'k':
+ key = EARGF(usage());
+ break;
+ case 'K':
+ keyfile = EARGF(usage());
+ break;
+ case 'f':
+ secretfile = EARGF(usage());
+ free_secretfile = false;
+ break;
+ default:
+ usage();
+ break;
} ARGEND
@@ -351,81 +352,79 @@ int main(int argc, char *argv[])
}
switch (cmd) {
- case CMD_LIST:
- fd = db_open_read(secretfile, &c);
- if (fd < 0)
- break;
- db_foreach(fd, &c, print_key, stdout);
- close(fd);
+ case CMD_LIST:
+ fd = db_open_read(secretfile, &c);
+ if (fd < 0)
break;
-
- case CMD_ADD: {
- struct token token = token_parse_uri(totpuri);
- if (!token.valid)
- croak("Invalid uri");
-
- fd = db_open_read(secretfile, &c);
- if (fd < 0 && errno != ENOENT)
- croak("Opening existing db failed: %s", strerror(errno));
-
- wfd = db_open_write(newsecretfile, &wc);
- if (wfd < 0)
- croak("Could not open temporary secret file: %s", strerror(errno));
- if (fd >= 0) {
- db_foreach(fd, &c, write_filter_key,
- &(struct write_filter_data){ .fd = wfd, .c = &wc });
- close(fd);
- }
- db_add_key(wfd, &wc, &token);
- close(wfd);
-
- rename(newsecretfile, secretfile);
-
- break;
- }
-
- case CMD_NONE:
- keyquery = argv[0];
- /* fall-through */
- case CMD_TOK:
- fd = db_open_read(secretfile, &c);
- if (fd < 0)
- croak("Could not open secret file: %s", strerror(errno));
- gd.filter = keyquery;
- db_foreach(fd, &c, generate_token, &gd);
- close(fd);
- if (!gd.found)
- croak("No secrets matching filter found");
- break;
-
- case CMD_DEL: {
- fd = db_open_read(secretfile, &c);
- if (fd < 0) {
- if (errno == ENOENT)
- break;
- croak("Could not open secret file: %s", strerror(errno));
- }
- wfd = db_open_write(newsecretfile, &wc);
- if (wfd < 0)
- croak("Could not open temporary secret file: %s", strerror(errno));
+ db_foreach(fd, &c, print_key, stdout);
+ close(fd);
+ break;
+
+ case CMD_ADD:
+ token = token_parse_uri(totpuri);
+ if (!token.valid)
+ croak("Invalid uri");
+
+ fd = db_open_read(secretfile, &c);
+ if (fd < 0 && errno != ENOENT)
+ croak("Opening existing db failed: %s", strerror(errno));
+
+ wfd = db_open_write(newsecretfile, &wc);
+ if (wfd < 0)
+ croak("Could not open temporary secret file: %s", strerror(errno));
+ if (fd >= 0) {
db_foreach(fd, &c, write_filter_key,
- &(struct write_filter_data){
- .fd = wfd, .filter = keyquery,
- .c = &wc
- });
- close(wfd);
- close(fd);
- rename(newsecretfile, secretfile);
- break;
-
- case CMD_EXP:
- fd = db_open_read(secretfile, &c);
- if (fd < 0)
- croak("Could not open secret file: %s", strerror(errno));
- db_foreach(fd, &c, print_keyuri, stdout);
+ &(struct write_filter_data){ .fd = wfd, .c = &wc });
close(fd);
- break;
}
+ db_add_key(wfd, &wc, &token);
+ close(wfd);
+
+ rename(newsecretfile, secretfile);
+
+ break;
+
+ case CMD_NONE:
+ keyquery = argv[0];
+ /* fall-through */
+ case CMD_TOK:
+ fd = db_open_read(secretfile, &c);
+ if (fd < 0)
+ croak("Could not open secret file: %s", strerror(errno));
+ gd.filter = keyquery;
+ db_foreach(fd, &c, generate_token, &gd);
+ close(fd);
+ if (!gd.found)
+ croak("No secrets matching filter found");
+ break;
+
+ case CMD_DEL:
+ fd = db_open_read(secretfile, &c);
+ if (fd < 0) {
+ if (errno == ENOENT)
+ break;
+ croak("Could not open secret file: %s", strerror(errno));
+ }
+ wfd = db_open_write(newsecretfile, &wc);
+ if (wfd < 0)
+ croak("Could not open temporary secret file: %s", strerror(errno));
+ db_foreach(fd, &c, write_filter_key,
+ &(struct write_filter_data){
+ .fd = wfd, .filter = keyquery,
+ .c = &wc
+ });
+ close(wfd);
+ close(fd);
+ rename(newsecretfile, secretfile);
+ break;
+
+ case CMD_EXP:
+ fd = db_open_read(secretfile, &c);
+ if (fd < 0)
+ croak("Could not open secret file: %s", strerror(errno));
+ db_foreach(fd, &c, print_keyuri, stdout);
+ close(fd);
+ break;
}
if (free_secretfile)