summaryrefslogtreecommitdiff
path: root/noncore/apps/zsafe/zsafe.cpp
Unidiff
Diffstat (limited to 'noncore/apps/zsafe/zsafe.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index 3df55eb..bf8f7f4 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -8,59 +8,58 @@
8** 8**
9** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html 9** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html
10** 10**
11** Compile Flags: 11** Compile Flags:
12** Zaurus arm : -DNO_OPIE 12** Zaurus arm : -DNO_OPIE
13** Zaurus Opie arm: none 13** Zaurus Opie arm: none
14** Linux Desktop : -DDESKTOP 14** Linux Desktop : -DDESKTOP
15** Windows Desktop: -DDESKTOP -DWIN32 15** Windows Desktop: -DDESKTOP -DWIN32
16** 16**
17** for japanese version additional use: -DJPATCH_HDE 17** for japanese version additional use: -DJPATCH_HDE
18** 18**
19****************************************************************************/ 19****************************************************************************/
20#include "zsafe.h" 20#include "zsafe.h"
21#include "newdialog.h" 21#include "newdialog.h"
22#include "searchdialog.h" 22#include "searchdialog.h"
23#include "categorydialog.h" 23#include "categorydialog.h"
24#include "passworddialog.h" 24#include "passworddialog.h"
25#include "infoform.h" 25#include "infoform.h"
26#include "zlistview.h" 26#include "zlistview.h"
27#include "shadedlistitem.h" 27#include "shadedlistitem.h"
28 28
29#ifndef DESKTOP 29#ifndef DESKTOP
30#ifndef NO_OPIE 30#ifndef NO_OPIE
31#include <opie2/ofiledialog.h> 31#include <opie2/ofiledialog.h>
32 32#include <opie2/odebug.h>
33using namespace Opie::Core;
33using namespace Opie::Ui; 34using namespace Opie::Ui;
34#else 35#else
35#include "scqtfileedit.h" 36#include "scqtfileedit.h"
36#endif 37#endif
37#endif 38#endif
38 39
39#include <qclipboard.h> 40#include <qclipboard.h>
40 41
41#include <stdio.h>
42
43#include <sys/types.h> 42#include <sys/types.h>
44#include <sys/stat.h> 43#include <sys/stat.h>
45#include <fcntl.h> 44#include <fcntl.h>
46#include <stdlib.h> 45#include <stdlib.h>
47#ifndef WIN32 46#ifndef WIN32
48#include <unistd.h> 47#include <unistd.h>
49#endif 48#endif
50#include <string.h> 49#include <string.h>
51#include <errno.h> 50#include <errno.h>
52 51
53#include <qmenubar.h> 52#include <qmenubar.h>
54#include <qpopupmenu.h> 53#include <qpopupmenu.h>
55 54
56#ifdef DESKTOP 55#ifdef DESKTOP
57#include <qfiledialog.h> 56#include <qfiledialog.h>
58#ifndef WIN32 57#ifndef WIN32
59#include <qsettings.h> 58#include <qsettings.h>
60#else 59#else
61#include "qsettings.h" 60#include "qsettings.h"
62#endif 61#endif
63#include <qapplication.h> 62#include <qapplication.h>
64#else 63#else
65#include <qfile.h> 64#include <qfile.h>
66#include <qpe/fileselector.h> 65#include <qpe/fileselector.h>
@@ -2048,69 +2047,67 @@ int ZSafe::loadInit(const char* _filename, const char *password)
2048 unsigned char charbuf[8]; 2047 unsigned char charbuf[8];
2049 unsigned short ciphertext[4]; 2048 unsigned short ciphertext[4];
2050 char key[128]; 2049 char key[128];
2051 Krc2* krc2 = new Krc2(); 2050 Krc2* krc2 = new Krc2();
2052 2051
2053 fd = fopen (_filename, "rb"); 2052 fd = fopen (_filename, "rb");
2054 2053
2055 QFileInfo f (_filename); 2054 QFileInfo f (_filename);
2056 load_buffer_length = f.size(); 2055 load_buffer_length = f.size();
2057 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; 2056 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2;
2058 2057
2059 if (fd == NULL) 2058 if (fd == NULL)
2060 return PWERR_OPEN; 2059 return PWERR_OPEN;
2061 2060
2062 buffer = (char *)malloc(load_buffer_length); 2061 buffer = (char *)malloc(load_buffer_length);
2063 for (j = 0; password[j] != '\0'; j++) { 2062 for (j = 0; password[j] != '\0'; j++) {
2064 key[j] = password[j]; 2063 key[j] = password[j];
2065 } 2064 }
2066 keylength = j; 2065 keylength = j;
2067 krc2->rc2_expandkey (key, keylength, 128); 2066 krc2->rc2_expandkey (key, keylength, 128);
2068 2067
2069#ifndef WIN32 2068#ifndef WIN32
2070 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); 2069 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
2071#else 2070#else
2072 printf ("LoadInit() read1");
2073 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2071 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2074#endif 2072#endif
2075 2073
2076 if (size < 8) 2074 if (size < 8)
2077 return PWERR_DATA; 2075 return PWERR_DATA;
2078 2076
2079 for (count = 0; count < 4; count++) { 2077 for (count = 0; count < 4; count++) {
2080 count2 = count << 1; 2078 count2 = count << 1;
2081 iv[count] = charbuf[count2] << 8; 2079 iv[count] = charbuf[count2] << 8;
2082 iv[count] += charbuf[count2 + 1]; 2080 iv[count] += charbuf[count2 + 1];
2083 } 2081 }
2084 2082
2085 size = 0; 2083 size = 0;
2086 bufferIndex = 0; 2084 bufferIndex = 0;
2087#ifndef WIN32 2085#ifndef WIN32
2088 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) { 2086 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
2089 while (count < 8) { 2087 while (count < 8) {
2090 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); 2088 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
2091#else 2089#else
2092 printf ("LoadInit() read2");
2093 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { 2090 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
2094 while (count < 8) { 2091 while (count < 8) {
2095 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2092 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2096#endif 2093#endif
2097 if (count2 == 0) { 2094 if (count2 == 0) {
2098 return PWERR_DATA; 2095 return PWERR_DATA;
2099 } 2096 }
2100 count += count2; 2097 count += count2;
2101 } /* while (count < 8) */ 2098 } /* while (count < 8) */
2102 2099
2103 size += 8; 2100 size += 8;
2104 for (count2 = 0; count2 < 8; count2 += 2) { 2101 for (count2 = 0; count2 < 8; count2 += 2) {
2105 count3 = count2 >> 1; 2102 count3 = count2 >> 1;
2106 ciphertext[count3] = charbuf[count2] << 8; 2103 ciphertext[count3] = charbuf[count2] << 8;
2107 ciphertext[count3] += charbuf[count2 + 1]; 2104 ciphertext[count3] += charbuf[count2 + 1];
2108 2105
2109 plaintext[count3] = ciphertext[count3] ^ iv[count3]; 2106 plaintext[count3] = ciphertext[count3] ^ iv[count3];
2110 iv[count3] = plaintext[count3]; 2107 iv[count3] = plaintext[count3];
2111 } /* for (count2) */ 2108 } /* for (count2) */
2112 2109
2113 krc2->rc2_decrypt (plaintext); 2110 krc2->rc2_decrypt (plaintext);
2114 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); 2111 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
2115 bufferIndex += 8; 2112 bufferIndex += 8;
2116 buffer[bufferIndex + 1] = '\0'; 2113 buffer[bufferIndex + 1] = '\0';
@@ -2238,102 +2235,102 @@ bool ZSafe::saveDocument(const char* _filename,
2238 char* entry[FIELD_SIZE]; 2235 char* entry[FIELD_SIZE];
2239 2236
2240 // save the validation entry 2237 // save the validation entry
2241 { 2238 {
2242 int i=0; 2239 int i=0;
2243 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1); 2240 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1);
2244 strcpy(entry[i++], "ZSAFECATEGORY"); 2241 strcpy(entry[i++], "ZSAFECATEGORY");
2245 entry[i] = (char*)malloc(strlen("name")+1); 2242 entry[i] = (char*)malloc(strlen("name")+1);
2246 strcpy(entry[i++], "name"); 2243 strcpy(entry[i++], "name");
2247 entry[i] = (char*)malloc(strlen("username")+1); 2244 entry[i] = (char*)malloc(strlen("username")+1);
2248 strcpy(entry[i++], "username"); 2245 strcpy(entry[i++], "username");
2249 entry[i] = (char*)malloc(strlen("password")+1); 2246 entry[i] = (char*)malloc(strlen("password")+1);
2250 strcpy(entry[i++], "password"); 2247 strcpy(entry[i++], "password");
2251 entry[i] = (char*)malloc(strlen("comment")+1); 2248 entry[i] = (char*)malloc(strlen("comment")+1);
2252 strcpy(entry[i++], "comment"); 2249 strcpy(entry[i++], "comment");
2253 2250
2254 entry[i] = (char*)malloc(strlen("field5")+1); 2251 entry[i] = (char*)malloc(strlen("field5")+1);
2255 strcpy(entry[i++], "field5"); 2252 strcpy(entry[i++], "field5");
2256 entry[i] = (char*)malloc(strlen("field6")+1); 2253 entry[i] = (char*)malloc(strlen("field6")+1);
2257 strcpy(entry[i++], "field6"); 2254 strcpy(entry[i++], "field6");
2258 2255
2259 retval = saveEntry(entry); 2256 retval = saveEntry(entry);
2260 for (int z=0; z<i; z++) free(entry[z]); 2257 for (int z=0; z<i; z++) free(entry[z]);
2261 if (retval == PWERR_DATA) { 2258 if (retval == PWERR_DATA) {
2262 qWarning("1: Error writing file, contents not saved"); 2259 owarn << "1: Error writing file, contents not saved" << oendl;
2263 saveFinalize(); 2260 saveFinalize();
2264 return false; 2261 return false;
2265 } 2262 }
2266// #ifndef WIN32 2263// #ifndef WIN32
2267 conf->writeEntry(APP_KEY+"valzsafe", 1); 2264 conf->writeEntry(APP_KEY+"valzsafe", 1);
2268// #endif 2265// #endif
2269 saveConf(); 2266 saveConf();
2270 } 2267 }
2271 2268
2272 QListViewItem *i; 2269 QListViewItem *i;
2273 // step through all categories 2270 // step through all categories
2274 for (i = ListView->firstChild(); 2271 for (i = ListView->firstChild();
2275 i != NULL; 2272 i != NULL;
2276 i = i->nextSibling()) 2273 i = i->nextSibling())
2277 { 2274 {
2278 // step through all subitems 2275 // step through all subitems
2279 QListViewItem *si; 2276 QListViewItem *si;
2280 for (si = i->firstChild(); 2277 for (si = i->firstChild();
2281 si != NULL; 2278 si != NULL;
2282 si = si->nextSibling()) 2279 si = si->nextSibling())
2283 { 2280 {
2284 int j=0; 2281 int j=0;
2285 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1); 2282 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1);
2286 strcpy(entry[j++], i->text(0).utf8()); 2283 strcpy(entry[j++], i->text(0).utf8());
2287 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1); 2284 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1);
2288 strcpy(entry[j++], si->text(0).utf8()); 2285 strcpy(entry[j++], si->text(0).utf8());
2289 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1); 2286 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1);
2290 strcpy(entry[j++], si->text(1).utf8()); 2287 strcpy(entry[j++], si->text(1).utf8());
2291 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1); 2288 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1);
2292 strcpy(entry[j++], si->text(2).utf8()); 2289 strcpy(entry[j++], si->text(2).utf8());
2293 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1); 2290 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1);
2294 strcpy(entry[j++], si->text(3).utf8()); 2291 strcpy(entry[j++], si->text(3).utf8());
2295 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1); 2292 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1);
2296 strcpy(entry[j++], si->text(4).utf8()); 2293 strcpy(entry[j++], si->text(4).utf8());
2297 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1); 2294 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1);
2298 strcpy(entry[j++], si->text(5).utf8()); 2295 strcpy(entry[j++], si->text(5).utf8());
2299 2296
2300 retval = saveEntry(entry); 2297 retval = saveEntry(entry);
2301 for (int z=0; z<j; z++) 2298 for (int z=0; z<j; z++)
2302 { 2299 {
2303 free(entry[z]); 2300 free(entry[z]);
2304 } 2301 }
2305 if (retval == PWERR_DATA) { 2302 if (retval == PWERR_DATA) {
2306 qWarning("1: Error writing file, contents not saved"); 2303 owarn << "1: Error writing file, contents not saved" << oendl;
2307 saveFinalize(); 2304 saveFinalize();
2308 return false; 2305 return false;
2309 } 2306 }
2310 2307
2311 } 2308 }
2312 } 2309 }
2313 2310
2314 if (saveFinalize() == PWERR_DATA) { 2311 if (saveFinalize() == PWERR_DATA) {
2315 qWarning("2: Error writing file, contents not saved"); 2312 owarn << "2: Error writing file, contents not saved" << oendl;
2316 return false; 2313 return false;
2317 } else { 2314 } else {
2318#ifndef DESKTOP 2315#ifndef DESKTOP
2319 Global::statusMessage (tr("Password file saved.")); 2316 Global::statusMessage (tr("Password file saved."));
2320#endif 2317#endif
2321 modified = false; 2318 modified = false;
2322 return true; 2319 return true;
2323 } 2320 }
2324} 2321}
2325 2322
2326PasswordForm *newPwdDialog; 2323PasswordForm *newPwdDialog;
2327bool newPwdDialogResult = false; 2324bool newPwdDialogResult = false;
2328void ZSafe::setPasswordDialogDone() 2325void ZSafe::setPasswordDialogDone()
2329{ 2326{
2330 newPwdDialogResult = true; 2327 newPwdDialogResult = true;
2331 newPwdDialog->close(); 2328 newPwdDialog->close();
2332} 2329}
2333 2330
2334void ZSafe::getDocPassword(QString title) 2331void ZSafe::getDocPassword(QString title)
2335{ 2332{
2336qWarning ("getDocPassword"); 2333qWarning ("getDocPassword");
2337 // open the 'Password' dialog 2334 // open the 'Password' dialog
2338 PasswordForm *dialog = new PasswordForm(this, title, TRUE); 2335 PasswordForm *dialog = new PasswordForm(this, title, TRUE);
2339 newPwdDialog = dialog; 2336 newPwdDialog = dialog;
@@ -3169,49 +3166,49 @@ void ZSafe::editCategory()
3169 DialogCode result = (DialogCode) dialog->exec(); 3166 DialogCode result = (DialogCode) dialog->exec();
3170#ifdef DESKTOP 3167#ifdef DESKTOP
3171 result = Accepted; 3168 result = Accepted;
3172#endif 3169#endif
3173 3170
3174 QString fullIconPath; 3171 QString fullIconPath;
3175 QPixmap *pix; 3172 QPixmap *pix;
3176 if (result == Accepted) 3173 if (result == Accepted)
3177 { 3174 {
3178 modified = true; 3175 modified = true;
3179 if (category != dialog->CategoryField->currentText()) 3176 if (category != dialog->CategoryField->currentText())
3180 { 3177 {
3181 categories.remove (category); 3178 categories.remove (category);
3182// #ifndef WIN32 3179// #ifndef WIN32
3183 conf->removeEntry(category); 3180 conf->removeEntry(category);
3184// #endif 3181// #endif
3185 saveConf(); 3182 saveConf();
3186 } 3183 }
3187 3184
3188 category = dialog->CategoryField->currentText(); 3185 category = dialog->CategoryField->currentText();
3189 icon = dialog->IconField->currentText()+".png"; 3186 icon = dialog->IconField->currentText()+".png";
3190 3187
3191 if (cat) 3188 if (cat)
3192 { 3189 {
3193 qWarning("Category found"); 3190 owarn << "Category found" << oendl;
3194 3191
3195 // if (!icon.isEmpty() && !icon.isNull()) 3192 // if (!icon.isEmpty() && !icon.isNull())
3196 if (icon != "predefined.png") 3193 if (icon != "predefined.png")
3197 { 3194 {
3198 // build the full path 3195 // build the full path
3199 fullIconPath = iconPath + icon; 3196 fullIconPath = iconPath + icon;
3200 pix = new QPixmap (fullIconPath); 3197 pix = new QPixmap (fullIconPath);
3201 if (pix) 3198 if (pix)
3202 { 3199 {
3203 // save the full pixmap name into the config file 3200 // save the full pixmap name into the config file
3204// #ifndef WIN32 3201// #ifndef WIN32
3205 conf->writeEntry(APP_KEY+category, icon); 3202 conf->writeEntry(APP_KEY+category, icon);
3206// #endif 3203// #endif
3207 saveConf(); 3204 saveConf();
3208 QImage img = pix->convertToImage(); 3205 QImage img = pix->convertToImage();
3209 pix->convertFromImage(img.smoothScale(14,14)); 3206 pix->convertFromImage(img.smoothScale(14,14));
3210 cat->setIconName (icon); 3207 cat->setIconName (icon);
3211 cat->setIcon (*pix); 3208 cat->setIcon (*pix);
3212 } 3209 }
3213 } 3210 }
3214 else 3211 else
3215 { 3212 {
3216// #ifndef WIN32 3213// #ifndef WIN32
3217 conf->removeEntry (category); 3214 conf->removeEntry (category);