ADD: command for printing basic device info

This commit is contained in:
Dominik Meyer 2018-04-07 23:07:18 +02:00
parent b824dbc6cb
commit 382f1e1a0e
No known key found for this signature in database
GPG Key ID: B4C312B600606B64
4 changed files with 83 additions and 2 deletions

View File

@ -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

View File

@ -28,5 +28,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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 info(int argc, char **argv); ///< print infos about mooltipass device
#endif

70
src/info.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/**
* @file info.c
* @brief source file for the info command
* @author Dominik Meyer <dmeyer@federationhq.de>
* @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;
}

View File

@ -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);