From 382f1e1a0e4381b864d7e20dc6583239b2b2cf68 Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Sat, 7 Apr 2018 23:07:18 +0200 Subject: [PATCH] ADD: command for printing basic device info --- Makefile.am | 1 + src/commands.h | 4 +-- src/info.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 10 ++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 src/info.c diff --git a/Makefile.am b/Makefile.am index 790795d..894d5ad 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,6 +6,7 @@ mpass_SOURCES = src/get.c mpass_SOURCES += yaap/src/argparse.c mpass_SOURCES += src/main.c mpass_SOURCES += src/ls.c +mpass_SOURCES += src/info.c if HAVE_X11 mpass_SOURCES+=src/x11_clipboard.c diff --git a/src/commands.h b/src/commands.h index 6bbaa85..e7a500e 100644 --- a/src/commands.h +++ b/src/commands.h @@ -27,6 +27,6 @@ along with this program. If not, see . */ int get(int argc, char **argv); ///< get the password from the mooltipass device -int ls(int argc, char **argv); ///< list services/logins on mooltipass device - +int ls(int argc, char **argv); ///< list services/logins on mooltipass device +int info(int argc, char **argv); ///< print infos about mooltipass device #endif diff --git a/src/info.c b/src/info.c new file mode 100644 index 0000000..3e087be --- /dev/null +++ b/src/info.c @@ -0,0 +1,70 @@ +/* +moolticute-pass + +Copyright (C) 2018 Dominik Meyer + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/** +* @file info.c +* @brief source file for the info command +* @author Dominik Meyer +* @copyright 2018 by Dominik Meyer +*/ +#include "../libmoolticute-c/src/moolticute.h" + +/** +* @brief show infos about the mooltipass device +* +* @param argc - number of command line arguments +* @param argv - array of command line arguments +* +* @return standard return value +*/ +int info(int argc, char **argv) +{ + struct moolticute_ctx *ctx; + int ret=0; + + // create moolticute context + ctx=moolticute_init_ctx(); + if (ctx == NULL) + { + fprintf(stderr,"ERROR: can not create library context.\n"); + return -1; + } + + // connect to moolticute daemon + ret=moolticute_connect(ctx); + if (ret < 0) + { + fprintf(stderr,"ERROR: can not connect to moolticute daemon. Is daemon running and is environment variable correctly set?\n"); + return -1; + } + + printf("|--moolticute\n"); + printf("| |--info\n"); + printf("| | |--device\n"); + printf("| | | |--flash_size=%d\n",ctx->info.device.flash_size); + printf("| | | |--hw_serial=%.8X\n",ctx->info.device.hw_serial); + printf("| | | |--hw_version=%s\n",ctx->info.device.hw_version); + printf("| | |--status\n"); + printf("| | | |--connected-to-daemon=%d\n",ctx->info.status.connected); + printf("| | | |--device-locked=%d\n",ctx->info.status.locked); + + + + return 0; +} diff --git a/src/main.c b/src/main.c index 3662a2a..918be26 100644 --- a/src/main.c +++ b/src/main.c @@ -62,6 +62,16 @@ int main(int argc, char **argv) }; argparse_add_command(argparse_ctx, &ls_cmd); + // command-line info command + struct arg_parse_cmd info_cmd = { + {ARG_CMD,1,0}, // set it mandatory, all commands should be mandatory + 0, + "info", + "print some infos about your mooltipass device", + &info + }; + argparse_add_command(argparse_ctx, &info_cmd); + // parse the command line, this function calls the correct function for each command int ret=argparse_parse(argparse_ctx, argc, argv);