author | Olivier Brunel
<jjk@jjacky.com> 2023-04-18 13:17:00 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-04-19 07:37:35 UTC |
parent | 042bbccff45ee03750136edbfc0dc2e69ce19921 |
src/include/ssp.h | +5 | -5 |
src/ssp/add.c | +13 | -13 |
src/ssp/database.c | +1 | -1 |
src/ssp/list.c | +8 | -8 |
src/ssp/remove.c | +9 | -9 |
src/ssp/rename.c | +12 | -12 |
src/ssp/show.c | +17 | -17 |
src/ssp/ssp.c | +1 | -1 |
diff --git a/src/include/ssp.h b/src/include/ssp.h index b2aa32f..b755d5f 100644 --- a/src/include/ssp.h +++ b/src/include/ssp.h @@ -64,7 +64,7 @@ struct otp /* ssp.c */ int exitcode_from_errno(int e); ssize_t unesc(char *dst, size_t dlen, const char *sce, size_t slen); -const char *get_site_name(const char *s, struct ssp *ctx); +const char *get_entry_name(const char *s, struct ssp *ctx); /* database.c */ void rebuild_db(const char *oldkey, const char *newkey, const struct otp *otp, struct ssp *ctx); @@ -73,13 +73,13 @@ int open_db(struct ssp *ctx); #define db_file(ctx) (((ctx)->db) ? (ctx)->db : (ctx)->sa.s) #define db_reset(ctx) (ctx)->pos = CDB_TRAVERSE_INIT() #define db_next(ctx) cdb_traverse_next(&(ctx)->cdb, &(ctx)->key, &(ctx)->val, &(ctx)->pos) -#define db_find(site,ctx) ((ctx)->key.s = site, (ctx)->key.len = strlen(site) + 1, \ +#define db_find(entry,ctx) ((ctx)->key.s = entry, (ctx)->key.len = strlen(entry) + 1, \ cdb_find(&(ctx)->cdb, &(ctx)->val, (ctx)->key.s, (ctx)->key.len)) -#define db_site(ctx) (ctx)->key.s +#define db_entry(ctx) (ctx)->key.s #define db_otp(ctx) (const struct otp *) (ctx)->val.s /* show.c */ -void show_site(unsigned options, struct ssp *ctx); -void show_site_ini(unsigned options, struct ssp *ctx); +void show_entry(unsigned options, struct ssp *ctx); +void show_entry_ini(unsigned options, struct ssp *ctx); #endif /* SSP_SSP_H */ diff --git a/src/ssp/add.c b/src/ssp/add.c index 98f5074..927b193 100644 --- a/src/ssp/add.c +++ b/src/ssp/add.c @@ -17,13 +17,13 @@ struct add { const char *comments; }; -COMMAND(add, "Add a new site", - "<site> [OPTION..] <secret>", +COMMAND(add, "Add a new entry", + "<entry> [OPTION..] <secret>", " -a, --algo ALGO Set ALGO as hashing algorithm [sha256]\n" " Use 'list' to list available algorithms\n" -" -c, --comments COMMENTS Set COMMENTS as site's comments\n" +" -c, --comments COMMENTS Set COMMENTS as entry's comments\n" " -d, --digits NUM Set to counter-based (HOTP) using NUM digits [6]\n" -" -t, --time [SECS] Set to time-based (TOTP) with precision of SECS [30]\n" +" -t, --time[=SECS] Set to time-based (TOTP) with precision of SECS [30]\n" ); @@ -101,18 +101,18 @@ add_main(int argc, const char *argv[], const char *env[], const char usage[], vo struct ssp *ctx = ctx_; struct add add = { .otp.type = TYPE_COUNTER, .otp.algo = ALGO_SHA256, .otp.digits = 6, .comments = "" }; - const char *site; + const char *entry; int i; if (argc == 1) { - warn("argument \"site\" missing"); + warn("argument \"entry\" missing"); diecmdusage(EX_USAGE, usage, &command_add); } - site = get_site_name(argv[1], ctx); - if (!site) - diefusys(exitcode_from_errno(errno), "parse site's name"); - if (*site == '-') { - warn("argument \"site\" cannot start with a '-'"); + entry = get_entry_name(argv[1], ctx); + if (!entry) + diefusys(exitcode_from_errno(errno), "parse entry's name"); + if (*entry == '-') { + warn("argument \"entry\" cannot start with a '-'"); diecmdusage(EX_DATA_ERR, usage, &command_add); } @@ -153,8 +153,8 @@ add_main(int argc, const char *argv[], const char *env[], const char usage[], vo if (open_db(ctx) < 0) diefu(exitcode_from_errno(errno), "open database"); - out("Adding site ", ESC, site, ESC, "... "); - rebuild_db(NULL, site, p, ctx); + out("Adding entry ", ESC, entry, ESC, "... "); + rebuild_db(NULL, entry, p, ctx); return 0; } diff --git a/src/ssp/database.c b/src/ssp/database.c index b02466c..352f59e 100644 --- a/src/ssp/database.c +++ b/src/ssp/database.c @@ -124,7 +124,7 @@ rebuild_db(const char *oldkey, const char *newkey, const struct otp *otp, struct /* existing newkey isn't allowed when adding or renaming */ if (nlen == ctx->key.len && !strcmp(newkey, ctx->key.s) && (!olen || strcmp(oldkey, newkey))) { - diefu(EX_DATA_ERR, "add site ", ESC, newkey, ESC, ": Site already exists"); + diefu(EX_DATA_ERR, "add entry ", ESC, newkey, ESC, ": Already exists"); } else { if (!a && strcoll(ctx->key.s, newkey) > 0) { /* insert otp at the right place */ diff --git a/src/ssp/list.c b/src/ssp/list.c index f0eac83..e419629 100644 --- a/src/ssp/list.c +++ b/src/ssp/list.c @@ -22,12 +22,12 @@ struct list { const char *ptrn; }; -COMMAND(list, "List all sites", +COMMAND(list, "List all entries", "[OPTION..] [<pattern>]", " -C, --no-comments Do not show comments with --details/--format\n" -" -d, --details Show sites' details\n" +" -d, --details Show entries' details\n" " -f, --format Output in INI-like format\n" -" -S, --secret Show sites' secrets (implies --details)\n" +" -S, --secret Show entries' secrets (implies --details)\n" " -s, --sep SEP Use SEP as separator\n" ); @@ -95,15 +95,15 @@ list_main(int argc, const char *argv[], const char *env[], const char usage[], v i = 0; db_reset(ctx); while ((r = db_next(ctx)) == 1) { - if (list.ptrn && fnmatch(list.ptrn, db_site(ctx), 0)) + if (list.ptrn && fnmatch(list.ptrn, db_entry(ctx), 0)) continue; if (list.options & OPT_FMT_INI) { - show_site_ini(list.options & OPT_NO_COMMENTS, ctx); + show_entry_ini(list.options & OPT_NO_COMMENTS, ctx); } else if (list.options & OPT_DETAILS) { - show_site(list.options & (OPT_NO_COMMENTS | OPT_SECRET), ctx); + show_entry(list.options & (OPT_NO_COMMENTS | OPT_SECRET), ctx); } else { if (i) add(list.sep); - add(ESC, db_site(ctx), ESC); + add(ESC, db_entry(ctx), ESC); } i = 1; } @@ -113,7 +113,7 @@ list_main(int argc, const char *argv[], const char *env[], const char usage[], v /* add new line + flush buffers */ if (!(list.options & (OPT_DETAILS | OPT_FMT_INI))) out(NULL); } else { - out("no site matching ", ESC, list.ptrn, ESC); + out("no entry matching ", ESC, list.ptrn, ESC); } return 0; diff --git a/src/ssp/remove.c b/src/ssp/remove.c index c7f1def..d063e8f 100644 --- a/src/ssp/remove.c +++ b/src/ssp/remove.c @@ -8,7 +8,7 @@ #include "ssp.h" -COMMAND(remove, "Remove a site", "<site>", NULL); +COMMAND(remove, "Remove an entry", "<entry>", NULL); int remove_main(int argc, const char *argv[], const char *env[], const char usage[], void *ctx_) @@ -18,9 +18,9 @@ remove_main(int argc, const char *argv[], const char *env[], const char usage[], if (argc != 2) diecmdusage(EX_USAGE, usage, &command_remove); - const char *site = get_site_name(argv[1], ctx); - if (!site) - diefusys(exitcode_from_errno(errno), "parse site's name"); + const char *entry = get_entry_name(argv[1], ctx); + if (!entry) + diefusys(exitcode_from_errno(errno), "parse entry's name"); int r = open_db(ctx); if (r < 0) @@ -28,14 +28,14 @@ remove_main(int argc, const char *argv[], const char *env[], const char usage[], if (!r) dief(0, "no database"); - r = db_find(site, ctx); + r = db_find(entry, ctx); if (r < 0) - diefu(EX_DATA_ERR, "find site ", ESC, site, ESC); + diefu(EX_DATA_ERR, "find entry ", ESC, entry, ESC); if (!r) { - out("no site ", ESC, site, ESC, " in database"); + out("no entry ", ESC, entry, ESC, " in database"); } else { - out("Removing ", ESC, site, ESC, "..."); - rebuild_db(site, NULL, NULL, ctx); + out("Removing ", ESC, entry, ESC, "..."); + rebuild_db(entry, NULL, NULL, ctx); } return 0; diff --git a/src/ssp/rename.c b/src/ssp/rename.c index 4f02089..0bee7ce 100644 --- a/src/ssp/rename.c +++ b/src/ssp/rename.c @@ -8,7 +8,7 @@ #include "ssp.h" -COMMAND(rename, "Rename a site", "<site> <newname>", NULL); +COMMAND(rename, "Rename an entry", "<entry> <newname>", NULL); int rename_main(int argc, const char *argv[], const char *env[], const char usage[], void *ctx_) @@ -18,16 +18,16 @@ rename_main(int argc, const char *argv[], const char *env[], const char usage[], if (argc != 3) diecmdusage(EX_USAGE, usage, &command_rename); - const char *site = get_site_name(argv[1], ctx); - if (!site) - diefusys(exitcode_from_errno(errno), "parse site's name"); + const char *entry = get_entry_name(argv[1], ctx); + if (!entry) + diefusys(exitcode_from_errno(errno), "parse entry's name"); - const char *new = get_site_name(argv[2], ctx); + const char *new = get_entry_name(argv[2], ctx); if (!new) diefusys(exitcode_from_errno(errno), "parse new name"); - if (!strcmp(site, new)) - diefu(EX_DATA_ERR, "rename site ", ESC, site, ESC, ": new name is the same"); + if (!strcmp(entry, new)) + diefu(EX_DATA_ERR, "rename entry ", ESC, entry, ESC, ": new name is the same"); int r = open_db(ctx); if (r < 0) @@ -35,14 +35,14 @@ rename_main(int argc, const char *argv[], const char *env[], const char usage[], if (!r) dief(0, "no database"); - r = db_find(site, ctx); + r = db_find(entry, ctx); if (r < 0) - diefu(EX_DATA_ERR, "find site ", ESC, site, ESC); + diefu(EX_DATA_ERR, "find entry ", ESC, entry, ESC); if (!r) { - out("no site ", ESC, site, ESC, " in database"); + out("no entry ", ESC, entry, ESC, " in database"); } else { - out("Renaming ", ESC, site, ESC, " to ", ESC, new, ESC, "..."); - rebuild_db(site, new, db_otp(ctx), ctx); + out("Renaming ", ESC, entry, ESC, " to ", ESC, new, ESC, "..."); + rebuild_db(entry, new, db_otp(ctx), ctx); } return 0; diff --git a/src/ssp/show.c b/src/ssp/show.c index 5f471b3..eb05e08 100644 --- a/src/ssp/show.c +++ b/src/ssp/show.c @@ -20,11 +20,11 @@ struct show { unsigned options; }; -COMMAND(show, "Show details of a site", - "[OPTION..] <site>", -" -C, --no-comments Do not show site's comments\n" +COMMAND(show, "Show an entry", + "[OPTION..] <entry>", +" -C, --no-comments Do not show entry's comments\n" " -f, --format Output in INI-like format\n" -" -S, --secret Show site's secret\n" +" -S, --secret Show entry's secret\n" ); static int @@ -59,11 +59,11 @@ parse_cmdline(int argc, const char *argv[], const char usage[], struct show *ctx } void -show_site(unsigned options, struct ssp *ctx) +show_entry(unsigned options, struct ssp *ctx) { const char *types[] = { "Counter", "Time" }; const struct otp *otp = db_otp(ctx); - out("- Site ", ESC, db_site(ctx), ESC); + out("- Entry ", ESC, db_entry(ctx), ESC); out(" Algo: ", algos[otp->algo]); add(" ", types[otp->type], "-based; "); if (otp->type == TYPE_COUNTER) @@ -85,11 +85,11 @@ show_site(unsigned options, struct ssp *ctx) } void -show_site_ini(unsigned options, struct ssp *ctx) +show_entry_ini(unsigned options, struct ssp *ctx) { const struct otp *otp = db_otp(ctx); - out("[", PUTMSG_TOGGLE_ESC, db_site(ctx), PUTMSG_TOGGLE_ESC, "]"); + out("[", PUTMSG_TOGGLE_ESC, db_entry(ctx), PUTMSG_TOGGLE_ESC, "]"); out("algo=", algos[otp->algo]); if (otp->type == TYPE_TIME) { out("time=1"); @@ -115,7 +115,7 @@ show_main(int argc, const char *argv[], const char *env[], const char usage[], v int i = parse_cmdline(argc, argv, usage, &show); if (i == argc) { - warn("argument \"site\" missing"); + warn("argument \"entry\" missing"); diecmdusage(EX_USAGE, usage, &command_show); } @@ -130,19 +130,19 @@ show_main(int argc, const char *argv[], const char *env[], const char usage[], v if (!r) dief(0, "no database"); - const char *site = get_site_name(argv[i], ctx); - if (!site) - diefusys(exitcode_from_errno(errno), "parse site's name"); + const char *entry = get_entry_name(argv[i], ctx); + if (!entry) + diefusys(exitcode_from_errno(errno), "parse entry's name"); - r = db_find(site, ctx); + r = db_find(entry, ctx); if (r < 0) - diefu(EX_DATA_ERR, "find site ", ESC, site, ESC); + diefu(EX_DATA_ERR, "find entry ", ESC, entry, ESC); if (!r) - out("no site ", ESC, site, ESC, " in database"); + out("no entry ", ESC, entry, ESC, " in database"); else if (show.options & OPT_FMT_INI) - show_site_ini(show.options & OPT_NO_COMMENTS, ctx); + show_entry_ini(show.options & OPT_NO_COMMENTS, ctx); else - show_site(show.options, ctx); + show_entry(show.options, ctx); return 0; } diff --git a/src/ssp/ssp.c b/src/ssp/ssp.c index 2d0088e..80a433d 100644 --- a/src/ssp/ssp.c +++ b/src/ssp/ssp.c @@ -50,7 +50,7 @@ unesc(char *dst, size_t dlen, const char *sce, size_t slen) } const char * -get_site_name(const char *s, struct ssp *ctx) +get_entry_name(const char *s, struct ssp *ctx) { ssize_t l = strlen(s);