1 /*
2  * common.h - Common definitions for stoken and stoken-gui
3  *
4  * Copyright 2012 Kevin Cernekee <cernekee@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef __STOKEN_COMMON_H__
22 #define __STOKEN_COMMON_H__
23 
24 #include "config.h"
25 
26 #include <stdarg.h>
27 #include <sys/types.h>
28 
29 #include "stoken-internal.h"
30 
31 static const char stoken_errstr[][32] = {
32 	"Success",
33 	"General failure",
34 	"Invalid length",
35 	"Unsupported token version",
36 	"Checksum failed",
37 	"Invalid password format",
38 	"Missing required password",
39 	"Seed decryption failed",
40 	"Device ID mismatch",
41 	"Out of memory",
42 	"Cannot read file",
43 	"Multiple tokens found in input",
44 };
45 
46 #define NOT_GUI			0
47 #define IS_GUI			1
48 
49 void prompt(const char *fmt, ...);
50 void warn(const char *fmt, ...);
51 void dbg(const char *fmt, ...);
52 void die(const char *fmt, ...);
53 
54 char *xstrdup(const char *s);
55 char *xconcat(const char *s1, const char *s2);
56 void xstrncpy(char *dest, const char *src, size_t n);
57 void *xmalloc(size_t size);
58 void *xzalloc(size_t size);
59 
60 char *parse_cmdline(int argc, char **argv, int is_gui);
61 int common_init(char *cmd);
62 int write_token_and_pin(char *token_str, char *pin_str, char *password);
63 char *format_token(const char *raw_token_str);
64 
65 /* binary flags, long options */
66 extern int opt_random, opt_keep_password, opt_blocks, opt_iphone, opt_android,
67 	opt_v3, opt_show_qr, opt_seed, opt_sdtid, opt_small, opt_next;
68 
69 /* binary flags, short/long options */
70 extern int opt_debug, opt_version, opt_help, opt_batch, opt_force, opt_stdin;
71 
72 /* string arguments */
73 extern char *opt_rcfile, *opt_file, *opt_token, *opt_devid, *opt_password,
74 	    *opt_pin, *opt_use_time, *opt_new_password, *opt_new_devid,
75 	    *opt_new_pin, *opt_template, *opt_qr;
76 
77 /* token read from .stokenrc, if available */
78 struct securid_token;
79 extern struct securid_token *current_token;
80 
81 #endif /* !__STOKEN_COMMON_H__ */
82