00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023
00024 #ifdef HAVE_NCURSES_H
00025 # include <ncurses.h>
00026 #else // HAVE_NCURSES_H
00027 # ifdef HAVE_CURSES_H
00028 # include <curses.h>
00029 # else
00030 # error "Neither curses.h nor ncurses.h available"
00031 # endif // HAVE_CURSES_H
00032 #endif // HAVE_NCURSES_H
00033 #include "curswa.h"
00034
00035 #ifdef TIME_WITH_SYS_TIME
00036 # include <sys/time.h>
00037 # include <time.h>
00038 #else
00039 # ifdef HAVE_SYS_TIME_H
00040 # include <sys/time.h>
00041 # else
00042 # include <time.h>
00043 # endif
00044 #endif
00045
00046 #ifdef HAVE_UNISTD_H
00047 # include <unistd.h>
00048 #endif
00049
00050 #ifdef HAVE_SYS_RESOURCE_H
00051 # include <sys/resource.h>
00052 #endif
00053
00054 #ifdef HAVE_STRING_H
00055 # include <string.h>
00056 #endif
00057
00058 #ifdef HAVE_ERRNO_H
00059 # include <errno.h>
00060 #endif
00061
00062 #ifdef HAVE_IOSTREAM
00063 # include <iostream>
00064 #endif
00065
00066 #ifdef HAVE_STRING
00067 # include <string>
00068 #endif
00069
00070 #ifdef HAVE_GETOPT_H
00071 # include <getopt.h>
00072 #endif
00073
00074 #ifdef HAVE_CRYPTO_H
00075 # include <openssl/crypto.h>
00076 #endif
00077
00078 #include "../intl.h"
00079 #include "fileopen.h"
00080 #include "mainwindow.h"
00081
00091 const char COPYRIGHT[] = "YAPET -- Yet Another Password Encryption Tool\n" \
00092 "Copyright (C) 2008 Rafael Ostertag\n" \
00093 "\n" \
00094 "This program is free software: you can redistribute it and/or modify\n" \
00095 "it under the terms of the GNU General Public License as published by\n" \
00096 "the Free Software Foundation, either version 3 of the License, or\n" \
00097 "(at your option) any later version.\n" \
00098 "\n" \
00099 "This program is distributed in the hope that it will be useful,\n" \
00100 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
00101 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \
00102 "GNU General Public License for more details.\n" \
00103 "\n" \
00104 "You should have received a copy of the GNU General Public License\n" \
00105 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n";
00106
00107
00108 void set_rlimit() {
00109 #if defined(HAVE_SETRLIMIT) && defined(RLIMIT_CORE)
00110 rlimit rl;
00111
00112 rl.rlim_cur = 0;
00113 rl.rlim_max = 0;
00114 int retval = setrlimit(RLIMIT_CORE, &rl);
00115 if (retval != 0) {
00116 std::cerr << _("Failed to suppress the creation of core file.")
00117 << std::endl
00118 << _("The error message is: ") << strerror(errno)
00119 << std::endl
00120 << _("In case a core file is created, it may contain clear text passwords.")
00121 << std::endl
00122 << std::endl
00123 << _("Press <ENTER> to continue")
00124 << std::endl;
00125 char tmp;
00126 std::cin >> tmp;
00127 }
00128 #else
00129 std::cerr << _("Cannot suppress the creation of core file.")
00130 << std::endl
00131 << _("In case a core file is created, it may contain clear text passwords.")
00132 << std::endl
00133 << std::endl
00134 << _("Press <ENTER> to continue")
00135 << std::endl;
00136 char tmp;
00137 std::cin >> tmp;
00138 #endif
00139 }
00140
00141 void show_version() {
00142 std::cout << PACKAGE_STRING << std::endl;
00143
00144 #ifdef HAVE_SSLEAY_VERSION
00145 std::cout << "SSL Version: " << SSLeay_version(SSLEAY_VERSION) << std::endl;
00146 #endif
00147
00148 #ifdef NCURSES_VERSION
00149 std::cout << "Curses Implementation: " << "ncurses (" << NCURSES_VERSION << ")" << std::endl;
00150 #else // NCURSES_VERSION
00151 #ifdef _XOPEN_CURSES
00152 std::cout << "Curses Implementation: " << "XOpen Curses" << std::endl;
00153 #else // _XOPEN_CURSES
00154 std::cout << "Curses Implementation: " << "System Curses" << std::endl;
00155 #endif // _XOPEN_CURSES
00156 #endif // NCURSES_VERSION
00157
00158 #if defined(HAVE_TERMINALTITLE) && defined(HAVE_TERMNAME)
00159 std::cout << "Compiled with support for terminal title" << std::endl;
00160 #else
00161 std::cout << "Compiled without support for terminal title" << std::endl;
00162 #endif
00163 }
00164
00165 void show_copyright() {
00166 std::cout << COPYRIGHT << std::endl;
00167 }
00168
00169 void show_help(char* prgname) {
00170 show_version();
00171 std::cout << std::endl;
00172 std::cout << prgname
00173 << " [-c] [-h] [-V] [<filename>]"
00174 << std::endl
00175 << std::endl;
00176 std::cout << "-c, --copyright\tshow copyright information"
00177 << std::endl
00178 << std::endl;
00179 std::cout << "-h, --help\tshow this help text"
00180 << std::endl
00181 << std::endl;
00182 std::cout << "-V, --version\tshow the version of " PACKAGE_NAME
00183 << std::endl
00184 << std::endl;
00185 std::cout << "<filename>\topen the specified file <filename>"
00186 << std::endl
00187 << std::endl;
00188 std::cout << PACKAGE_NAME " stores passwords encrypted on disk using the blowfish algorithm."
00189 << std::endl;
00190 std::cout << "The encryption key is computed from the master password using md5, sha1, and"
00191 << std::endl;
00192 std::cout << "ripemd-160 digest algorithms producing a 448 bit (56 bytes) key."
00193 << std::endl
00194 << std::endl;
00195 }
00196
00197 int main (int argc, char** argv) {
00198 set_rlimit();
00199
00200 setlocale(LC_ALL, "");
00201 bindtextdomain(PACKAGE, LOCALEDIR);
00202 textdomain(PACKAGE);
00203
00204 int c;
00205 std::string filename;
00206 #ifdef HAVE_GETOPT_LONG
00207 struct option long_options[] = {
00208 {"copyright", no_argument, NULL, 'c'},
00209 {"help", no_argument, NULL, 'h'},
00210 {"version", no_argument, NULL, 'V'},
00211 {NULL,0,NULL,0}
00212 };
00213 while ( (c = getopt_long(argc, argv, ":chV", long_options, NULL)) != -1) {
00214 #else // HAVE_GETOPT_LONG
00215 while ( (c = getopt(argc, argv, ":c(copyright)h(help)V(version)")) != -1) {
00216 #endif // HAVE_GETOPT_LONG
00217 switch (c) {
00218 case 'c':
00219 show_copyright();
00220 return 0;
00221 case 'h':
00222 show_help(argv[0]);
00223 return 0;
00224 case 'V':
00225 show_version();
00226 return 0;
00227 case ':':
00228 std::cerr << "-" << (char)optopt << _(" without argument")
00229 << std::endl;
00230 return 1;
00231 case '?':
00232 std::cerr << _("unknown argument") << " '" << (char)optopt << "'"
00233 << std::endl;
00234 return 1;
00235 }
00236 }
00237
00238 if (argc > 1) {
00239 filename = argv[argc-1];
00240
00241 if (!endswith(filename, ".pet"))
00242 filename+=".pet";
00243 }
00244
00245 YAPETUI::BaseWindow::initCurses();
00246
00247 MainWindow* mainwin = NULL;
00248 try {
00249 mainwin = new MainWindow();
00250
00251 mainwin->run(filename);
00252 delete mainwin;
00253 } catch (std::exception& ex) {
00254 if (mainwin != NULL)
00255 delete mainwin;
00256 YAPETUI::BaseWindow::endCurses();
00257 std::cerr << ex.what() << std::endl << std::endl;
00258 return 1;
00259 }
00260
00261 YAPETUI::BaseWindow::endCurses();
00262
00263 return 0;
00264 }