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