1af101e7fSchristos /*
2af101e7fSchristos  * The Initial Developer of the Original Code is International
3af101e7fSchristos  * Business Machines Corporation. Portions created by IBM
4af101e7fSchristos  * Corporation are Copyright (C) 2005, 2006 International Business
5af101e7fSchristos  * Machines Corporation. All Rights Reserved.
6af101e7fSchristos  *
7af101e7fSchristos  * This program is free software; you can redistribute it and/or modify
8af101e7fSchristos  * it under the terms of the Common Public License as published by
9af101e7fSchristos  * IBM Corporation; either version 1 of the License, or (at your option)
10af101e7fSchristos  * any later version.
11af101e7fSchristos  *
12af101e7fSchristos  * This program is distributed in the hope that it will be useful,
13af101e7fSchristos  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14af101e7fSchristos  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15af101e7fSchristos  * Common Public License for more details.
16af101e7fSchristos  *
17af101e7fSchristos  * You should have received a copy of the Common Public License
18af101e7fSchristos  * along with this program; if not, a copy can be viewed at
19af101e7fSchristos  * http://www.opensource.org/licenses/cpl1.0.php.
20af101e7fSchristos  */
21af101e7fSchristos 
22af101e7fSchristos #ifndef __TPM_UTILS_H
23af101e7fSchristos #define __TPM_UTILS_H
24af101e7fSchristos 
25af101e7fSchristos #ifdef ENABLE_NLS
26af101e7fSchristos #include <libintl.h>
27af101e7fSchristos #include <locale.h>
28af101e7fSchristos #define _(String) gettext(String)
29af101e7fSchristos #define N_(String) String
30af101e7fSchristos #else
31af101e7fSchristos #define setlocale(category, local)
32af101e7fSchristos #define bindtextdomain(package, localedir)
33af101e7fSchristos #define textdomain(package);
34af101e7fSchristos #define _(String) String
35af101e7fSchristos #define N_(String) String
36af101e7fSchristos #endif
37af101e7fSchristos 
38af101e7fSchristos #include <string.h>
39af101e7fSchristos #include <stdio.h>
40af101e7fSchristos #include <stdlib.h>
41af101e7fSchristos #include <stdarg.h>
42af101e7fSchristos //#define GNU_SOURCE
43af101e7fSchristos #include <getopt.h>
44af101e7fSchristos 
45af101e7fSchristos #ifndef BOOL
46af101e7fSchristos #define BOOL int
47af101e7fSchristos #endif
48af101e7fSchristos 
49af101e7fSchristos #ifndef FALSE
50af101e7fSchristos #define FALSE 0
51af101e7fSchristos #endif
52af101e7fSchristos 
53af101e7fSchristos #ifndef TRUE
54af101e7fSchristos #define TRUE (!FALSE)
55af101e7fSchristos #endif
56af101e7fSchristos 
57af101e7fSchristos #define CMD_VERSION             PACKAGE_VERSION
58af101e7fSchristos 
59af101e7fSchristos #define LOG_NONE                _("none")
60af101e7fSchristos #define LOG_LEVEL_NONE          0
61af101e7fSchristos #define LOG_ERROR               _("error")
62af101e7fSchristos #define LOG_LEVEL_ERROR         1
63af101e7fSchristos #define LOG_INFO                _("info")
64af101e7fSchristos #define LOG_LEVEL_INFO          2
65af101e7fSchristos #define LOG_DEBUG               _("debug")
66af101e7fSchristos #define LOG_LEVEL_DEBUG         3
67af101e7fSchristos 
68*739b7041Schristos #ifdef __GNUC__
69*739b7041Schristos #define __no_optimize __attribute__((optimize("O0")))
70*739b7041Schristos #else
71*739b7041Schristos #define __no_optimize
72*739b7041Schristos #endif
73*739b7041Schristos 
74*739b7041Schristos void * __no_optimize __memset(void *s, int c, size_t n);
75*739b7041Schristos 
76af101e7fSchristos typedef int (*CmdOptParser)( const int aOpt, const char *aOptArg );
77af101e7fSchristos typedef void (*CmdHelpFunction)( const char *aCmd );
78af101e7fSchristos 
79af101e7fSchristos void initIntlSys( );
80af101e7fSchristos 
81af101e7fSchristos int genericOptHandler( int a_iNumArgs, char **a_pszArgs,
82af101e7fSchristos 		       const char *a_pszShortOpts,
83af101e7fSchristos 		       struct option *a_psLongOpts, int a_iNumOpts,
84af101e7fSchristos 		       CmdOptParser, CmdHelpFunction );
85af101e7fSchristos char *getPlainPasswd( const char* a_pszPrompt, BOOL a_bConfirm );
86af101e7fSchristos #ifdef TSS_LIB_IS_12
87af101e7fSchristos char *_getPasswd12( const char *a_pszPrompt, int *a_iLen, BOOL a_bConfirm, BOOL a_uUseUnicode);
88af101e7fSchristos char *getPasswd12( const char *a_pszPrompt, int *a_iLen, BOOL a_bConfirm );
89af101e7fSchristos 
90af101e7fSchristos #define _GETPASSWD	_getPasswd12
91af101e7fSchristos #define GETPASSWD	getPasswd12
92af101e7fSchristos #else
93af101e7fSchristos char *getPasswd( const char *a_pszPrompt, int *a_iLen, BOOL a_bConfirm );
94af101e7fSchristos 
95af101e7fSchristos #define _GETPASSWD	_getPasswd
96af101e7fSchristos #define GETPASSWD	getPasswd
97af101e7fSchristos #endif
98af101e7fSchristos char *_getPasswd( const char *a_pszPrompt, int *a_iLen, BOOL a_bConfirm, BOOL a_bUseUnicode);
99af101e7fSchristos void  shredPasswd( char *a_pszPasswd );
100af101e7fSchristos char *getReply( const char *a_pszPrompt, int a_iMaxLen );
101af101e7fSchristos 
102af101e7fSchristos extern int iLogLevel;
103af101e7fSchristos extern BOOL useUnicode;
104af101e7fSchristos 
105af101e7fSchristos int logHex( int a_iLen, void *a_pData );
106af101e7fSchristos int logMsg( const char *a_pszFormat, ... );
107af101e7fSchristos int logDebug( const char *a_pszFormat, ... );
108af101e7fSchristos int logInfo( const char *a_pszFormat, ... );
109af101e7fSchristos int logError( const char *a_pszFormat, ... );
110af101e7fSchristos 
111af101e7fSchristos int logProcess( FILE *a_pStream, const char *a_pszFormat, va_list a_vaArgs );
112af101e7fSchristos int logIt( FILE *a_pStream, const char *a_pszFormat, va_list a_vaArgs );
113af101e7fSchristos 
114af101e7fSchristos void  logSuccess( const char *a_pszCmd );
115af101e7fSchristos void  logCmdOption( const char *a_pszOption, const char *a_pszDescr );
116af101e7fSchristos void  logUnicodeCmdOption( );
117af101e7fSchristos void  logGenericOptions( );
118af101e7fSchristos void  logCmdHelp( const char *a_pszCmd );
119af101e7fSchristos void  logCmdHelpEx( const char *a_pszCmd, char *a_pszArgs[], char *a_pszArgDescs[] );
120af101e7fSchristos char *logBool( BOOL aValue );
121af101e7fSchristos void  logOwnerPassCmdOption( );
122af101e7fSchristos void  logNVIndexCmdOption( );
123af101e7fSchristos 
124af101e7fSchristos #endif
125