Welcome to little lamb

Code » ssp » commit ae0ab04

Minor tweaks

author Olivier Brunel
2023-04-18 16:47:06 UTC
committer Olivier Brunel
2023-04-19 07:38:08 UTC
parent 9f6777a12517d37cb67a3695683636fbf7016260

Minor tweaks

src/include/ssp.h +1 -1
src/ssp/add.c +2 -2
src/ssp/database.c +2 -0

diff --git a/src/include/ssp.h b/src/include/ssp.h
index b755d5f..fc63971 100644
--- a/src/include/ssp.h
+++ b/src/include/ssp.h
@@ -76,7 +76,7 @@ int open_db(struct ssp *ctx);
 #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_entry(ctx)       (ctx)->key.s
-#define db_otp(ctx)         (const struct otp *) (ctx)->val.s
+#define db_otp(ctx)         ((const struct otp *) (ctx)->val.s)
 
 /* show.c */
 void show_entry(unsigned options, struct ssp *ctx);
diff --git a/src/ssp/add.c b/src/ssp/add.c
index 927b193..b8ba645 100644
--- a/src/ssp/add.c
+++ b/src/ssp/add.c
@@ -120,10 +120,10 @@ add_main(int argc, const char *argv[], const char *env[], const char usage[], vo
     ++argv;
     i = parse_cmdline(argc, argv, usage, &add);
 
-    if (i == argc) {
+    if (argc == i) {
         warn("argument \"secret\" missing");
         diecmdusage(EX_USAGE, usage, &command_add);
-    } else if (i + 1 < argc) {
+    } else if (argc > i + 1) {
         warn("too many arguments");
         diecmdusage(EX_USAGE, usage, &command_add);
     }
diff --git a/src/ssp/database.c b/src/ssp/database.c
index 352f59e..d78e657 100644
--- a/src/ssp/database.c
+++ b/src/ssp/database.c
@@ -126,6 +126,8 @@ rebuild_db(const char *oldkey, const char *newkey, const struct otp *otp, struct
                     && (!olen || strcmp(oldkey, newkey))) {
                 diefu(EX_DATA_ERR, "add entry ", ESC, newkey, ESC, ": Already exists");
             } else {
+                /* Note the use of strcoll() here to ensure we order entries
+                 * using locale-specific rules. */
                 if (!a && strcoll(ctx->key.s, newkey) > 0) {
                     /* insert otp at the right place */
                     if (!cdbmaker_sa_add(&mkr, newkey, nlen, (char *) otp, vlen))