author | zautrix <zautrix> | 2004-10-23 17:05:41 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-23 17:05:41 (UTC) |
commit | 13d274c37baaae48a1c93081077cf3035459c6a8 (patch) (unidiff) | |
tree | cf49d1c5bec1fb4cd8bbd7fc9a007304634676a8 /pwmanager | |
parent | fbdad188bd7048148cc60c90325efcccb0417060 (diff) | |
download | kdepimpi-13d274c37baaae48a1c93081077cf3035459c6a8.zip kdepimpi-13d274c37baaae48a1c93081077cf3035459c6a8.tar.gz kdepimpi-13d274c37baaae48a1c93081077cf3035459c6a8.tar.bz2 |
made pwm compile on windows. now the cryptolibs are still missing
-rw-r--r-- | pwmanager/pwmanager/blowfish.h | 11 | ||||
-rw-r--r-- | pwmanager/pwmanager/gpasmanfile.cpp | 16 | ||||
-rw-r--r-- | pwmanager/pwmanager/htmlgen.cpp | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/ipc.cpp | 7 | ||||
-rw-r--r-- | pwmanager/pwmanager/ipc.h | 5 | ||||
-rw-r--r-- | pwmanager/pwmanager/libgcryptif.h | 7 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwm.cpp | 1 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmanager.pro | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 9 | ||||
-rw-r--r-- | pwmanager/pwmanager/spinforsignal.h | 2 |
10 files changed, 50 insertions, 12 deletions
diff --git a/pwmanager/pwmanager/blowfish.h b/pwmanager/pwmanager/blowfish.h index c05de77..5129eab 100644 --- a/pwmanager/pwmanager/blowfish.h +++ b/pwmanager/pwmanager/blowfish.h | |||
@@ -1,120 +1,129 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * blowfish.c - Blowfish encryption * | 6 | * blowfish.c - Blowfish encryption * |
7 | * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. * | 7 | * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. * |
8 | * * | 8 | * * |
9 | * This program is free software; you can redistribute it and/or modify * | 9 | * This program is free software; you can redistribute it and/or modify * |
10 | * it under the terms of the GNU General Public License version 2 * | 10 | * it under the terms of the GNU General Public License version 2 * |
11 | * as published by the Free Software Foundation. * | 11 | * as published by the Free Software Foundation. * |
12 | * * | 12 | * * |
13 | ***************************************************************************/ | 13 | ***************************************************************************/ |
14 | 14 | ||
15 | /*************************************************************************** | 15 | /*************************************************************************** |
16 | * copyright (C) 2004 by Ulf Schenk | 16 | * copyright (C) 2004 by Ulf Schenk |
17 | * This file is originaly based on version 1.0.1 of pwmanager | 17 | * This file is originaly based on version 1.0.1 of pwmanager |
18 | * and was modified to run on embedded devices that run microkde | 18 | * and was modified to run on embedded devices that run microkde |
19 | * | 19 | * |
20 | * $Id$ | 20 | * $Id$ |
21 | **************************************************************************/ | 21 | **************************************************************************/ |
22 | 22 | ||
23 | #ifndef BLOWFISH_H | 23 | #ifndef BLOWFISH_H |
24 | #define BLOWFISH_H | 24 | #define BLOWFISH_H |
25 | 25 | ||
26 | #include "pwmexception.h" | 26 | #include "pwmexception.h" |
27 | 27 | #ifndef _WIN32_ | |
28 | #include <stdint.h> | 28 | #include <stdint.h> |
29 | #else | ||
30 | |||
31 | #endif | ||
29 | #include <string> | 32 | #include <string> |
30 | using std::string; | 33 | using std::string; |
31 | 34 | ||
32 | #define BLOWFISH_BLOCKSIZE8 | 35 | #define BLOWFISH_BLOCKSIZE8 |
33 | #define BLOWFISH_ROUNDS 16 | 36 | #define BLOWFISH_ROUNDS 16 |
34 | #define CIPHER_ALGO_BLOWFISH 4/* blowfish 128 bit key */ | 37 | #define CIPHER_ALGO_BLOWFISH 4/* blowfish 128 bit key */ |
35 | 38 | ||
39 | #ifndef _WIN32_ | ||
36 | typedef uint8_t byte; | 40 | typedef uint8_t byte; |
41 | #else | ||
42 | #define uint8_t Q_UINT8 | ||
43 | #define byte Q_UINT8 | ||
44 | #define uint32_t Q_UINT32 | ||
45 | #endif | ||
37 | 46 | ||
38 | /** blowfish encryption algorithm. | 47 | /** blowfish encryption algorithm. |
39 | * Derived from libgcrypt-1.1.12 | 48 | * Derived from libgcrypt-1.1.12 |
40 | */ | 49 | */ |
41 | class Blowfish | 50 | class Blowfish |
42 | { | 51 | { |
43 | struct BLOWFISH_context | 52 | struct BLOWFISH_context |
44 | { | 53 | { |
45 | uint32_t s0[256]; | 54 | uint32_t s0[256]; |
46 | uint32_t s1[256]; | 55 | uint32_t s1[256]; |
47 | uint32_t s2[256]; | 56 | uint32_t s2[256]; |
48 | uint32_t s3[256]; | 57 | uint32_t s3[256]; |
49 | uint32_t p[BLOWFISH_ROUNDS+2]; | 58 | uint32_t p[BLOWFISH_ROUNDS+2]; |
50 | }; | 59 | }; |
51 | 60 | ||
52 | public: | 61 | public: |
53 | Blowfish() {} | 62 | Blowfish() {} |
54 | static bool selfTest(); | 63 | static bool selfTest(); |
55 | 64 | ||
56 | /** set key to encrypt. if return == 1, it is a weak key. */ | 65 | /** set key to encrypt. if return == 1, it is a weak key. */ |
57 | int bf_setkey( byte *key, unsigned int keylen ); | 66 | int bf_setkey( byte *key, unsigned int keylen ); |
58 | /** encrypt inbuf and return it in outbuf. | 67 | /** encrypt inbuf and return it in outbuf. |
59 | * inbuf and outbuf have to be: buf % 8 == 0 | 68 | * inbuf and outbuf have to be: buf % 8 == 0 |
60 | * You may check this with getPaddedLen() and pad with NULL. | 69 | * You may check this with getPaddedLen() and pad with NULL. |
61 | */ | 70 | */ |
62 | int bf_encrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len ); | 71 | int bf_encrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len ); |
63 | /** decrypt inbuf and return it in outbuf. | 72 | /** decrypt inbuf and return it in outbuf. |
64 | * inbuf and outbuf have to be: buf % 8 == 0 | 73 | * inbuf and outbuf have to be: buf % 8 == 0 |
65 | * You may check this with getPaddedLen() and pad with NULL. | 74 | * You may check this with getPaddedLen() and pad with NULL. |
66 | */ | 75 | */ |
67 | int bf_decrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len ); | 76 | int bf_decrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len ); |
68 | /** returns the length, the sting has to be padded to */ | 77 | /** returns the length, the sting has to be padded to */ |
69 | static unsigned int getPaddedLen(unsigned int inLen) | 78 | static unsigned int getPaddedLen(unsigned int inLen) |
70 | { return ((8 - (inLen % 8)) + inLen); } | 79 | { return ((8 - (inLen % 8)) + inLen); } |
71 | /** pad up to 8 bytes. */ | 80 | /** pad up to 8 bytes. */ |
72 | static void padNull(string *buf); | 81 | static void padNull(string *buf); |
73 | /** remove padded data */ | 82 | /** remove padded data */ |
74 | static bool unpadNull(string *buf); | 83 | static bool unpadNull(string *buf); |
75 | 84 | ||
76 | protected: | 85 | protected: |
77 | #if BLOWFISH_ROUNDS != 16 | 86 | #if BLOWFISH_ROUNDS != 16 |
78 | uint32_t function_F( uint32_t x) | 87 | uint32_t function_F( uint32_t x) |
79 | { | 88 | { |
80 | uint16_t a, b, c, d; | 89 | uint16_t a, b, c, d; |
81 | #ifdef BIG_ENDIAN_HOST | 90 | #ifdef BIG_ENDIAN_HOST |
82 | a = ((byte *) & x)[0]; | 91 | a = ((byte *) & x)[0]; |
83 | b = ((byte *) & x)[1]; | 92 | b = ((byte *) & x)[1]; |
84 | c = ((byte *) & x)[2]; | 93 | c = ((byte *) & x)[2]; |
85 | d = ((byte *) & x)[3]; | 94 | d = ((byte *) & x)[3]; |
86 | #else | 95 | #else |
87 | a = ((byte *) & x)[3]; | 96 | a = ((byte *) & x)[3]; |
88 | b = ((byte *) & x)[2]; | 97 | b = ((byte *) & x)[2]; |
89 | c = ((byte *) & x)[1]; | 98 | c = ((byte *) & x)[1]; |
90 | d = ((byte *) & x)[0]; | 99 | d = ((byte *) & x)[0]; |
91 | #endif | 100 | #endif |
92 | return ((bc.s0[a] + bc.s1[b]) ^ bc.s2[c]) + bc.s3[d]; | 101 | return ((bc.s0[a] + bc.s1[b]) ^ bc.s2[c]) + bc.s3[d]; |
93 | } | 102 | } |
94 | #endif | 103 | #endif |
95 | void R(uint32_t &l, uint32_t &r, uint32_t i, uint32_t *p, | 104 | void R(uint32_t &l, uint32_t &r, uint32_t i, uint32_t *p, |
96 | uint32_t *s0, uint32_t *s1, uint32_t *s2, uint32_t *s3) | 105 | uint32_t *s0, uint32_t *s1, uint32_t *s2, uint32_t *s3) |
97 | { | 106 | { |
98 | l ^= p[i]; | 107 | l ^= p[i]; |
99 | #ifdef BIG_ENDIAN_HOST | 108 | #ifdef BIG_ENDIAN_HOST |
100 | r ^= (( s0[((byte*)&l)[0]] + s1[((byte*)&l)[1]]) | 109 | r ^= (( s0[((byte*)&l)[0]] + s1[((byte*)&l)[1]]) |
101 | ^ s2[((byte*)&l)[2]]) + s3[((byte*)&l)[3]]; | 110 | ^ s2[((byte*)&l)[2]]) + s3[((byte*)&l)[3]]; |
102 | #else | 111 | #else |
103 | r ^= (( s0[((byte*)&l)[3]] + s1[((byte*)&l)[2]]) | 112 | r ^= (( s0[((byte*)&l)[3]] + s1[((byte*)&l)[2]]) |
104 | ^ s2[((byte*)&l)[1]]) + s3[((byte*)&l)[0]]; | 113 | ^ s2[((byte*)&l)[1]]) + s3[((byte*)&l)[0]]; |
105 | #endif | 114 | #endif |
106 | } | 115 | } |
107 | void encrypt_block(byte *outbuf, byte *inbuf); | 116 | void encrypt_block(byte *outbuf, byte *inbuf); |
108 | void decrypt_block(byte *outbuf, byte *inbuf); | 117 | void decrypt_block(byte *outbuf, byte *inbuf); |
109 | void burn_stack(int bytes); | 118 | void burn_stack(int bytes); |
110 | void do_encrypt(uint32_t *ret_xl, uint32_t *ret_xr); | 119 | void do_encrypt(uint32_t *ret_xl, uint32_t *ret_xr); |
111 | void do_decrypt(uint32_t *ret_xl, uint32_t *ret_xr); | 120 | void do_decrypt(uint32_t *ret_xl, uint32_t *ret_xr); |
112 | void do_encrypt_block(byte *outbuf, byte *inbuf); | 121 | void do_encrypt_block(byte *outbuf, byte *inbuf); |
113 | void do_decrypt_block(byte *outbuf, byte *inbuf); | 122 | void do_decrypt_block(byte *outbuf, byte *inbuf); |
114 | int do_bf_setkey(byte *key, unsigned int keylen); | 123 | int do_bf_setkey(byte *key, unsigned int keylen); |
115 | 124 | ||
116 | protected: | 125 | protected: |
117 | struct BLOWFISH_context bc; | 126 | struct BLOWFISH_context bc; |
118 | }; | 127 | }; |
119 | 128 | ||
120 | #endif | 129 | #endif |
diff --git a/pwmanager/pwmanager/gpasmanfile.cpp b/pwmanager/pwmanager/gpasmanfile.cpp index f80bc13..ae34c83 100644 --- a/pwmanager/pwmanager/gpasmanfile.cpp +++ b/pwmanager/pwmanager/gpasmanfile.cpp | |||
@@ -1,437 +1,447 @@ | |||
1 | /* Gpasman, a password manager | 1 | /* Gpasman, a password manager |
2 | Copyright (C) 1998-1999 Olivier Sessink, olivier@lx.student.wau.nl | 2 | Copyright (C) 1998-1999 Olivier Sessink, olivier@lx.student.wau.nl |
3 | 3 | ||
4 | file.c, handles file opening and closing | 4 | file.c, handles file opening and closing |
5 | 5 | ||
6 | Other code contributors: | 6 | Other code contributors: |
7 | Dave Rudder | 7 | Dave Rudder |
8 | Chris Halverson | 8 | Chris Halverson |
9 | Matthew Palmer | 9 | Matthew Palmer |
10 | Guide Berning | 10 | Guide Berning |
11 | Jimmy Mason | 11 | Jimmy Mason |
12 | website at http://www.student.wau.nl/~olivier/gpasman/ | 12 | website at http://www.student.wau.nl/~olivier/gpasman/ |
13 | 13 | ||
14 | This program is free software; you can redistribute it and/or modify | 14 | This program is free software; you can redistribute it and/or modify |
15 | it under the terms of the GNU General Public License as published by | 15 | it under the terms of the GNU General Public License as published by |
16 | the Free Software Foundation; either version 2 of the License, or | 16 | the Free Software Foundation; either version 2 of the License, or |
17 | (at your option) any later version. | 17 | (at your option) any later version. |
18 | 18 | ||
19 | This program is distributed in the hope that it will be useful, | 19 | This program is distributed in the hope that it will be useful, |
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | GNU General Public License for more details. | 22 | GNU General Public License for more details. |
23 | 23 | ||
24 | You should have received a copy of the GNU General Public License | 24 | You should have received a copy of the GNU General Public License |
25 | along with this program; if not, write to the Free Software | 25 | along with this program; if not, write to the Free Software |
26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
27 | */ | 27 | */ |
28 | 28 | ||
29 | /* 2003/06/10: | 29 | /* 2003/06/10: |
30 | * modified by Michael Buesch to work together | 30 | * modified by Michael Buesch to work together |
31 | * with PwM as import/export module. | 31 | * with PwM as import/export module. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | /*************************************************************************** | 34 | /*************************************************************************** |
35 | * copyright (C) 2004 by Ulf Schenk | 35 | * copyright (C) 2004 by Ulf Schenk |
36 | * This file is originaly based on version 1.0.1 of pwmanager | 36 | * This file is originaly based on version 1.0.1 of pwmanager |
37 | * and was modified to run on embedded devices that run microkde | 37 | * and was modified to run on embedded devices that run microkde |
38 | * | 38 | * |
39 | * $Id$ | 39 | * $Id$ |
40 | **************************************************************************/ | 40 | **************************************************************************/ |
41 | 41 | ||
42 | #include <sys/types.h> | 42 | #include <sys/types.h> |
43 | #include <sys/stat.h> | 43 | #include <sys/stat.h> |
44 | #include <stdio.h> | 44 | #include <stdio.h> |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <stdlib.h> | 46 | #include <stdlib.h> |
47 | #ifndef _WIN32_ | ||
47 | #include <unistd.h> | 48 | #include <unistd.h> |
49 | #else | ||
50 | #include <io.h> | ||
51 | #define S_IRUSR _S_IREAD | ||
52 | #define S_IWUSR _S_IWRITE | ||
53 | #define creat _creat | ||
54 | #endif | ||
48 | #include <string.h> | 55 | #include <string.h> |
49 | #include <errno.h> | 56 | #include <errno.h> |
50 | 57 | ||
51 | #include "gpasmanfile.h" | 58 | #include "gpasmanfile.h" |
52 | #include "globalstuff.h" | 59 | #include "globalstuff.h" |
53 | 60 | ||
54 | #define SAVE_BUFFER_LENGTH 1024 | 61 | #define SAVE_BUFFER_LENGTH 1024 |
55 | #define LOAD_BUFFER_LENGTH 2048 | 62 | #define LOAD_BUFFER_LENGTH 2048 |
56 | 63 | ||
57 | #ifndef S_IAMB | 64 | #ifndef S_IAMB |
58 | #define S_IAMB 00777 | 65 | #define S_IAMB 00777 |
59 | #endif | 66 | #endif |
60 | 67 | ||
61 | // enable/disable debug output | 68 | // enable/disable debug output |
62 | //#define GPASMANFILE_DEBUG | 69 | //#define GPASMANFILE_DEBUG |
63 | #undef GPASMANFILE_DEBUG | 70 | #undef GPASMANFILE_DEBUG |
64 | 71 | ||
65 | 72 | #ifndef _WIN32_ | |
66 | #if defined(PWM_DEBUG) && defined(GPASMANFILE_DEBUG) | 73 | #if defined(PWM_DEBUG) && defined(GPASMANFILE_DEBUG) |
67 | # define DBG(msg,x...)do { fprintf(stderr, msg "\n" , ##x); } while (0) | 74 | # define DBG(msg,x...)do { fprintf(stderr, msg "\n" , ##x); } while (0) |
68 | #else | 75 | #else |
69 | # define DBG(msg,x...)do { } while (0) | 76 | # define DBG(msg,x...)do { } while (0) |
70 | #endif | 77 | #endif |
78 | #else | ||
79 | # define DBG | ||
80 | #endif | ||
71 | 81 | ||
72 | #ifdef BIG_ENDIAN_HOST | 82 | #ifdef BIG_ENDIAN_HOST |
73 | # define WORDS_BIGENDIAN | 83 | # define WORDS_BIGENDIAN |
74 | #else | 84 | #else |
75 | # undef WORDS_BIGENDIAN | 85 | # undef WORDS_BIGENDIAN |
76 | #endif | 86 | #endif |
77 | 87 | ||
78 | 88 | ||
79 | GpasmanFile::GpasmanFile() | 89 | GpasmanFile::GpasmanFile() |
80 | { | 90 | { |
81 | } | 91 | } |
82 | 92 | ||
83 | GpasmanFile::~GpasmanFile() | 93 | GpasmanFile::~GpasmanFile() |
84 | { | 94 | { |
85 | } | 95 | } |
86 | 96 | ||
87 | int GpasmanFile::save_init(const char *filename, const char *password) | 97 | int GpasmanFile::save_init(const char *filename, const char *password) |
88 | { | 98 | { |
89 | 99 | ||
90 | /* | 100 | /* |
91 | * returncodes: | 101 | * returncodes: |
92 | * 1 = success | 102 | * 1 = success |
93 | * 0 = can't open filedescriptor / can't create file | 103 | * 0 = can't open filedescriptor / can't create file |
94 | * -1 = permissions are bad | 104 | * -1 = permissions are bad |
95 | * -2 = is a symlink | 105 | * -2 = is a symlink |
96 | * -3 = can't get file status | 106 | * -3 = can't get file status |
97 | */ | 107 | */ |
98 | 108 | ||
99 | unsigned char key[128]; | 109 | unsigned char key[128]; |
100 | unsigned int j = 0; | 110 | unsigned int j = 0; |
101 | unsigned int keylength; | 111 | unsigned int keylength; |
102 | int val, count2; | 112 | int val, count2; |
103 | 113 | ||
104 | /* first we should check the permissions of the filename */ | 114 | /* first we should check the permissions of the filename */ |
105 | 115 | ||
106 | if (file_exists(filename)) { | 116 | if (file_exists(filename)) { |
107 | val = check_file(filename); | 117 | val = check_file(filename); |
108 | if (val != 1) { | 118 | if (val != 1) { |
109 | DBG("save_init, return %d", val); | 119 | DBG("save_init, return %d", val); |
110 | return val; | 120 | return val; |
111 | } | 121 | } |
112 | } else { | 122 | } else { |
113 | val = creat(filename, (S_IRUSR | S_IWUSR)); | 123 | val = creat(filename, (S_IRUSR | S_IWUSR)); |
114 | if (val == -1) { | 124 | if (val == -1) { |
115 | DBG("%s", "save_init, return 0"); | 125 | DBG("%s", "save_init, return 0"); |
116 | return 0; | 126 | return 0; |
117 | } else { | 127 | } else { |
118 | close(val); | 128 | close(val); |
119 | } | 129 | } |
120 | } | 130 | } |
121 | 131 | ||
122 | fd = fopen(filename, "wb"); | 132 | fd = fopen(filename, "wb"); |
123 | if (fd == NULL) { | 133 | if (fd == NULL) { |
124 | return 0; | 134 | return 0; |
125 | } | 135 | } |
126 | buffer = (char*)malloc(SAVE_BUFFER_LENGTH); | 136 | buffer = (char*)malloc(SAVE_BUFFER_LENGTH); |
127 | 137 | ||
128 | /* make the key ready */ | 138 | /* make the key ready */ |
129 | DBG("save_init, password=%s", password); | 139 | DBG("save_init, password=%s", password); |
130 | for (j = 0; password[j] != '\0'; j++) { | 140 | for (j = 0; password[j] != '\0'; j++) { |
131 | key[j] = password[j]; | 141 | key[j] = password[j]; |
132 | } | 142 | } |
133 | keylength = j; | 143 | keylength = j; |
134 | rc2.rc2_expandkey((char*)key, (int)keylength, 128); | 144 | rc2.rc2_expandkey((char*)key, (int)keylength, 128); |
135 | 145 | ||
136 | /* First, we make the IV */ | 146 | /* First, we make the IV */ |
137 | for (count2 = 0; count2 < 4; count2++) { | 147 | for (count2 = 0; count2 < 4; count2++) { |
138 | iv[count2] = rand(); | 148 | iv[count2] = rand(); |
139 | putc((unsigned char) (iv[count2] >> 8), fd); | 149 | putc((unsigned char) (iv[count2] >> 8), fd); |
140 | putc((unsigned char) (iv[count2] & 0xff), fd); | 150 | putc((unsigned char) (iv[count2] & 0xff), fd); |
141 | } | 151 | } |
142 | 152 | ||
143 | bufferIndex = 0; | 153 | bufferIndex = 0; |
144 | return 1; | 154 | return 1; |
145 | } | 155 | } |
146 | 156 | ||
147 | int GpasmanFile::save_entry(char *entry[4]) | 157 | int GpasmanFile::save_entry(char *entry[4]) |
148 | { | 158 | { |
149 | 159 | ||
150 | char *text1; | 160 | char *text1; |
151 | int count2, count3; | 161 | int count2, count3; |
152 | unsigned short ciphertext[4]; | 162 | unsigned short ciphertext[4]; |
153 | 163 | ||
154 | buffer = (char*)memset(buffer, '\0', SAVE_BUFFER_LENGTH); | 164 | buffer = (char*)memset(buffer, '\0', SAVE_BUFFER_LENGTH); |
155 | 165 | ||
156 | for (count2 = 0; count2 < 4; count2++) { | 166 | for (count2 = 0; count2 < 4; count2++) { |
157 | text1 = entry[count2]; | 167 | text1 = entry[count2]; |
158 | if (strlen(text1) == 0) { | 168 | if (strlen(text1) == 0) { |
159 | strncpy(text1, " ", strlen(" ")); | 169 | strncpy(text1, " ", strlen(" ")); |
160 | } | 170 | } |
161 | strncat(buffer, text1, strlen(text1)); | 171 | strncat(buffer, text1, strlen(text1)); |
162 | /* Use 255 as the marker. \n is too tough to test for */ | 172 | /* Use 255 as the marker. \n is too tough to test for */ |
163 | buffer[strlen(buffer)] = 255; | 173 | buffer[strlen(buffer)] = 255; |
164 | 174 | ||
165 | } /*for (count2 = 0; count2 < 4; count2++) */ | 175 | } /*for (count2 = 0; count2 < 4; count2++) */ |
166 | DBG("save_entry, buffer contains %s", buffer); | 176 | DBG("save_entry, buffer contains %s", buffer); |
167 | count2 = 0; | 177 | count2 = 0; |
168 | /* I'm using CBC mode and encrypting the data straight from top down. | 178 | /* I'm using CBC mode and encrypting the data straight from top down. |
169 | * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. | 179 | * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. |
170 | * PKCS 5 padding (explained at the code section | 180 | * PKCS 5 padding (explained at the code section |
171 | */ | 181 | */ |
172 | while (count2 < (int)strlen(buffer)) { | 182 | while (count2 < (int)strlen(buffer)) { |
173 | #ifndef WORDS_BIGENDIAN | 183 | #ifndef WORDS_BIGENDIAN |
174 | plaintext[bufferIndex] = buffer[count2 + 1] << 8; | 184 | plaintext[bufferIndex] = buffer[count2 + 1] << 8; |
175 | plaintext[bufferIndex] += buffer[count2] & 0xff; | 185 | plaintext[bufferIndex] += buffer[count2] & 0xff; |
176 | #else | 186 | #else |
177 | plaintext[bufferIndex] = buffer[count2] << 8; | 187 | plaintext[bufferIndex] = buffer[count2] << 8; |
178 | plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; | 188 | plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; |
179 | #endif | 189 | #endif |
180 | bufferIndex++; | 190 | bufferIndex++; |
181 | if (bufferIndex == 4) { | 191 | if (bufferIndex == 4) { |
182 | rc2.rc2_encrypt(plaintext); | 192 | rc2.rc2_encrypt(plaintext); |
183 | 193 | ||
184 | for (count3 = 0; count3 < 4; count3++) { | 194 | for (count3 = 0; count3 < 4; count3++) { |
185 | ciphertext[count3] = | 195 | ciphertext[count3] = |
186 | iv[count3] ^ plaintext[count3]; | 196 | iv[count3] ^ plaintext[count3]; |
187 | 197 | ||
188 | /* Now store the ciphertext as the iv */ | 198 | /* Now store the ciphertext as the iv */ |
189 | iv[count3] = plaintext[count3]; | 199 | iv[count3] = plaintext[count3]; |
190 | 200 | ||
191 | /* reset the buffer index */ | 201 | /* reset the buffer index */ |
192 | bufferIndex = 0; | 202 | bufferIndex = 0; |
193 | if (putc | 203 | if (putc |
194 | ((unsigned char) (ciphertext[count3] >> 8), | 204 | ((unsigned char) (ciphertext[count3] >> 8), |
195 | fd) == EOF) | 205 | fd) == EOF) |
196 | return -1; | 206 | return -1; |
197 | if (putc | 207 | if (putc |
198 | ((unsigned char) (ciphertext[count3] & | 208 | ((unsigned char) (ciphertext[count3] & |
199 | 0xff), fd) == EOF) | 209 | 0xff), fd) == EOF) |
200 | return -1; | 210 | return -1; |
201 | }/*for (count3 = 0; count3 < 4; count3++) */ | 211 | }/*for (count3 = 0; count3 < 4; count3++) */ |
202 | } | 212 | } |
203 | /*if (bufferIndex == 4) */ | 213 | /*if (bufferIndex == 4) */ |
204 | /* increment a short, not a byte */ | 214 | /* increment a short, not a byte */ |
205 | count2 += 2; | 215 | count2 += 2; |
206 | } /*while (count2 < strlen (buffer)) */ | 216 | } /*while (count2 < strlen (buffer)) */ |
207 | return 1; | 217 | return 1; |
208 | } | 218 | } |
209 | 219 | ||
210 | int GpasmanFile::save_finalize(void) | 220 | int GpasmanFile::save_finalize(void) |
211 | { | 221 | { |
212 | 222 | ||
213 | int count1, retval = 1; | 223 | int count1, retval = 1; |
214 | unsigned short ciphertext[4]; | 224 | unsigned short ciphertext[4]; |
215 | 225 | ||
216 | /* Tack on the PKCS 5 padding | 226 | /* Tack on the PKCS 5 padding |
217 | How it works is we fill up the last n bytes with the value n | 227 | How it works is we fill up the last n bytes with the value n |
218 | 228 | ||
219 | So, if we have, say, 13 bytes, 8 of which are used, we have 5 left | 229 | So, if we have, say, 13 bytes, 8 of which are used, we have 5 left |
220 | over, leaving us 3 short, so we fill it in with 3's. | 230 | over, leaving us 3 short, so we fill it in with 3's. |
221 | 231 | ||
222 | If we come out even, we fill it with 8 8s | 232 | If we come out even, we fill it with 8 8s |
223 | 233 | ||
224 | um, except that in this instance we are using 4 shorts instead of 8 bytes. | 234 | um, except that in this instance we are using 4 shorts instead of 8 bytes. |
225 | so, half everything | 235 | so, half everything |
226 | */ | 236 | */ |
227 | for (count1 = bufferIndex; count1 < 4; count1++) { | 237 | for (count1 = bufferIndex; count1 < 4; count1++) { |
228 | plaintext[count1] = (4 - bufferIndex); | 238 | plaintext[count1] = (4 - bufferIndex); |
229 | } | 239 | } |
230 | DBG("save_finalize, 4 - bufferIndex = %d", | 240 | DBG("save_finalize, 4 - bufferIndex = %d", |
231 | 4 - bufferIndex); | 241 | 4 - bufferIndex); |
232 | DBG("save_finalize, plaintext[3]=%c", plaintext[3]); | 242 | DBG("save_finalize, plaintext[3]=%c", plaintext[3]); |
233 | rc2.rc2_encrypt(plaintext); | 243 | rc2.rc2_encrypt(plaintext); |
234 | for (count1 = 0; count1 < 4; count1++) { | 244 | for (count1 = 0; count1 < 4; count1++) { |
235 | ciphertext[count1] = iv[count1] ^ plaintext[count1]; | 245 | ciphertext[count1] = iv[count1] ^ plaintext[count1]; |
236 | if (putc((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) | 246 | if (putc((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) |
237 | retval = -1; | 247 | retval = -1; |
238 | if (putc((unsigned char) (ciphertext[count1] & 0xff), fd) == | 248 | if (putc((unsigned char) (ciphertext[count1] & 0xff), fd) == |
239 | EOF) | 249 | EOF) |
240 | retval = -1; | 250 | retval = -1; |
241 | } | 251 | } |
242 | 252 | ||
243 | fclose(fd); | 253 | fclose(fd); |
244 | DBG("%s", "save_finalize, fd is closed"); | 254 | DBG("%s", "save_finalize, fd is closed"); |
245 | free(buffer); | 255 | free(buffer); |
246 | return retval; | 256 | return retval; |
247 | 257 | ||
248 | } | 258 | } |
249 | 259 | ||
250 | int GpasmanFile::load_init(const char *filename, const char *password) | 260 | int GpasmanFile::load_init(const char *filename, const char *password) |
251 | { | 261 | { |
252 | /* | 262 | /* |
253 | * returncodes: | 263 | * returncodes: |
254 | * 1 = success | 264 | * 1 = success |
255 | * 0 = can't open filedescriptor / can't create file | 265 | * 0 = can't open filedescriptor / can't create file |
256 | * -1 = permissions are bad | 266 | * -1 = permissions are bad |
257 | * -2 = is a symlink | 267 | * -2 = is a symlink |
258 | * -3 = can't get file status | 268 | * -3 = can't get file status |
259 | */ | 269 | */ |
260 | unsigned int j = 0; | 270 | unsigned int j = 0; |
261 | unsigned int keylength = 0; | 271 | unsigned int keylength = 0; |
262 | int count = 0, count2 = 0, count3 = 0; | 272 | int count = 0, count2 = 0, count3 = 0; |
263 | unsigned char charbuf[8]; | 273 | unsigned char charbuf[8]; |
264 | unsigned short ciphertext[4]; | 274 | unsigned short ciphertext[4]; |
265 | int val = 0; | 275 | int val = 0; |
266 | unsigned char key[128]; | 276 | unsigned char key[128]; |
267 | 277 | ||
268 | /* first we should check the file permissions */ | 278 | /* first we should check the file permissions */ |
269 | if (file_exists(filename)) { | 279 | if (file_exists(filename)) { |
270 | val = check_file(filename); | 280 | val = check_file(filename); |
271 | if (val != 1) { | 281 | if (val != 1) { |
272 | return val; | 282 | return val; |
273 | } | 283 | } |
274 | } else { | 284 | } else { |
275 | return 0; | 285 | return 0; |
276 | } | 286 | } |
277 | 287 | ||
278 | fd = fopen(filename, "rb"); | 288 | fd = fopen(filename, "rb"); |
279 | if (fd == NULL) { | 289 | if (fd == NULL) { |
280 | return 0; | 290 | return 0; |
281 | } | 291 | } |
282 | 292 | ||
283 | buffer = (char*)malloc(LOAD_BUFFER_LENGTH); | 293 | buffer = (char*)malloc(LOAD_BUFFER_LENGTH); |
284 | DBG("load_init, password=\"%s\"", password); | 294 | DBG("load_init, password=\"%s\"", password); |
285 | for (j = 0; password[j] != '\0'; j++) { | 295 | for (j = 0; password[j] != '\0'; j++) { |
286 | key[j] = password[j]; | 296 | key[j] = password[j]; |
287 | } | 297 | } |
288 | keylength = j; | 298 | keylength = j; |
289 | rc2.rc2_expandkey((char*)key, (int)keylength, 128); | 299 | rc2.rc2_expandkey((char*)key, (int)keylength, 128); |
290 | 300 | ||
291 | size = read(fileno(fd), (unsigned char *) (charbuf + count), 8); | 301 | size = read(fileno(fd), (unsigned char *) (charbuf + count), 8); |
292 | DBG("load_init, size=%d, keylength=%d", size, keylength); | 302 | DBG("load_init, size=%d, keylength=%d", size, keylength); |
293 | 303 | ||
294 | if (size < 8) { | 304 | if (size < 8) { |
295 | fclose(fd); | 305 | fclose(fd); |
296 | free(buffer); | 306 | free(buffer); |
297 | return -1; | 307 | return -1; |
298 | } | 308 | } |
299 | 309 | ||
300 | for (count = 0; count < 4; count++) { | 310 | for (count = 0; count < 4; count++) { |
301 | count2 = count << 1; | 311 | count2 = count << 1; |
302 | iv[count] = charbuf[count2] << 8; | 312 | iv[count] = charbuf[count2] << 8; |
303 | iv[count] += charbuf[count2 + 1]; | 313 | iv[count] += charbuf[count2 + 1]; |
304 | DBG("load_init iv[%d]=%d", count, iv[count]); | 314 | DBG("load_init iv[%d]=%d", count, iv[count]); |
305 | } | 315 | } |
306 | 316 | ||
307 | size = 0; | 317 | size = 0; |
308 | bufferIndex = 0; | 318 | bufferIndex = 0; |
309 | while ((count = read(fileno(fd), (unsigned char *) charbuf, 8)) > 0) { | 319 | while ((count = read(fileno(fd), (unsigned char *) charbuf, 8)) > 0) { |
310 | DBG("load_init A, count=%d, count2=%d", count, count2); | 320 | DBG("load_init A, count=%d, count2=%d", count, count2); |
311 | while (count < 8) { | 321 | while (count < 8) { |
312 | count2 = read(fileno(fd), (unsigned char *) (charbuf + | 322 | count2 = read(fileno(fd), (unsigned char *) (charbuf + |
313 | count), 8); | 323 | count), 8); |
314 | DBG("load_init B, count=%d, count2=%d", | 324 | DBG("load_init B, count=%d, count2=%d", |
315 | count, count2); | 325 | count, count2); |
316 | if (count2 == 0) { | 326 | if (count2 == 0) { |
317 | printf("bad EOF\n"); | 327 | printf("bad EOF\n"); |
318 | fclose(fd); | 328 | fclose(fd); |
319 | free(buffer); | 329 | free(buffer); |
320 | return -1; | 330 | return -1; |
321 | } | 331 | } |
322 | count += count2; | 332 | count += count2; |
323 | } /* while (count < 8) */ | 333 | } /* while (count < 8) */ |
324 | 334 | ||
325 | size += 8; | 335 | size += 8; |
326 | DBG("load_init charbuf[1]=%c", charbuf[1]); | 336 | DBG("load_init charbuf[1]=%c", charbuf[1]); |
327 | for (count2 = 0; count2 < 8; count2 += 2) { | 337 | for (count2 = 0; count2 < 8; count2 += 2) { |
328 | count3 = count2 >> 1; | 338 | count3 = count2 >> 1; |
329 | ciphertext[count3] = charbuf[count2] << 8; | 339 | ciphertext[count3] = charbuf[count2] << 8; |
330 | ciphertext[count3] += charbuf[count2 + 1]; | 340 | ciphertext[count3] += charbuf[count2 + 1]; |
331 | 341 | ||
332 | plaintext[count3] = ciphertext[count3] ^ iv[count3]; | 342 | plaintext[count3] = ciphertext[count3] ^ iv[count3]; |
333 | iv[count3] = plaintext[count3]; | 343 | iv[count3] = plaintext[count3]; |
334 | } | 344 | } |
335 | 345 | ||
336 | rc2.rc2_decrypt(plaintext); | 346 | rc2.rc2_decrypt(plaintext); |
337 | memcpy((unsigned char *) (buffer + bufferIndex), plaintext, 8); | 347 | memcpy((unsigned char *) (buffer + bufferIndex), plaintext, 8); |
338 | bufferIndex += 8; | 348 | bufferIndex += 8; |
339 | buffer[bufferIndex + 1] = '\0'; | 349 | buffer[bufferIndex + 1] = '\0'; |
340 | DBG("bufferIndex=%d, buffer=%s", bufferIndex, | 350 | DBG("bufferIndex=%d, buffer=%s", bufferIndex, |
341 | buffer); | 351 | buffer); |
342 | } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ | 352 | } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ |
343 | DBG("load_init, size=%d, buffer[size-1]=%d,", size, | 353 | DBG("load_init, size=%d, buffer[size-1]=%d,", size, |
344 | buffer[size - 1]); | 354 | buffer[size - 1]); |
345 | size -= buffer[size - 1]; | 355 | size -= buffer[size - 1]; |
346 | DBG("size=%d", size); | 356 | DBG("size=%d", size); |
347 | lastcount = 0; | 357 | lastcount = 0; |
348 | 358 | ||
349 | /* This will point to the starting index */ | 359 | /* This will point to the starting index */ |
350 | bufferIndex = 0; | 360 | bufferIndex = 0; |
351 | return 1; | 361 | return 1; |
352 | } | 362 | } |
353 | 363 | ||
354 | int GpasmanFile::load_entry(char *entry[4]) | 364 | int GpasmanFile::load_entry(char *entry[4]) |
355 | { | 365 | { |
356 | /* Strip off PKCS 5 padding | 366 | /* Strip off PKCS 5 padding |
357 | Should check to make sure it's good here | 367 | Should check to make sure it's good here |
358 | */ | 368 | */ |
359 | int count, count1 = 0; | 369 | int count, count1 = 0; |
360 | DBG("load_entry, lastcount=%d, size=%d, entry=%p", | 370 | DBG("load_entry, lastcount=%d, size=%d, entry=%p", |
361 | lastcount, size, entry); | 371 | lastcount, size, entry); |
362 | 372 | ||
363 | for (count = lastcount; count < size; count++) { | 373 | for (count = lastcount; count < size; count++) { |
364 | if ((unsigned char) (buffer[count]) == 255) { | 374 | if ((unsigned char) (buffer[count]) == 255) { |
365 | if (buffer[bufferIndex] == '\0') { | 375 | if (buffer[bufferIndex] == '\0') { |
366 | bufferIndex++; | 376 | bufferIndex++; |
367 | } | 377 | } |
368 | entry[count1] = | 378 | entry[count1] = |
369 | (char *) malloc(count - bufferIndex + 1); | 379 | (char *) malloc(count - bufferIndex + 1); |
370 | DBG("load_entry, entry[%d]=%p", count1, | 380 | DBG("load_entry, entry[%d]=%p", count1, |
371 | entry[count1]); | 381 | entry[count1]); |
372 | memcpy(entry[count1], | 382 | memcpy(entry[count1], |
373 | (unsigned char *) (buffer + bufferIndex), | 383 | (unsigned char *) (buffer + bufferIndex), |
374 | count - bufferIndex); | 384 | count - bufferIndex); |
375 | entry[count1][count - bufferIndex] = '\0'; | 385 | entry[count1][count - bufferIndex] = '\0'; |
376 | DBG("load_entry, entry[%d]=%s", count1, | 386 | DBG("load_entry, entry[%d]=%s", count1, |
377 | entry[count1]); | 387 | entry[count1]); |
378 | count++; | 388 | count++; |
379 | bufferIndex = count; | 389 | bufferIndex = count; |
380 | count1++; | 390 | count1++; |
381 | if (count1 == 4) { | 391 | if (count1 == 4) { |
382 | lastcount = count; | 392 | lastcount = count; |
383 | DBG("%s", "load_entry, return 1, entry ready"); | 393 | DBG("%s", "load_entry, return 1, entry ready"); |
384 | return 1; | 394 | return 1; |
385 | } | 395 | } |
386 | } /* if ((unsigned char) (buffer[count]) == 255) */ | 396 | } /* if ((unsigned char) (buffer[count]) == 255) */ |
387 | } /* for (count = 0; count < size; count++) */ | 397 | } /* for (count = 0; count < size; count++) */ |
388 | 398 | ||
389 | DBG("%s", "load_entry, ended no entry anymore"); | 399 | DBG("%s", "load_entry, ended no entry anymore"); |
390 | return 2; | 400 | return 2; |
391 | } | 401 | } |
392 | 402 | ||
393 | void GpasmanFile::load_finalize(void) | 403 | void GpasmanFile::load_finalize(void) |
394 | { | 404 | { |
395 | fclose(fd); | 405 | fclose(fd); |
396 | free(buffer); | 406 | free(buffer); |
397 | } | 407 | } |
398 | 408 | ||
399 | int GpasmanFile::check_file(const char *filename) | 409 | int GpasmanFile::check_file(const char *filename) |
400 | { | 410 | { |
401 | struct stat naamstat; | 411 | struct stat naamstat; |
402 | 412 | ||
403 | if (stat(filename, &naamstat) == -1) { | 413 | if (stat(filename, &naamstat) == -1) { |
404 | return (-3); | 414 | return (-3); |
405 | } | 415 | } |
406 | 416 | ||
407 | if (((naamstat.st_mode & S_IAMB) | (S_IRUSR | S_IWUSR)) != (S_IRUSR | | 417 | if (((naamstat.st_mode & S_IAMB) | (S_IRUSR | S_IWUSR)) != (S_IRUSR | |
408 | S_IWUSR)) { | 418 | S_IWUSR)) { |
409 | DBG("%s perms are bad, they are: %ld, should be -rw------", | 419 | DBG("%s perms are bad, they are: %ld, should be -rw------", |
410 | filename, (naamstat.st_mode & (S_IREAD | S_IWRITE))); | 420 | filename, (naamstat.st_mode & (S_IREAD | S_IWRITE))); |
411 | return (-1); | 421 | return (-1); |
412 | } | 422 | } |
413 | 423 | #ifndef _WIN32_ | |
414 | if (!S_ISREG(naamstat.st_mode)) { | 424 | if (!S_ISREG(naamstat.st_mode)) { |
415 | lstat(filename, &naamstat); | 425 | lstat(filename, &naamstat); |
416 | if (S_ISLNK(naamstat.st_mode)) { | 426 | if (S_ISLNK(naamstat.st_mode)) { |
417 | DBG("%s is a symlink", filename); | 427 | DBG("%s is a symlink", filename); |
418 | return (-2); | 428 | return (-2); |
419 | } | 429 | } |
420 | } | 430 | } |
421 | 431 | #endif | |
422 | return (1); | 432 | return (1); |
423 | } | 433 | } |
424 | 434 | ||
425 | int GpasmanFile::file_exists(const char *tfile) | 435 | int GpasmanFile::file_exists(const char *tfile) |
426 | { | 436 | { |
427 | struct stat naamstat; | 437 | struct stat naamstat; |
428 | 438 | ||
429 | if ((stat(tfile, &naamstat) == -1) && (errno == ENOENT)) { | 439 | if ((stat(tfile, &naamstat) == -1) && (errno == ENOENT)) { |
430 | DBG("file_exists, %s does NOT exist", tfile); | 440 | DBG("file_exists, %s does NOT exist", tfile); |
431 | return (0); | 441 | return (0); |
432 | } else { | 442 | } else { |
433 | DBG("file_exists, %s DOES exist", tfile); | 443 | DBG("file_exists, %s DOES exist", tfile); |
434 | return (1); | 444 | return (1); |
435 | } | 445 | } |
436 | } | 446 | } |
437 | 447 | ||
diff --git a/pwmanager/pwmanager/htmlgen.cpp b/pwmanager/pwmanager/htmlgen.cpp index 166b987..bee8198 100644 --- a/pwmanager/pwmanager/htmlgen.cpp +++ b/pwmanager/pwmanager/htmlgen.cpp | |||
@@ -1,248 +1,248 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "htmlgen.h" | 20 | #include "htmlgen.h" |
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | 22 | ||
23 | #include <kstandarddirs.h> | 23 | #include <kstandarddirs.h> |
24 | 24 | ||
25 | /** enable/disable HTML-generator debugging (0/1) */ | 25 | /** enable/disable HTML-generator debugging (0/1) */ |
26 | #define HTMLGEN_DEBUG0 | 26 | #define HTMLGEN_DEBUG0 |
27 | 27 | ||
28 | 28 | ||
29 | #define HTML_DOCTYPE_HDR"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" | 29 | #define HTML_DOCTYPE_HDR"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" |
30 | #define HTML_PWM_HDR "<!-- PwManager generated HTML -->" | 30 | #define HTML_PWM_HDR "<!-- PwManager generated HTML -->" |
31 | #define HTML_COMMENT_HDR"<!-- type: comment -->" | 31 | #define HTML_COMMENT_HDR"<!-- type: comment -->" |
32 | #define HTML_COMMENTVER_HDR"<!-- ver: 0.1 -->" | 32 | #define HTML_COMMENTVER_HDR"<!-- ver: 0.1 -->" |
33 | #define HTML_STYLESHEET_DUMMY"@STYLESHEET@" | 33 | #define HTML_STYLESHEET_DUMMY"@STYLESHEET@" |
34 | #define HTML_GLOBTBL_CLASS"\"globtable\"" | 34 | #define HTML_GLOBTBL_CLASS"\"globtable\"" |
35 | #define HTML_GLOBTITLE_CLASS"\"globtitle\"" | 35 | #define HTML_GLOBTITLE_CLASS"\"globtitle\"" |
36 | #define HTML_SUBTBL_CLASS"\"subtable\"" | 36 | #define HTML_SUBTBL_CLASS"\"subtable\"" |
37 | #define HTML_SUBTITLE_CLASS"\"subtitle\"" | 37 | #define HTML_SUBTITLE_CLASS"\"subtitle\"" |
38 | #define HTML_ENTRY_CLASS"\"entry\"" | 38 | #define HTML_ENTRY_CLASS"\"entry\"" |
39 | #define HTML_VALUE_CLASS"\"value\"" | 39 | #define HTML_VALUE_CLASS"\"value\"" |
40 | #define PATH_COMMENTSTYLE_CSS"pwmanager/html/htmlcomment_style.css" | 40 | #define PATH_COMMENTSTYLE_CSS"pwmanager/html/htmlcomment_style.css" |
41 | #if defined(PWM_DEBUG) && HTMLGEN_DEBUG != 0 | 41 | #if defined(PWM_DEBUG) && HTMLGEN_DEBUG != 0 |
42 | #define HTML_ENDL "\n" | 42 | #define HTML_ENDL "\n" |
43 | #else // defined(PWM_DEBUG) && ... | 43 | #else // defined(PWM_DEBUG) && ... |
44 | #define HTML_ENDL "" | 44 | #define HTML_ENDL "" |
45 | #endif // defined(PWM_DEBUG) && ... | 45 | #endif // defined(PWM_DEBUG) && ... |
46 | 46 | ||
47 | 47 | ||
48 | HtmlGen::HtmlGen() | 48 | HtmlGen::HtmlGen() |
49 | { | 49 | { |
50 | useSSDummy = true; | 50 | useSSDummy = true; |
51 | } | 51 | } |
52 | 52 | ||
53 | HtmlGen::~HtmlGen() | 53 | HtmlGen::~HtmlGen() |
54 | { | 54 | { |
55 | } | 55 | } |
56 | 56 | ||
57 | QString HtmlGen::escapeHtmlText(const QString &str) | 57 | QString HtmlGen::escapeHtmlText(const QString &str) |
58 | { | 58 | { |
59 | QString ret; | 59 | QString ret; |
60 | unsigned int len = str.length(), i; | 60 | unsigned int len = str.length(), i; |
61 | char c; | 61 | char c; |
62 | for (i = 0; i < len; ++i) { | 62 | for (i = 0; i < len; ++i) { |
63 | c = str[i]; | 63 | c = str.at(i); |
64 | switch (c) { | 64 | switch (c) { |
65 | case '<': | 65 | case '<': |
66 | ret.append("<"); | 66 | ret.append("<"); |
67 | break; | 67 | break; |
68 | case '>': | 68 | case '>': |
69 | ret.append(">"); | 69 | ret.append(">"); |
70 | break; | 70 | break; |
71 | case '&': | 71 | case '&': |
72 | ret.append("&"); | 72 | ret.append("&"); |
73 | break; | 73 | break; |
74 | case '\"': | 74 | case '\"': |
75 | ret.append("""); | 75 | ret.append("""); |
76 | break; | 76 | break; |
77 | case 'ä': | 77 | case 'ä': |
78 | ret.append("ä"); | 78 | ret.append("ä"); |
79 | break; | 79 | break; |
80 | case 'Ä': | 80 | case 'Ä': |
81 | ret.append("Ä"); | 81 | ret.append("Ä"); |
82 | break; | 82 | break; |
83 | case 'ü': | 83 | case 'ü': |
84 | ret.append("ü"); | 84 | ret.append("ü"); |
85 | break; | 85 | break; |
86 | case 'Ü': | 86 | case 'Ü': |
87 | ret.append("Ü"); | 87 | ret.append("Ü"); |
88 | break; | 88 | break; |
89 | case 'ö': | 89 | case 'ö': |
90 | ret.append("ö"); | 90 | ret.append("ö"); |
91 | break; | 91 | break; |
92 | case 'Ö': | 92 | case 'Ö': |
93 | ret.append("Ö"); | 93 | ret.append("Ö"); |
94 | break; | 94 | break; |
95 | case 'ß': | 95 | case 'ß': |
96 | ret.append("ß"); | 96 | ret.append("ß"); |
97 | break; | 97 | break; |
98 | case '¿': | 98 | case '¿': |
99 | ret.append("€"); | 99 | ret.append("€"); |
100 | break; | 100 | break; |
101 | default: | 101 | default: |
102 | ret.append(c); | 102 | ret.append(c); |
103 | } | 103 | } |
104 | } | 104 | } |
105 | return ret; | 105 | return ret; |
106 | } | 106 | } |
107 | 107 | ||
108 | bool HtmlGen::isHtml(const QString &dta) | 108 | bool HtmlGen::isHtml(const QString &dta) |
109 | { | 109 | { |
110 | int ret; | 110 | int ret; |
111 | ret = dta.find("<html>", 0, false); | 111 | ret = dta.find("<html>", 0, false); |
112 | if (ret == -1) | 112 | if (ret == -1) |
113 | return false; | 113 | return false; |
114 | ret = dta.find("<head>", ret, false); | 114 | ret = dta.find("<head>", ret, false); |
115 | if (ret == -1) | 115 | if (ret == -1) |
116 | return false; | 116 | return false; |
117 | return true; | 117 | return true; |
118 | } | 118 | } |
119 | 119 | ||
120 | QString HtmlGen::getStyleSheetHtml() | 120 | QString HtmlGen::getStyleSheetHtml() |
121 | { | 121 | { |
122 | QString ret; | 122 | QString ret; |
123 | ret = "<link rel=\"stylesheet\" href=\""; | 123 | ret = "<link rel=\"stylesheet\" href=\""; |
124 | QString cssPath(::locate("data", PATH_COMMENTSTYLE_CSS)); | 124 | QString cssPath(::locate("data", PATH_COMMENTSTYLE_CSS)); |
125 | if ((cssPath == QString::null) || (cssPath == "")) { | 125 | if ((cssPath == QString::null) || (cssPath == "")) { |
126 | printDebug("HtmlGen::getStyleSheetHtml(): not found"); | 126 | printDebug("HtmlGen::getStyleSheetHtml(): not found"); |
127 | return ""; | 127 | return ""; |
128 | } | 128 | } |
129 | ret += cssPath; | 129 | ret += cssPath; |
130 | ret += "\" type=\"text/css\">" HTML_ENDL; | 130 | ret += "\" type=\"text/css\">" HTML_ENDL; |
131 | return ret; | 131 | return ret; |
132 | } | 132 | } |
133 | 133 | ||
134 | bool HtmlGen::replaceSSDummy(QString *doc) | 134 | bool HtmlGen::replaceSSDummy(QString *doc) |
135 | { | 135 | { |
136 | int beginPos = doc->find(HTML_STYLESHEET_DUMMY); | 136 | int beginPos = doc->find(HTML_STYLESHEET_DUMMY); |
137 | if (beginPos == -1) { | 137 | if (beginPos == -1) { |
138 | printDebug("HtmlGen::replaceSSDummy(): not found"); | 138 | printDebug("HtmlGen::replaceSSDummy(): not found"); |
139 | return false; | 139 | return false; |
140 | } | 140 | } |
141 | *doc = doc->replace(beginPos, strlen(HTML_STYLESHEET_DUMMY), | 141 | *doc = doc->replace(beginPos, strlen(HTML_STYLESHEET_DUMMY), |
142 | getStyleSheetHtml()); | 142 | getStyleSheetHtml()); |
143 | return true; | 143 | return true; |
144 | } | 144 | } |
145 | 145 | ||
146 | QString HtmlGen::genHtmlComment(const HtmlComment *dta) | 146 | QString HtmlGen::genHtmlComment(const HtmlComment *dta) |
147 | { | 147 | { |
148 | QString ret(HTML_DOCTYPE_HDR | 148 | QString ret(HTML_DOCTYPE_HDR |
149 | HTML_PWM_HDRHTML_ENDL | 149 | HTML_PWM_HDRHTML_ENDL |
150 | HTML_COMMENT_HDRHTML_ENDL | 150 | HTML_COMMENT_HDRHTML_ENDL |
151 | HTML_COMMENTVER_HDRHTML_ENDL); | 151 | HTML_COMMENTVER_HDRHTML_ENDL); |
152 | ret += "<html>" HTML_ENDL; | 152 | ret += "<html>" HTML_ENDL; |
153 | if (!appendCommentHeader(&ret)) | 153 | if (!appendCommentHeader(&ret)) |
154 | return ""; | 154 | return ""; |
155 | if (!appendCommentBody(&ret, dta)) | 155 | if (!appendCommentBody(&ret, dta)) |
156 | return ""; | 156 | return ""; |
157 | ret += "</html>" HTML_ENDL; | 157 | ret += "</html>" HTML_ENDL; |
158 | 158 | ||
159 | #if defined(PWM_DEBUG) && HTMLGEN_DEBUG != 0 | 159 | #if defined(PWM_DEBUG) && HTMLGEN_DEBUG != 0 |
160 | printDebug("<BEGIN HtmlGen::genHtmlComment() dump>"); | 160 | printDebug("<BEGIN HtmlGen::genHtmlComment() dump>"); |
161 | cout << ret << endl; | 161 | cout << ret << endl; |
162 | printDebug("<END HtmlGen::genHtmlComment() dump>"); | 162 | printDebug("<END HtmlGen::genHtmlComment() dump>"); |
163 | #endif // DEBUG | 163 | #endif // DEBUG |
164 | return ret; | 164 | return ret; |
165 | } | 165 | } |
166 | 166 | ||
167 | bool HtmlGen::appendCommentHeader(QString *str) | 167 | bool HtmlGen::appendCommentHeader(QString *str) |
168 | { | 168 | { |
169 | *str += "<head>" HTML_ENDL; | 169 | *str += "<head>" HTML_ENDL; |
170 | if (useSSDummy) { | 170 | if (useSSDummy) { |
171 | *str += HTML_STYLESHEET_DUMMYHTML_ENDL; | 171 | *str += HTML_STYLESHEET_DUMMYHTML_ENDL; |
172 | } else { | 172 | } else { |
173 | QString ssLine(getStyleSheetHtml()); | 173 | QString ssLine(getStyleSheetHtml()); |
174 | if (ssLine.isEmpty()) | 174 | if (ssLine.isEmpty()) |
175 | return false; | 175 | return false; |
176 | *str += ssLine; | 176 | *str += ssLine; |
177 | } | 177 | } |
178 | *str += "</head>" HTML_ENDL; | 178 | *str += "</head>" HTML_ENDL; |
179 | return true; | 179 | return true; |
180 | } | 180 | } |
181 | 181 | ||
182 | bool HtmlGen::appendCommentBody(QString *str, | 182 | bool HtmlGen::appendCommentBody(QString *str, |
183 | const HtmlComment *dta) | 183 | const HtmlComment *dta) |
184 | { | 184 | { |
185 | *str += "<body>" HTML_ENDL; | 185 | *str += "<body>" HTML_ENDL; |
186 | if (!appendCommentGlobTbl(str, dta)) | 186 | if (!appendCommentGlobTbl(str, dta)) |
187 | return false; | 187 | return false; |
188 | *str += "</body>" HTML_ENDL; | 188 | *str += "</body>" HTML_ENDL; |
189 | return true; | 189 | return true; |
190 | } | 190 | } |
191 | 191 | ||
192 | bool HtmlGen::appendCommentGlobTbl(QString *str, | 192 | bool HtmlGen::appendCommentGlobTbl(QString *str, |
193 | const HtmlComment *dta) | 193 | const HtmlComment *dta) |
194 | { | 194 | { |
195 | *str += "<table class=" HTML_GLOBTBL_CLASS ">" HTML_ENDL; | 195 | *str += "<table class=" HTML_GLOBTBL_CLASS ">" HTML_ENDL; |
196 | *str += "<tr><th class=" HTML_GLOBTITLE_CLASS ">"; | 196 | *str += "<tr><th class=" HTML_GLOBTITLE_CLASS ">"; |
197 | *str += escapeHtmlText(dta->getTitle()); | 197 | *str += escapeHtmlText(dta->getTitle()); |
198 | *str += "</th></tr>" HTML_ENDL; | 198 | *str += "</th></tr>" HTML_ENDL; |
199 | 199 | ||
200 | const vector<HtmlComment::SubTable> *subTbls = dta->getSubTableList(); | 200 | const vector<HtmlComment::SubTable> *subTbls = dta->getSubTableList(); |
201 | vector<HtmlComment::SubTable>::const_iterator i = subTbls->begin(), | 201 | vector<HtmlComment::SubTable>::const_iterator i = subTbls->begin(), |
202 | end = subTbls->end(); | 202 | end = subTbls->end(); |
203 | while (i != end) { | 203 | while (i != end) { |
204 | *str += "<tr><td>" HTML_ENDL; | 204 | *str += "<tr><td>" HTML_ENDL; |
205 | if (!appendCommentSubTbl(str, &(*i))) | 205 | if (!appendCommentSubTbl(str, &(*i))) |
206 | return false; | 206 | return false; |
207 | ++i; | 207 | ++i; |
208 | *str += "</td></tr>" HTML_ENDL; | 208 | *str += "</td></tr>" HTML_ENDL; |
209 | } | 209 | } |
210 | 210 | ||
211 | *str += "</table>" HTML_ENDL; | 211 | *str += "</table>" HTML_ENDL; |
212 | return true; | 212 | return true; |
213 | } | 213 | } |
214 | 214 | ||
215 | bool HtmlGen::appendCommentSubTbl(QString *str, | 215 | bool HtmlGen::appendCommentSubTbl(QString *str, |
216 | const HtmlComment::SubTable *dta) | 216 | const HtmlComment::SubTable *dta) |
217 | { | 217 | { |
218 | *str += "<table class=" HTML_SUBTBL_CLASS ">" HTML_ENDL; | 218 | *str += "<table class=" HTML_SUBTBL_CLASS ">" HTML_ENDL; |
219 | *str += "<tr><th colspan=\"2\" class=" HTML_SUBTITLE_CLASS ">"; | 219 | *str += "<tr><th colspan=\"2\" class=" HTML_SUBTITLE_CLASS ">"; |
220 | *str += escapeHtmlText(dta->getTitle()); | 220 | *str += escapeHtmlText(dta->getTitle()); |
221 | *str += "</th></tr>" HTML_ENDL; | 221 | *str += "</th></tr>" HTML_ENDL; |
222 | 222 | ||
223 | const vector< pair<QString, QString> > *entries = dta->getEntryList(); | 223 | const vector< pair<QString, QString> > *entries = dta->getEntryList(); |
224 | vector< pair<QString, QString> >::const_iterator i = entries->begin(), | 224 | vector< pair<QString, QString> >::const_iterator i = entries->begin(), |
225 | end = entries->end(); | 225 | end = entries->end(); |
226 | while (i != end) { | 226 | while (i != end) { |
227 | *str += "<tr>" HTML_ENDL; | 227 | *str += "<tr>" HTML_ENDL; |
228 | if (!appendCommentSubTblEntry(str, &(*i))) | 228 | if (!appendCommentSubTblEntry(str, &(*i))) |
229 | return false; | 229 | return false; |
230 | *str += "</tr>" HTML_ENDL; | 230 | *str += "</tr>" HTML_ENDL; |
231 | ++i; | 231 | ++i; |
232 | } | 232 | } |
233 | 233 | ||
234 | *str += "</table>" HTML_ENDL; | 234 | *str += "</table>" HTML_ENDL; |
235 | return true; | 235 | return true; |
236 | } | 236 | } |
237 | 237 | ||
238 | bool HtmlGen::appendCommentSubTblEntry(QString *str, | 238 | bool HtmlGen::appendCommentSubTblEntry(QString *str, |
239 | const pair<QString, QString> *dta) | 239 | const pair<QString, QString> *dta) |
240 | { | 240 | { |
241 | *str += "<td class=" HTML_ENTRY_CLASS ">"; | 241 | *str += "<td class=" HTML_ENTRY_CLASS ">"; |
242 | *str += escapeHtmlText(dta->first); | 242 | *str += escapeHtmlText(dta->first); |
243 | *str += "</td>" HTML_ENDL; | 243 | *str += "</td>" HTML_ENDL; |
244 | *str += "<td class=" HTML_VALUE_CLASS ">"; | 244 | *str += "<td class=" HTML_VALUE_CLASS ">"; |
245 | *str += escapeHtmlText(dta->second); | 245 | *str += escapeHtmlText(dta->second); |
246 | *str += "</td>" HTML_ENDL; | 246 | *str += "</td>" HTML_ENDL; |
247 | return true; | 247 | return true; |
248 | } | 248 | } |
diff --git a/pwmanager/pwmanager/ipc.cpp b/pwmanager/pwmanager/ipc.cpp index b1d2c68..643b022 100644 --- a/pwmanager/pwmanager/ipc.cpp +++ b/pwmanager/pwmanager/ipc.cpp | |||
@@ -1,216 +1,217 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "ipc.h" | 20 | #include "ipc.h" |
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | 22 | ||
23 | #include <qsocketnotifier.h> | 23 | #include <qsocketnotifier.h> |
24 | 24 | #ifndef _WIN32_ | |
25 | #include <sys/socket.h> | 25 | #include <sys/socket.h> |
26 | 26 | #endif | |
27 | #ifndef PWM_EMBEDDED | 27 | #ifndef PWM_EMBEDDED |
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | #else | 30 | #else |
31 | #include <qsocket.h> | 31 | #include <qsocket.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #define END_OF_LINE '\n' | 34 | #define END_OF_LINE '\n' |
35 | #define INIT_LINEBUF_LEN64 /* byte */ | 35 | #define INIT_LINEBUF_LEN64 /* byte */ |
36 | 36 | ||
37 | #ifndef PWM_EMBEDDED | 37 | #ifndef PWM_EMBEDDED |
38 | 38 | ||
39 | Ipc::Ipc() | 39 | Ipc::Ipc() |
40 | : stream (0) | 40 | : stream (0) |
41 | , notifier (0) | 41 | , notifier (0) |
42 | , rdBuf (0) | 42 | , rdBuf (0) |
43 | { | 43 | { |
44 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { | 44 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { |
45 | throw PwMException(PwMException::EX_GENERIC, | 45 | throw PwMException(PwMException::EX_GENERIC, |
46 | "Ipc: socketpair() failed"); | 46 | "Ipc: socketpair() failed"); |
47 | } | 47 | } |
48 | rdBufSize = INIT_LINEBUF_LEN; | 48 | rdBufSize = INIT_LINEBUF_LEN; |
49 | rdBuf = static_cast<char *>(malloc(rdBufSize)); | 49 | rdBuf = static_cast<char *>(malloc(rdBufSize)); |
50 | if (!rdBuf) { | 50 | if (!rdBuf) { |
51 | close(sock[0]); | 51 | close(sock[0]); |
52 | close(sock[1]); | 52 | close(sock[1]); |
53 | throw PwMException(PwMException::EX_GENERIC, | 53 | throw PwMException(PwMException::EX_GENERIC, |
54 | "Ipc: OOM"); | 54 | "Ipc: OOM"); |
55 | } | 55 | } |
56 | stream = fdopen(sock[0], "r"); | 56 | stream = fdopen(sock[0], "r"); |
57 | if (!stream) { | 57 | if (!stream) { |
58 | close(sock[0]); | 58 | close(sock[0]); |
59 | close(sock[1]); | 59 | close(sock[1]); |
60 | free(rdBuf); | 60 | free(rdBuf); |
61 | throw PwMException(PwMException::EX_GENERIC, | 61 | throw PwMException(PwMException::EX_GENERIC, |
62 | "Ipc: fdopen() failed"); | 62 | "Ipc: fdopen() failed"); |
63 | } | 63 | } |
64 | 64 | ||
65 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); | 65 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); |
66 | connect(notifier, SIGNAL(activated(int)), | 66 | connect(notifier, SIGNAL(activated(int)), |
67 | this, SLOT(receiveData(int))); | 67 | this, SLOT(receiveData(int))); |
68 | host = true; | 68 | host = true; |
69 | } | 69 | } |
70 | #else | 70 | #else |
71 | Ipc::Ipc() | 71 | Ipc::Ipc() |
72 | : notifier (0) | 72 | : notifier (0) |
73 | , rdBuf (0) | 73 | , rdBuf (0) |
74 | { | 74 | { |
75 | #ifndef _WIN32_ | ||
75 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { | 76 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { |
76 | qDebug("Ipc: socketpair() failed"); | 77 | qDebug("Ipc: socketpair() failed"); |
77 | } | 78 | } |
78 | 79 | #endif | |
79 | QSocket* qsock = new QSocket(); | 80 | QSocket* qsock = new QSocket(); |
80 | qsock->setSocket(sock[0]); | 81 | qsock->setSocket(sock[0]); |
81 | 82 | ||
82 | rdBufSize = INIT_LINEBUF_LEN; | 83 | rdBufSize = INIT_LINEBUF_LEN; |
83 | rdBuf = (char *)(malloc(rdBufSize)); | 84 | rdBuf = (char *)(malloc(rdBufSize)); |
84 | if (!rdBuf) { | 85 | if (!rdBuf) { |
85 | close(sock[0]); | 86 | close(sock[0]); |
86 | close(sock[1]); | 87 | close(sock[1]); |
87 | qDebug("Ipc: OOM"); | 88 | qDebug("Ipc: OOM"); |
88 | } | 89 | } |
89 | 90 | ||
90 | qsock = new QSocket(); | 91 | qsock = new QSocket(); |
91 | qsock->setSocket(sock[0]); | 92 | qsock->setSocket(sock[0]); |
92 | 93 | ||
93 | /*US | 94 | /*US |
94 | stream = fdopen(sock[0], "r"); | 95 | stream = fdopen(sock[0], "r"); |
95 | if (!stream) { | 96 | if (!stream) { |
96 | close(sock[0]); | 97 | close(sock[0]); |
97 | close(sock[1]); | 98 | close(sock[1]); |
98 | free(rdBuf); | 99 | free(rdBuf); |
99 | qDebug("Ipc: fdopen() failed"); | 100 | qDebug("Ipc: fdopen() failed"); |
100 | } | 101 | } |
101 | */ | 102 | */ |
102 | 103 | ||
103 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); | 104 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); |
104 | connect(notifier, SIGNAL(activated(int)), | 105 | connect(notifier, SIGNAL(activated(int)), |
105 | this, SLOT(receiveData(int))); | 106 | this, SLOT(receiveData(int))); |
106 | host = true; | 107 | host = true; |
107 | } | 108 | } |
108 | 109 | ||
109 | #endif | 110 | #endif |
110 | 111 | ||
111 | 112 | ||
112 | #ifndef PWM_EMBEDDED | 113 | #ifndef PWM_EMBEDDED |
113 | 114 | ||
114 | Ipc::Ipc(const Ipc *ipc) | 115 | Ipc::Ipc(const Ipc *ipc) |
115 | : stream (0) | 116 | : stream (0) |
116 | , notifier (0) | 117 | , notifier (0) |
117 | , rdBuf (0) | 118 | , rdBuf (0) |
118 | { | 119 | { |
119 | rdBufSize = INIT_LINEBUF_LEN; | 120 | rdBufSize = INIT_LINEBUF_LEN; |
120 | rdBuf = static_cast<char *>(malloc(rdBufSize)); | 121 | rdBuf = static_cast<char *>(malloc(rdBufSize)); |
121 | if (!rdBuf) { | 122 | if (!rdBuf) { |
122 | throw PwMException(PwMException::EX_GENERIC, | 123 | throw PwMException(PwMException::EX_GENERIC, |
123 | "Ipc: OOM"); | 124 | "Ipc: OOM"); |
124 | } | 125 | } |
125 | sock[0] = ipc->sock[1]; | 126 | sock[0] = ipc->sock[1]; |
126 | sock[1] = ipc->sock[0]; | 127 | sock[1] = ipc->sock[0]; |
127 | stream = fdopen(sock[0], "r"); | 128 | stream = fdopen(sock[0], "r"); |
128 | if (!stream) { | 129 | if (!stream) { |
129 | free(rdBuf); | 130 | free(rdBuf); |
130 | throw PwMException(PwMException::EX_GENERIC, | 131 | throw PwMException(PwMException::EX_GENERIC, |
131 | "Ipc: fdopen() failed"); | 132 | "Ipc: fdopen() failed"); |
132 | } | 133 | } |
133 | 134 | ||
134 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); | 135 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); |
135 | connect(notifier, SIGNAL(activated(int)), | 136 | connect(notifier, SIGNAL(activated(int)), |
136 | this, SLOT(receiveData(int))); | 137 | this, SLOT(receiveData(int))); |
137 | host = false; | 138 | host = false; |
138 | } | 139 | } |
139 | 140 | ||
140 | #else | 141 | #else |
141 | 142 | ||
142 | Ipc::Ipc(const Ipc *ipc) | 143 | Ipc::Ipc(const Ipc *ipc) |
143 | : notifier (0) | 144 | : notifier (0) |
144 | , rdBuf (0) | 145 | , rdBuf (0) |
145 | { | 146 | { |
146 | rdBufSize = INIT_LINEBUF_LEN; | 147 | rdBufSize = INIT_LINEBUF_LEN; |
147 | rdBuf = (char *)(malloc(rdBufSize)); | 148 | rdBuf = (char *)(malloc(rdBufSize)); |
148 | if (!rdBuf) { | 149 | if (!rdBuf) { |
149 | qDebug("Ipc: OOM"); | 150 | qDebug("Ipc: OOM"); |
150 | } | 151 | } |
151 | sock[0] = ipc->sock[1]; | 152 | sock[0] = ipc->sock[1]; |
152 | sock[1] = ipc->sock[0]; | 153 | sock[1] = ipc->sock[0]; |
153 | 154 | ||
154 | qSock = new QSocket(); | 155 | qSock = new QSocket(); |
155 | qSock->setSocket(sock[0]); | 156 | qSock->setSocket(sock[0]); |
156 | 157 | ||
157 | /*US | 158 | /*US |
158 | stream = fdopen(sock[0], "r"); | 159 | stream = fdopen(sock[0], "r"); |
159 | if (!stream) { | 160 | if (!stream) { |
160 | free(rdBuf); | 161 | free(rdBuf); |
161 | qDebug("Ipc: fdopen() failed"); | 162 | qDebug("Ipc: fdopen() failed"); |
162 | } | 163 | } |
163 | */ | 164 | */ |
164 | 165 | ||
165 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); | 166 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); |
166 | connect(notifier, SIGNAL(activated(int)), | 167 | connect(notifier, SIGNAL(activated(int)), |
167 | this, SLOT(receiveData(int))); | 168 | this, SLOT(receiveData(int))); |
168 | host = false; | 169 | host = false; |
169 | } | 170 | } |
170 | 171 | ||
171 | #endif | 172 | #endif |
172 | 173 | ||
173 | Ipc::~Ipc() | 174 | Ipc::~Ipc() |
174 | { | 175 | { |
175 | #ifdef PWM_EMBEDDED | 176 | #ifdef PWM_EMBEDDED |
176 | delete qSock; | 177 | delete qSock; |
177 | #endif | 178 | #endif |
178 | delete_ifnot_null(notifier); | 179 | delete_ifnot_null(notifier); |
179 | if (rdBuf) | 180 | if (rdBuf) |
180 | free(rdBuf); | 181 | free(rdBuf); |
181 | #ifndef PWM_EMBEDDED | 182 | #ifndef PWM_EMBEDDED |
182 | if (stream) | 183 | if (stream) |
183 | fclose(stream); | 184 | fclose(stream); |
184 | #endif | 185 | #endif |
185 | if (host) { | 186 | if (host) { |
186 | close(sock[0]); | 187 | close(sock[0]); |
187 | close(sock[1]); | 188 | close(sock[1]); |
188 | } | 189 | } |
189 | 190 | ||
190 | } | 191 | } |
191 | 192 | ||
192 | void Ipc::receiveData(int s) | 193 | void Ipc::receiveData(int s) |
193 | { | 194 | { |
194 | PWM_ASSERT(s == sock[0]); | 195 | PWM_ASSERT(s == sock[0]); |
195 | PARAM_UNUSED(s); | 196 | PARAM_UNUSED(s); |
196 | #ifndef PWM_EMBEDDED | 197 | #ifndef PWM_EMBEDDED |
197 | ssize_t rd; | 198 | ssize_t rd; |
198 | 199 | ||
199 | rd = ::getline(&rdBuf, &rdBufSize, stream); | 200 | rd = ::getline(&rdBuf, &rdBufSize, stream); |
200 | if (likely(rd > 0)) { | 201 | if (likely(rd > 0)) { |
201 | emit lineAvailable(rdBuf, rd); | 202 | emit lineAvailable(rdBuf, rd); |
202 | } | 203 | } |
203 | #else | 204 | #else |
204 | int rd; | 205 | int rd; |
205 | rd = qSock->readLine(rdBuf, rdBufSize); | 206 | rd = qSock->readLine(rdBuf, rdBufSize); |
206 | if (rd > 0) { | 207 | if (rd > 0) { |
207 | emit lineAvailable(rdBuf, rd); | 208 | emit lineAvailable(rdBuf, rd); |
208 | } | 209 | } |
209 | #endif | 210 | #endif |
210 | qDebug("void Ipc::receiveData(int s) has to be implemented."); | 211 | qDebug("void Ipc::receiveData(int s) has to be implemented."); |
211 | 212 | ||
212 | } | 213 | } |
213 | 214 | ||
214 | #ifndef PWM_EMBEDDED | 215 | #ifndef PWM_EMBEDDED |
215 | #include "ipc.moc" | 216 | #include "ipc.moc" |
216 | #endif | 217 | #endif |
diff --git a/pwmanager/pwmanager/ipc.h b/pwmanager/pwmanager/ipc.h index e5a496d..7bfca02 100644 --- a/pwmanager/pwmanager/ipc.h +++ b/pwmanager/pwmanager/ipc.h | |||
@@ -1,89 +1,92 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #ifndef __PWM_IPC_H | 20 | #ifndef __PWM_IPC_H |
21 | #define __PWM_IPC_H | 21 | #define __PWM_IPC_H |
22 | 22 | ||
23 | #include <qobject.h> | 23 | #include <qobject.h> |
24 | #ifndef _WIN32_ | ||
24 | #include <unistd.h> | 25 | #include <unistd.h> |
25 | 26 | #else | |
27 | #include <io.h> | ||
28 | #endif | ||
26 | #ifndef PWM_EMBEDDED | 29 | #ifndef PWM_EMBEDDED |
27 | #include <stdio.h> | 30 | #include <stdio.h> |
28 | #else | 31 | #else |
29 | #include <qsocket.h> | 32 | #include <qsocket.h> |
30 | #endif | 33 | #endif |
31 | 34 | ||
32 | class QSocketNotifier; | 35 | class QSocketNotifier; |
33 | 36 | ||
34 | /** very simple interprocess communication class */ | 37 | /** very simple interprocess communication class */ |
35 | class Ipc : public QObject | 38 | class Ipc : public QObject |
36 | { | 39 | { |
37 | Q_OBJECT | 40 | Q_OBJECT |
38 | public: | 41 | public: |
39 | /** create a new Ipc communication object */ | 42 | /** create a new Ipc communication object */ |
40 | Ipc(); | 43 | Ipc(); |
41 | /** create a new Ipc communication object and | 44 | /** create a new Ipc communication object and |
42 | * connect it to "ipc" | 45 | * connect it to "ipc" |
43 | */ | 46 | */ |
44 | Ipc(const Ipc *ipc); | 47 | Ipc(const Ipc *ipc); |
45 | /** destructor */ | 48 | /** destructor */ |
46 | ~Ipc(); | 49 | ~Ipc(); |
47 | 50 | ||
48 | /** send data to the other socket end | 51 | /** send data to the other socket end |
49 | * (To the connected ipc object) | 52 | * (To the connected ipc object) |
50 | */ | 53 | */ |
51 | #ifndef PWM_EMBEDDED | 54 | #ifndef PWM_EMBEDDED |
52 | void send(const char *buf, size_t size) | 55 | void send(const char *buf, size_t size) |
53 | { write(sock[0], buf, size); } | 56 | { write(sock[0], buf, size); } |
54 | #else | 57 | #else |
55 | void send(const char *buf, size_t size) | 58 | void send(const char *buf, size_t size) |
56 | { qSock->writeBlock(buf, size); } | 59 | { qSock->writeBlock(buf, size); } |
57 | #endif | 60 | #endif |
58 | 61 | ||
59 | signals: | 62 | signals: |
60 | /** a line is available */ | 63 | /** a line is available */ |
61 | void lineAvailable(const char *buf, size_t size); | 64 | void lineAvailable(const char *buf, size_t size); |
62 | 65 | ||
63 | protected slots: | 66 | protected slots: |
64 | /** received data on socket */ | 67 | /** received data on socket */ |
65 | void receiveData(int s); | 68 | void receiveData(int s); |
66 | 69 | ||
67 | protected: | 70 | protected: |
68 | #ifndef PWM_EMBEDDED | 71 | #ifndef PWM_EMBEDDED |
69 | /** stream on "this" end of the socket (sock[0]) */ | 72 | /** stream on "this" end of the socket (sock[0]) */ |
70 | FILE *stream; | 73 | FILE *stream; |
71 | /** current receive buffer size */ | 74 | /** current receive buffer size */ |
72 | size_t rdBufSize; | 75 | size_t rdBufSize; |
73 | #else | 76 | #else |
74 | QSocket* qSock; | 77 | QSocket* qSock; |
75 | /** current receive buffer size */ | 78 | /** current receive buffer size */ |
76 | unsigned int rdBufSize; | 79 | unsigned int rdBufSize; |
77 | #endif | 80 | #endif |
78 | 81 | ||
79 | /** full-duplex socket file desciptors */ | 82 | /** full-duplex socket file desciptors */ |
80 | int sock[2]; | 83 | int sock[2]; |
81 | /** socket notifier */ | 84 | /** socket notifier */ |
82 | QSocketNotifier *notifier; | 85 | QSocketNotifier *notifier; |
83 | /** are we the host or the client object? */ | 86 | /** are we the host or the client object? */ |
84 | bool host; | 87 | bool host; |
85 | /** receive buffer */ | 88 | /** receive buffer */ |
86 | char *rdBuf; | 89 | char *rdBuf; |
87 | }; | 90 | }; |
88 | 91 | ||
89 | #endif // __PWM_IPC_H | 92 | #endif // __PWM_IPC_H |
diff --git a/pwmanager/pwmanager/libgcryptif.h b/pwmanager/pwmanager/libgcryptif.h index dffd55b..1a7b658 100644 --- a/pwmanager/pwmanager/libgcryptif.h +++ b/pwmanager/pwmanager/libgcryptif.h | |||
@@ -1,166 +1,171 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * hashPassphrase() is derived from GnuPG and is * | 6 | * hashPassphrase() is derived from GnuPG and is * |
7 | * Copyright (C) 1998, 1999, 2000, 2001, 2003 * | 7 | * Copyright (C) 1998, 1999, 2000, 2001, 2003 * |
8 | * Free Software Foundation, Inc. * | 8 | * Free Software Foundation, Inc. * |
9 | * * | 9 | * * |
10 | * This program is free software; you can redistribute it and/or modify * | 10 | * This program is free software; you can redistribute it and/or modify * |
11 | * it under the terms of the GNU General Public License version 2 * | 11 | * it under the terms of the GNU General Public License version 2 * |
12 | * as published by the Free Software Foundation. * | 12 | * as published by the Free Software Foundation. * |
13 | * * | 13 | * * |
14 | ***************************************************************************/ | 14 | ***************************************************************************/ |
15 | 15 | ||
16 | /*************************************************************************** | 16 | /*************************************************************************** |
17 | * copyright (C) 2004 by Ulf Schenk | 17 | * copyright (C) 2004 by Ulf Schenk |
18 | * This file is originaly based on version 1.1 of pwmanager | 18 | * This file is originaly based on version 1.1 of pwmanager |
19 | * and was modified to run on embedded devices that run microkde | 19 | * and was modified to run on embedded devices that run microkde |
20 | * | 20 | * |
21 | * $Id$ | 21 | * $Id$ |
22 | **************************************************************************/ | 22 | **************************************************************************/ |
23 | 23 | ||
24 | #ifndef __LIBGCRYPTIF_H | 24 | #ifndef __LIBGCRYPTIF_H |
25 | #define __LIBGCRYPTIF_H | 25 | #define __LIBGCRYPTIF_H |
26 | 26 | ||
27 | #include "pwmexception.h" | 27 | #include "pwmexception.h" |
28 | 28 | ||
29 | //#undef CONFIG_PWMANAGER_GCRY // for debugging only. | 29 | //#undef CONFIG_PWMANAGER_GCRY // for debugging only. |
30 | #ifdef CONFIG_PWMANAGER_GCRY | 30 | #ifdef CONFIG_PWMANAGER_GCRY |
31 | 31 | ||
32 | #include <stddef.h> | 32 | #include <stddef.h> |
33 | #include <sys/types.h> | 33 | #include <sys/types.h> |
34 | #ifndef _WIN32_ | ||
34 | #include <stdint.h> | 35 | #include <stdint.h> |
35 | 36 | #else | |
37 | #define uint8_t Q_UINT8 | ||
38 | #define byte Q_UINT8 | ||
39 | #define uint32_t Q_UINT32 | ||
40 | #endif | ||
36 | #define STRING2KEY_SALTLEN8 | 41 | #define STRING2KEY_SALTLEN8 |
37 | 42 | ||
38 | /** interface class for the libgcrypt cipher and hash algorithms | 43 | /** interface class for the libgcrypt cipher and hash algorithms |
39 | * NOTE: Always allocate 1024 extra bytes for the inBuf (for padding) | 44 | * NOTE: Always allocate 1024 extra bytes for the inBuf (for padding) |
40 | */ | 45 | */ |
41 | class LibGCryptIf | 46 | class LibGCryptIf |
42 | { | 47 | { |
43 | protected: | 48 | protected: |
44 | struct STRING2KEY | 49 | struct STRING2KEY |
45 | { | 50 | { |
46 | int mode; | 51 | int mode; |
47 | int hash_algo; | 52 | int hash_algo; |
48 | uint8_t salt[STRING2KEY_SALTLEN]; | 53 | uint8_t salt[STRING2KEY_SALTLEN]; |
49 | uint32_t count; | 54 | uint32_t count; |
50 | }; | 55 | }; |
51 | struct DEK | 56 | struct DEK |
52 | { | 57 | { |
53 | size_t keylen; | 58 | size_t keylen; |
54 | uint8_t key[32]; // this is the largest used keylen (256 bit) | 59 | uint8_t key[32]; // this is the largest used keylen (256 bit) |
55 | }; | 60 | }; |
56 | 61 | ||
57 | public: | 62 | public: |
58 | LibGCryptIf() { } | 63 | LibGCryptIf() { } |
59 | /** is libgcrypt available? */ | 64 | /** is libgcrypt available? */ |
60 | static bool available() | 65 | static bool available() |
61 | { return true; } | 66 | { return true; } |
62 | /** encrypt data. _algo is the PWM_CRYPT_* ID | 67 | /** encrypt data. _algo is the PWM_CRYPT_* ID |
63 | * of the algorithm. | 68 | * of the algorithm. |
64 | */ | 69 | */ |
65 | PwMerror encrypt(unsigned char **outBuf, | 70 | PwMerror encrypt(unsigned char **outBuf, |
66 | size_t *outBufLen, | 71 | size_t *outBufLen, |
67 | unsigned char *inBuf, | 72 | unsigned char *inBuf, |
68 | size_t inBufLen, | 73 | size_t inBufLen, |
69 | const unsigned char *key, | 74 | const unsigned char *key, |
70 | size_t keylen, | 75 | size_t keylen, |
71 | char _algo); | 76 | char _algo); |
72 | /** decrypt data. _algo is the PWM_CRYPT_* ID | 77 | /** decrypt data. _algo is the PWM_CRYPT_* ID |
73 | * of the algorithm. | 78 | * of the algorithm. |
74 | */ | 79 | */ |
75 | PwMerror decrypt(unsigned char **outBuf, | 80 | PwMerror decrypt(unsigned char **outBuf, |
76 | size_t *outBufLen, | 81 | size_t *outBufLen, |
77 | const unsigned char *inBuf, | 82 | const unsigned char *inBuf, |
78 | size_t inBufLen, | 83 | size_t inBufLen, |
79 | const unsigned char *key, | 84 | const unsigned char *key, |
80 | size_t keylen, | 85 | size_t keylen, |
81 | char _algo); | 86 | char _algo); |
82 | /** hash data. _algo is the PWM_HASH_* ID of the hash */ | 87 | /** hash data. _algo is the PWM_HASH_* ID of the hash */ |
83 | PwMerror hash(unsigned char **outBuf, | 88 | PwMerror hash(unsigned char **outBuf, |
84 | size_t *outBufLen, | 89 | size_t *outBufLen, |
85 | const unsigned char *inBuf, | 90 | const unsigned char *inBuf, |
86 | size_t inBufLen, | 91 | size_t inBufLen, |
87 | char _algo); | 92 | char _algo); |
88 | /** returns the length of the hash. _algo is the PWM_HASH_* | 93 | /** returns the length of the hash. _algo is the PWM_HASH_* |
89 | * id of the hash. returns 0 on error. | 94 | * id of the hash. returns 0 on error. |
90 | */ | 95 | */ |
91 | unsigned int hashLength(char _algo); | 96 | unsigned int hashLength(char _algo); |
92 | 97 | ||
93 | protected: | 98 | protected: |
94 | /** returns the total buffer length */ | 99 | /** returns the total buffer length */ |
95 | size_t getBufLen(size_t inBufLen, size_t boundary) | 100 | size_t getBufLen(size_t inBufLen, size_t boundary) |
96 | { | 101 | { |
97 | return ((boundary - (inBufLen % boundary)) + inBufLen); | 102 | return ((boundary - (inBufLen % boundary)) + inBufLen); |
98 | } | 103 | } |
99 | /** pad the data up to the given boundary. | 104 | /** pad the data up to the given boundary. |
100 | * "buf" has to be big enough! | 105 | * "buf" has to be big enough! |
101 | */ | 106 | */ |
102 | void padData(unsigned char *buf, | 107 | void padData(unsigned char *buf, |
103 | size_t bufLen, | 108 | size_t bufLen, |
104 | size_t boundary); | 109 | size_t boundary); |
105 | /** unpad the data */ | 110 | /** unpad the data */ |
106 | void unpadData(const unsigned char *buf, | 111 | void unpadData(const unsigned char *buf, |
107 | size_t *bufLen); | 112 | size_t *bufLen); |
108 | /** maps the PWM_CRYPT_* ID of an algorithm | 113 | /** maps the PWM_CRYPT_* ID of an algorithm |
109 | * to the libgcrypt GCRY_CIPHER_* ID | 114 | * to the libgcrypt GCRY_CIPHER_* ID |
110 | */ | 115 | */ |
111 | int mapCipherId(char algo); | 116 | int mapCipherId(char algo); |
112 | /** maps the PWM_HASH_* ID of an algorithm | 117 | /** maps the PWM_HASH_* ID of an algorithm |
113 | * to the libgcrypt GCRY_MD_* ID | 118 | * to the libgcrypt GCRY_MD_* ID |
114 | */ | 119 | */ |
115 | int mapHashId(char algo); | 120 | int mapHashId(char algo); |
116 | /** hash a passphrase to a cipher key */ | 121 | /** hash a passphrase to a cipher key */ |
117 | bool hashPassphrase(const unsigned char *pw, | 122 | bool hashPassphrase(const unsigned char *pw, |
118 | size_t pwlen, | 123 | size_t pwlen, |
119 | unsigned char *salt, | 124 | unsigned char *salt, |
120 | unsigned char *key, | 125 | unsigned char *key, |
121 | size_t keylen, | 126 | size_t keylen, |
122 | bool create); | 127 | bool create); |
123 | /** hash a passphrase to a cipher key */ | 128 | /** hash a passphrase to a cipher key */ |
124 | bool doHashPassphrase(DEK *dek, | 129 | bool doHashPassphrase(DEK *dek, |
125 | const unsigned char *pw, | 130 | const unsigned char *pw, |
126 | size_t pwlen, | 131 | size_t pwlen, |
127 | STRING2KEY *s2k, | 132 | STRING2KEY *s2k, |
128 | bool create); | 133 | bool create); |
129 | }; | 134 | }; |
130 | 135 | ||
131 | 136 | ||
132 | #else // CONFIG_PWMANAGER_GCRY | 137 | #else // CONFIG_PWMANAGER_GCRY |
133 | /** libgcrypt is not installed. This is a NOP wrapper. */ | 138 | /** libgcrypt is not installed. This is a NOP wrapper. */ |
134 | class LibGCryptIf | 139 | class LibGCryptIf |
135 | { | 140 | { |
136 | public: | 141 | public: |
137 | LibGCryptIf() { } | 142 | LibGCryptIf() { } |
138 | static bool available() | 143 | static bool available() |
139 | { return false; } | 144 | { return false; } |
140 | PwMerror encrypt(unsigned char **, | 145 | PwMerror encrypt(unsigned char **, |
141 | size_t *, | 146 | size_t *, |
142 | unsigned char *, | 147 | unsigned char *, |
143 | size_t, | 148 | size_t, |
144 | const unsigned char *, | 149 | const unsigned char *, |
145 | size_t, | 150 | size_t, |
146 | char) | 151 | char) |
147 | { return e_cryptNotImpl; } | 152 | { return e_cryptNotImpl; } |
148 | PwMerror decrypt(unsigned char **, | 153 | PwMerror decrypt(unsigned char **, |
149 | size_t *, | 154 | size_t *, |
150 | const unsigned char *, | 155 | const unsigned char *, |
151 | size_t, | 156 | size_t, |
152 | const unsigned char *, | 157 | const unsigned char *, |
153 | size_t, | 158 | size_t, |
154 | char) | 159 | char) |
155 | { return e_cryptNotImpl; } | 160 | { return e_cryptNotImpl; } |
156 | PwMerror hash(unsigned char **, | 161 | PwMerror hash(unsigned char **, |
157 | size_t *, | 162 | size_t *, |
158 | const unsigned char *, | 163 | const unsigned char *, |
159 | size_t, | 164 | size_t, |
160 | char) | 165 | char) |
161 | { return e_hashNotImpl; } | 166 | { return e_hashNotImpl; } |
162 | unsigned int hashLength(char) | 167 | unsigned int hashLength(char) |
163 | { return 0; } | 168 | { return 0; } |
164 | }; | 169 | }; |
165 | #endif // CONFIG_PWMANAGER_GCRY | 170 | #endif // CONFIG_PWMANAGER_GCRY |
166 | #endif // __LIBGCRYPTIF_H | 171 | #endif // __LIBGCRYPTIF_H |
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp index d92c90d..1ab2b71 100644 --- a/pwmanager/pwmanager/pwm.cpp +++ b/pwmanager/pwmanager/pwm.cpp | |||
@@ -1221,245 +1221,246 @@ bool PwM::checkAndAskForKWalletEmu() | |||
1221 | 1221 | ||
1222 | bool PwM::importKWallet() | 1222 | bool PwM::importKWallet() |
1223 | { | 1223 | { |
1224 | #ifdef CONFIG_KWALLETIF | 1224 | #ifdef CONFIG_KWALLETIF |
1225 | if (!checkAndAskForKWalletEmu()) | 1225 | if (!checkAndAskForKWalletEmu()) |
1226 | return false; | 1226 | return false; |
1227 | KWalletIf walletIf(this); | 1227 | KWalletIf walletIf(this); |
1228 | if (!isVirgin()) { | 1228 | if (!isVirgin()) { |
1229 | if (KMessageBox::questionYesNo(this, | 1229 | if (KMessageBox::questionYesNo(this, |
1230 | i18n("Do you want to import the data " | 1230 | i18n("Do you want to import the data " |
1231 | "into the current document? (If you " | 1231 | "into the current document? (If you " |
1232 | "select \"no\", a new document will be " | 1232 | "select \"no\", a new document will be " |
1233 | "opened.)"), | 1233 | "opened.)"), |
1234 | i18n("import into this document?")) | 1234 | i18n("import into this document?")) |
1235 | == KMessageBox::No) { | 1235 | == KMessageBox::No) { |
1236 | // import the data to a new window. | 1236 | // import the data to a new window. |
1237 | PwM *newInstance = init->createMainWnd(); | 1237 | PwM *newInstance = init->createMainWnd(); |
1238 | bool ok = newInstance->importKWallet(); | 1238 | bool ok = newInstance->importKWallet(); |
1239 | if (!ok) { | 1239 | if (!ok) { |
1240 | newInstance->setForceQuit(true); | 1240 | newInstance->setForceQuit(true); |
1241 | delete_and_null(newInstance); | 1241 | delete_and_null(newInstance); |
1242 | goto exit_fail; | 1242 | goto exit_fail; |
1243 | } else { | 1243 | } else { |
1244 | goto exit_ok; | 1244 | goto exit_ok; |
1245 | } | 1245 | } |
1246 | } | 1246 | } |
1247 | } | 1247 | } |
1248 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1248 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1249 | if (!walletIf.kwalletImport(curDoc())) { | 1249 | if (!walletIf.kwalletImport(curDoc())) { |
1250 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1250 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1251 | showStatMsg(i18n("KWallet import failed")); | 1251 | showStatMsg(i18n("KWallet import failed")); |
1252 | goto exit_fail; | 1252 | goto exit_fail; |
1253 | } | 1253 | } |
1254 | KMessageBox::information(this, | 1254 | KMessageBox::information(this, |
1255 | i18n("Successfully imported the KWallet data " | 1255 | i18n("Successfully imported the KWallet data " |
1256 | "into the current document."), | 1256 | "into the current document."), |
1257 | i18n("successfully imported")); | 1257 | i18n("successfully imported")); |
1258 | showStatMsg(i18n("successfully imported")); | 1258 | showStatMsg(i18n("successfully imported")); |
1259 | setVirgin(false); | 1259 | setVirgin(false); |
1260 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1260 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1261 | 1261 | ||
1262 | exit_ok: | 1262 | exit_ok: |
1263 | init->initKWalletEmu(); | 1263 | init->initKWalletEmu(); |
1264 | return true; | 1264 | return true; |
1265 | 1265 | ||
1266 | exit_fail: | 1266 | exit_fail: |
1267 | init->initKWalletEmu(); | 1267 | init->initKWalletEmu(); |
1268 | #endif // CONFIG_KWALLETIF | 1268 | #endif // CONFIG_KWALLETIF |
1269 | return false; | 1269 | return false; |
1270 | } | 1270 | } |
1271 | 1271 | ||
1272 | void PwM::print_slot() | 1272 | void PwM::print_slot() |
1273 | { | 1273 | { |
1274 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1274 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1275 | #ifndef PWM_EMBEDDED | 1275 | #ifndef PWM_EMBEDDED |
1276 | PwMPrint p(curDoc(), this); | 1276 | PwMPrint p(curDoc(), this); |
1277 | p.printNow(); | 1277 | p.printNow(); |
1278 | #else | 1278 | #else |
1279 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); | 1279 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); |
1280 | #endif | 1280 | #endif |
1281 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1281 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1282 | } | 1282 | } |
1283 | 1283 | ||
1284 | void PwM::genNewCard_slot() | 1284 | void PwM::genNewCard_slot() |
1285 | { | 1285 | { |
1286 | #ifdef CONFIG_KEYCARD | 1286 | #ifdef CONFIG_KEYCARD |
1287 | init->keycard()->genNewCard(); | 1287 | init->keycard()->genNewCard(); |
1288 | #endif | 1288 | #endif |
1289 | } | 1289 | } |
1290 | 1290 | ||
1291 | void PwM::eraseCard_slot() | 1291 | void PwM::eraseCard_slot() |
1292 | { | 1292 | { |
1293 | #ifdef CONFIG_KEYCARD | 1293 | #ifdef CONFIG_KEYCARD |
1294 | init->keycard()->eraseCard(); | 1294 | init->keycard()->eraseCard(); |
1295 | #endif | 1295 | #endif |
1296 | } | 1296 | } |
1297 | 1297 | ||
1298 | void PwM::readCardId_slot() | 1298 | void PwM::readCardId_slot() |
1299 | { | 1299 | { |
1300 | #ifdef CONFIG_KEYCARD | 1300 | #ifdef CONFIG_KEYCARD |
1301 | init->keycard()->displayKey(); | 1301 | init->keycard()->displayKey(); |
1302 | #endif | 1302 | #endif |
1303 | } | 1303 | } |
1304 | 1304 | ||
1305 | void PwM::makeCardBackup_slot() | 1305 | void PwM::makeCardBackup_slot() |
1306 | { | 1306 | { |
1307 | #ifdef CONFIG_KEYCARD | 1307 | #ifdef CONFIG_KEYCARD |
1308 | init->keycard()->makeBackupImage(); | 1308 | init->keycard()->makeBackupImage(); |
1309 | #endif | 1309 | #endif |
1310 | } | 1310 | } |
1311 | 1311 | ||
1312 | void PwM::replayCardBackup_slot() | 1312 | void PwM::replayCardBackup_slot() |
1313 | { | 1313 | { |
1314 | #ifdef CONFIG_KEYCARD | 1314 | #ifdef CONFIG_KEYCARD |
1315 | init->keycard()->replayBackupImage(); | 1315 | init->keycard()->replayBackupImage(); |
1316 | #endif | 1316 | #endif |
1317 | } | 1317 | } |
1318 | 1318 | ||
1319 | void PwM::execLauncher_slot() | 1319 | void PwM::execLauncher_slot() |
1320 | { | 1320 | { |
1321 | PWM_ASSERT(curDoc()); | 1321 | PWM_ASSERT(curDoc()); |
1322 | if (curDoc()->isDeepLocked()) | 1322 | if (curDoc()->isDeepLocked()) |
1323 | return; | 1323 | return; |
1324 | unsigned int curEntryIndex; | 1324 | unsigned int curEntryIndex; |
1325 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1325 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1326 | return; | 1326 | return; |
1327 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), | 1327 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), |
1328 | curEntryIndex); | 1328 | curEntryIndex); |
1329 | if (ret) | 1329 | if (ret) |
1330 | showStatMsg(i18n("Executed the \"Launcher\".")); | 1330 | showStatMsg(i18n("Executed the \"Launcher\".")); |
1331 | else | 1331 | else |
1332 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); | 1332 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); |
1333 | } | 1333 | } |
1334 | 1334 | ||
1335 | void PwM::goToURL_slot() | 1335 | void PwM::goToURL_slot() |
1336 | { | 1336 | { |
1337 | PWM_ASSERT(curDoc()); | 1337 | PWM_ASSERT(curDoc()); |
1338 | if (curDoc()->isDeepLocked()) | 1338 | if (curDoc()->isDeepLocked()) |
1339 | return; | 1339 | return; |
1340 | unsigned int curEntryIndex; | 1340 | unsigned int curEntryIndex; |
1341 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1341 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1342 | return; | 1342 | return; |
1343 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), | 1343 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), |
1344 | curEntryIndex); | 1344 | curEntryIndex); |
1345 | if (ret) | 1345 | if (ret) |
1346 | showStatMsg(i18n("started browser with current URL.")); | 1346 | showStatMsg(i18n("started browser with current URL.")); |
1347 | else | 1347 | else |
1348 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); | 1348 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); |
1349 | } | 1349 | } |
1350 | 1350 | ||
1351 | void PwM::copyToClipboard(const QString &s) | 1351 | void PwM::copyToClipboard(const QString &s) |
1352 | { | 1352 | { |
1353 | QClipboard *cb = QApplication::clipboard(); | 1353 | QClipboard *cb = QApplication::clipboard(); |
1354 | #ifndef PWM_EMBEDDED | 1354 | #ifndef PWM_EMBEDDED |
1355 | if (cb->supportsSelection()) | 1355 | if (cb->supportsSelection()) |
1356 | cb->setText(s, QClipboard::Selection); | 1356 | cb->setText(s, QClipboard::Selection); |
1357 | cb->setText(s, QClipboard::Clipboard); | 1357 | cb->setText(s, QClipboard::Clipboard); |
1358 | #else | 1358 | #else |
1359 | cb->setText(s); | 1359 | cb->setText(s); |
1360 | 1360 | ||
1361 | #endif | 1361 | #endif |
1362 | 1362 | ||
1363 | } | 1363 | } |
1364 | 1364 | ||
1365 | 1365 | ||
1366 | void PwM::showStatMsg(const QString &msg) | 1366 | void PwM::showStatMsg(const QString &msg) |
1367 | { | 1367 | { |
1368 | #ifdef DESKTOP_VERSION | 1368 | #ifdef DESKTOP_VERSION |
1369 | statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); | 1369 | statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); |
1370 | #else | 1370 | #else |
1371 | qDebug("Statusbar : %s",msg.latin1()); | 1371 | qDebug("Statusbar : %s",msg.latin1()); |
1372 | Global::statusMessage(msg); | 1372 | Global::statusMessage(msg); |
1373 | #endif | 1373 | #endif |
1374 | } | 1374 | } |
1375 | 1375 | ||
1376 | void PwM::focusInEvent(QFocusEvent *e) | 1376 | void PwM::focusInEvent(QFocusEvent *e) |
1377 | { | 1377 | { |
1378 | if (e->gotFocus()) { | 1378 | if (e->gotFocus()) { |
1379 | emit gotFocus(this); | 1379 | emit gotFocus(this); |
1380 | } else if (e->lostFocus()) { | 1380 | } else if (e->lostFocus()) { |
1381 | emit lostFocus(this); | 1381 | emit lostFocus(this); |
1382 | } | 1382 | } |
1383 | } | 1383 | } |
1384 | 1384 | ||
1385 | 1385 | ||
1386 | #ifdef PWM_EMBEDDED | 1386 | #ifdef PWM_EMBEDDED |
1387 | 1387 | ||
1388 | void PwM::whatsnew_slot() | 1388 | void PwM::whatsnew_slot() |
1389 | { | 1389 | { |
1390 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); | 1390 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); |
1391 | } | 1391 | } |
1392 | 1392 | ||
1393 | void PwM::showLicense_slot() | 1393 | void PwM::showLicense_slot() |
1394 | { | 1394 | { |
1395 | KApplication::showLicence(); | 1395 | KApplication::showLicence(); |
1396 | } | 1396 | } |
1397 | 1397 | ||
1398 | void PwM::faq_slot() | 1398 | void PwM::faq_slot() |
1399 | { | 1399 | { |
1400 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); | 1400 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); |
1401 | } | 1401 | } |
1402 | 1402 | ||
1403 | void PwM::syncHowTo_slot() | 1403 | void PwM::syncHowTo_slot() |
1404 | { | 1404 | { |
1405 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | 1405 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); |
1406 | } | 1406 | } |
1407 | 1407 | ||
1408 | 1408 | ||
1409 | void PwM::createAboutData_slot() | 1409 | void PwM::createAboutData_slot() |
1410 | { | 1410 | { |
1411 | QString version; | 1411 | QString version; |
1412 | #include <../version> | 1412 | #include <../version> |
1413 | ; | ||
1413 | QMessageBox::about( this, "About PwManager/Pi", | 1414 | QMessageBox::about( this, "About PwManager/Pi", |
1414 | "PwManager/Platform-independent\n" | 1415 | "PwManager/Platform-independent\n" |
1415 | "(PWM/Pi) " +version + " - " + | 1416 | "(PWM/Pi) " +version + " - " + |
1416 | #ifdef DESKTOP_VERSION | 1417 | #ifdef DESKTOP_VERSION |
1417 | "Desktop Edition\n" | 1418 | "Desktop Edition\n" |
1418 | #else | 1419 | #else |
1419 | "PDA-Edition\n" | 1420 | "PDA-Edition\n" |
1420 | "for: Zaurus 5500 / 7x0 / 8x0\n" | 1421 | "for: Zaurus 5500 / 7x0 / 8x0\n" |
1421 | #endif | 1422 | #endif |
1422 | 1423 | ||
1423 | "(c) 2004 Ulf Schenk\n" | 1424 | "(c) 2004 Ulf Schenk\n" |
1424 | "(c) 2004 Lutz Rogowski\n" | 1425 | "(c) 2004 Lutz Rogowski\n" |
1425 | "(c) 1997-2004, The KDE PIM Team\n" | 1426 | "(c) 1997-2004, The KDE PIM Team\n" |
1426 | 1427 | ||
1427 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" | 1428 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" |
1428 | "Matt Scifo - mscifo@o1.com\n" | 1429 | "Matt Scifo - mscifo@o1.com\n" |
1429 | "Elias Probst - elias.probst@gmx.de\n" | 1430 | "Elias Probst - elias.probst@gmx.de\n" |
1430 | "George Staikos - staikos@kde.org\n" | 1431 | "George Staikos - staikos@kde.org\n" |
1431 | "Matthew Palmer - mjp16@uow.edu.au\n" | 1432 | "Matthew Palmer - mjp16@uow.edu.au\n" |
1432 | "Olivier Sessink - gpasman@nl.linux.org\n" | 1433 | "Olivier Sessink - gpasman@nl.linux.org\n" |
1433 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" | 1434 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" |
1434 | "Troy Engel - tengel@sonic.net\n" | 1435 | "Troy Engel - tengel@sonic.net\n" |
1435 | "Wickey - wickey@gmx.at\n" | 1436 | "Wickey - wickey@gmx.at\n" |
1436 | "Ian MacGregor - original documentation author.\n" | 1437 | "Ian MacGregor - original documentation author.\n" |
1437 | ); | 1438 | ); |
1438 | } | 1439 | } |
1439 | 1440 | ||
1440 | 1441 | ||
1441 | //this are the overwritten callbackmethods from the syncinterface | 1442 | //this are the overwritten callbackmethods from the syncinterface |
1442 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) | 1443 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) |
1443 | { | 1444 | { |
1444 | PWM_ASSERT(curDoc()); | 1445 | PWM_ASSERT(curDoc()); |
1445 | 1446 | ||
1446 | bool ret = curDoc()->sync(manager, filename, mode); | 1447 | bool ret = curDoc()->sync(manager, filename, mode); |
1447 | 1448 | ||
1448 | qDebug("PwM::sync save now: ret=%i", ret); | 1449 | qDebug("PwM::sync save now: ret=%i", ret); |
1449 | 1450 | ||
1450 | if (ret == true) { | 1451 | if (ret == true) { |
1451 | //US BUG: what can we call here to update the view of the current doc? | 1452 | //US BUG: what can we call here to update the view of the current doc? |
1452 | //mViewManager->refreshView(); | 1453 | //mViewManager->refreshView(); |
1453 | 1454 | ||
1454 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. | 1455 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. |
1455 | save(); | 1456 | save(); |
1456 | } | 1457 | } |
1457 | 1458 | ||
1458 | return ret; | 1459 | return ret; |
1459 | } | 1460 | } |
1460 | #endif | 1461 | #endif |
1461 | 1462 | ||
1462 | 1463 | ||
1463 | #ifndef PWM_EMBEDDED | 1464 | #ifndef PWM_EMBEDDED |
1464 | #include "pwm.moc" | 1465 | #include "pwm.moc" |
1465 | #endif | 1466 | #endif |
diff --git a/pwmanager/pwmanager/pwmanager.pro b/pwmanager/pwmanager/pwmanager.pro index 80b2519..fbc0554 100644 --- a/pwmanager/pwmanager/pwmanager.pro +++ b/pwmanager/pwmanager/pwmanager.pro | |||
@@ -1,175 +1,175 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG += qt warn_off | 2 | CONFIG += qt warn_off |
3 | DESTDIR= ../../bin | 3 | DESTDIR= ../../bin |
4 | TARGET = pwmpi | 4 | TARGET = pwmpi |
5 | include( ../../variables.pri ) | 5 | include( ../../variables.pri ) |
6 | 6 | ||
7 | INCLUDEPATH += . ../../ ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils | 7 | INCLUDEPATH += . ../../ ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils ../libcrypt/crypt ../libcrypt/error ../libcrypt/zlib |
8 | DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY DESKTOP_VERSION | 8 | DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY DESKTOP_VERSION |
9 | 9 | ||
10 | #enable this setting if you want debugoutput for pwmanager | 10 | #enable this setting if you want debugoutput for pwmanager |
11 | #DEFINES += CONFIG_DEBUG | 11 | #DEFINES += CONFIG_DEBUG |
12 | LIBS += -L../libcrypt/ | 12 | LIBS += -L../libcrypt/ |
13 | LIBS += -L../../bin/ | 13 | LIBS += -L../../bin/ |
14 | LIBS += -lmicrokde | 14 | LIBS += -lmicrokde |
15 | LIBS += -lmicrokdepim | 15 | LIBS += -lmicrokdepim |
16 | LIBS += -lzlib | 16 | LIBS += -lzlib |
17 | LIBS += -lkpmicrocipher | 17 | LIBS += -lkpmicrocipher |
18 | LIBS += -lkpmicroerror | 18 | LIBS += -lkpmicroerror |
19 | LIBS += -lkpmicrompi | 19 | LIBS += -lkpmicrompi |
20 | LIBS += -lstdc++ | 20 | LIBS += -lstdc++ |
21 | 21 | ||
22 | unix:{ | 22 | unix:{ |
23 | OBJECTS_DIR = obj/unix | 23 | OBJECTS_DIR = obj/unix |
24 | MOC_DIR = moc/unix | 24 | MOC_DIR = moc/unix |
25 | 25 | ||
26 | } | 26 | } |
27 | win32:{ | 27 | win32:{ |
28 | 28 | ||
29 | DEFINES += _WIN32_ | 29 | DEFINES += _WIN32_ |
30 | OBJECTS_DIR = obj/win | 30 | OBJECTS_DIR = obj/win |
31 | MOC_DIR = moc/win | 31 | MOC_DIR = moc/win |
32 | QMAKE_LINK += /NODEFAULTLIB:LIBC | 32 | QMAKE_LINK += /NODEFAULTLIB:LIBC |
33 | QMAKE_CXXFLAGS += /TP /GX /GR /Ehsc | 33 | QMAKE_CXXFLAGS += /TP /GX /GR /Ehsc |
34 | } | 34 | } |
35 | 35 | ||
36 | #INTERFACES = \ | 36 | #INTERFACES = \ |
37 | #addentrywnd.ui \ | 37 | #addentrywnd.ui \ |
38 | #configwnd.ui \ | 38 | #configwnd.ui \ |
39 | #findwnd.ui \ | 39 | #findwnd.ui \ |
40 | #getmasterpwwnd.ui \ | 40 | #getmasterpwwnd.ui \ |
41 | #pwgenwnd.ui \ | 41 | #pwgenwnd.ui \ |
42 | #setmasterpwwnd.ui \ | 42 | #setmasterpwwnd.ui \ |
43 | #subtbledit.ui | 43 | #subtbledit.ui |
44 | 44 | ||
45 | #INTERFACES = \ | 45 | #INTERFACES = \ |
46 | #subtbledit.ui \ | 46 | #subtbledit.ui \ |
47 | 47 | ||
48 | 48 | ||
49 | 49 | ||
50 | #HEADERS = \ | 50 | #HEADERS = \ |
51 | #configuration_31compat.h \ | 51 | #configuration_31compat.h \ |
52 | #configuration.h \ | 52 | #configuration.h \ |
53 | #configwnd.h \ | 53 | #configwnd.h \ |
54 | #configwndimpl.h \ | 54 | #configwndimpl.h \ |
55 | #selftest.h | 55 | #selftest.h |
56 | #subtbledit.h \ | 56 | #subtbledit.h \ |
57 | #subtbleditimpl.h \ | 57 | #subtbleditimpl.h \ |
58 | #compressbzip2.h \ | 58 | #compressbzip2.h \ |
59 | 59 | ||
60 | HEADERS = \ | 60 | HEADERS = \ |
61 | addentrywnd_emb.h \ | 61 | addentrywnd_emb.h \ |
62 | addentrywndimpl.h \ | 62 | addentrywndimpl.h \ |
63 | base64.h \ | 63 | base64.h \ |
64 | binentrygen.h \ | 64 | binentrygen.h \ |
65 | blowfish.h \ | 65 | blowfish.h \ |
66 | commentbox.h \ | 66 | commentbox.h \ |
67 | compiler.h \ | 67 | compiler.h \ |
68 | compressgzip.h \ | 68 | compressgzip.h \ |
69 | csv.h \ | 69 | csv.h \ |
70 | findwnd_emb.h \ | 70 | findwnd_emb.h \ |
71 | findwndimpl.h \ | 71 | findwndimpl.h \ |
72 | genpasswd.h \ | 72 | genpasswd.h \ |
73 | getkeycardwnd.h \ | 73 | getkeycardwnd.h \ |
74 | getmasterpwwnd_emb.h \ | 74 | getmasterpwwnd_emb.h \ |
75 | getmasterpwwndimpl.h \ | 75 | getmasterpwwndimpl.h \ |
76 | globalstuff.h \ | 76 | globalstuff.h \ |
77 | gpasmanfile.h \ | 77 | gpasmanfile.h \ |
78 | htmlgen.h \ | 78 | htmlgen.h \ |
79 | htmlparse.h \ | 79 | htmlparse.h \ |
80 | ipc.h \ | 80 | ipc.h \ |
81 | libgcryptif.h \ | 81 | libgcryptif.h \ |
82 | listobjselectwnd.h \ | 82 | listobjselectwnd.h \ |
83 | listviewpwm.h \ | 83 | listviewpwm.h \ |
84 | printtext.h \ | 84 | printtext.h \ |
85 | pwgenwnd_emb.h \ | 85 | pwgenwnd_emb.h \ |
86 | pwgenwndimpl.h \ | 86 | pwgenwndimpl.h \ |
87 | pwmdoc.h \ | 87 | pwmdoc.h \ |
88 | pwmdocui.h \ | 88 | pwmdocui.h \ |
89 | pwmexception.h \ | 89 | pwmexception.h \ |
90 | pwm.h \ | 90 | pwm.h \ |
91 | pwminit.h \ | 91 | pwminit.h \ |
92 | pwmprefs.h \ | 92 | pwmprefs.h \ |
93 | pwmprint.h \ | 93 | pwmprint.h \ |
94 | pwmtray.h \ | 94 | pwmtray.h \ |
95 | pwmview.h \ | 95 | pwmview.h \ |
96 | pwmviewstyle_0.h \ | 96 | pwmviewstyle_0.h \ |
97 | pwmviewstyle_1.h \ | 97 | pwmviewstyle_1.h \ |
98 | pwmviewstyle.h \ | 98 | pwmviewstyle.h \ |
99 | randomizer.h \ | 99 | randomizer.h \ |
100 | rc2.h \ | 100 | rc2.h \ |
101 | rencatwnd.h \ | 101 | rencatwnd.h \ |
102 | serializer.h \ | 102 | serializer.h \ |
103 | setmasterpwwnd_emb.h \ | 103 | setmasterpwwnd_emb.h \ |
104 | setmasterpwwndimpl.h \ | 104 | setmasterpwwndimpl.h \ |
105 | sha1.h \ | 105 | sha1.h \ |
106 | waitwnd.h \ | 106 | waitwnd.h \ |
107 | kcmconfigs/kcmpwmconfig.h \ | 107 | kcmconfigs/kcmpwmconfig.h \ |
108 | kcmconfigs/pwmconfigwidget.h | 108 | kcmconfigs/pwmconfigwidget.h |
109 | 109 | ||
110 | #sources that need not be build | 110 | #sources that need not be build |
111 | #SOURCES = \ | 111 | #SOURCES = \ |
112 | #advcommeditimpl.cpp \ | 112 | #advcommeditimpl.cpp \ |
113 | #configuration.cpp \ | 113 | #configuration.cpp \ |
114 | #configwnd.cpp \ | 114 | #configwnd.cpp \ |
115 | #configwndimpl.cpp \ | 115 | #configwndimpl.cpp \ |
116 | #configuration_31compat.cpp \ | 116 | #configuration_31compat.cpp \ |
117 | #htmlparse.cpp \ | 117 | #htmlparse.cpp \ |
118 | #printtext.cpp \ | 118 | #printtext.cpp \ |
119 | #selftest.cpp \ | 119 | #selftest.cpp \ |
120 | #pwmprint.cpp \ | 120 | #pwmprint.cpp \ |
121 | #spinforsignal.cpp | 121 | #spinforsignal.cpp |
122 | #subtbledit.cpp \ | 122 | #subtbledit.cpp \ |
123 | #subtbleditimpl.cpp \ | 123 | #subtbleditimpl.cpp \ |
124 | #compressbzip2.cpp | 124 | #compressbzip2.cpp |
125 | 125 | ||
126 | 126 | ||
127 | SOURCES = \ | 127 | SOURCES = \ |
128 | addentrywnd_emb.cpp \ | 128 | addentrywnd_emb.cpp \ |
129 | addentrywndimpl.cpp \ | 129 | addentrywndimpl.cpp \ |
130 | base64.cpp \ | 130 | base64.cpp \ |
131 | binentrygen.cpp \ | 131 | binentrygen.cpp \ |
132 | blowfish.cpp \ | 132 | blowfish.cpp \ |
133 | commentbox.cpp \ | 133 | commentbox.cpp \ |
134 | compressgzip.cpp \ | 134 | compressgzip.cpp \ |
135 | csv.cpp \ | 135 | csv.cpp \ |
136 | findwnd_emb.cpp \ | 136 | findwnd_emb.cpp \ |
137 | findwndimpl.cpp \ | 137 | findwndimpl.cpp \ |
138 | genpasswd.cpp \ | 138 | genpasswd.cpp \ |
139 | getkeycardwnd.cpp \ | 139 | getkeycardwnd.cpp \ |
140 | getmasterpwwnd_emb.cpp \ | 140 | getmasterpwwnd_emb.cpp \ |
141 | getmasterpwwndimpl.cpp \ | 141 | getmasterpwwndimpl.cpp \ |
142 | globalstuff.cpp \ | 142 | globalstuff.cpp \ |
143 | gpasmanfile.cpp \ | 143 | gpasmanfile.cpp \ |
144 | htmlgen.cpp \ | 144 | htmlgen.cpp \ |
145 | ipc.cpp \ | 145 | ipc.cpp \ |
146 | libgcryptif.cpp \ | 146 | libgcryptif.cpp \ |
147 | listobjselectwnd.cpp \ | 147 | listobjselectwnd.cpp \ |
148 | listviewpwm.cpp \ | 148 | listviewpwm.cpp \ |
149 | main.cpp \ | 149 | main.cpp \ |
150 | pwgenwnd_emb.cpp \ | 150 | pwgenwnd_emb.cpp \ |
151 | pwgenwndimpl.cpp \ | 151 | pwgenwndimpl.cpp \ |
152 | pwm.cpp \ | 152 | pwm.cpp \ |
153 | pwmdoc.cpp \ | 153 | pwmdoc.cpp \ |
154 | pwmdocui.cpp \ | 154 | pwmdocui.cpp \ |
155 | pwmexception.cpp \ | 155 | pwmexception.cpp \ |
156 | pwminit.cpp \ | 156 | pwminit.cpp \ |
157 | pwmprefs.cpp \ | 157 | pwmprefs.cpp \ |
158 | pwmtray.cpp \ | 158 | pwmtray.cpp \ |
159 | pwmview.cpp \ | 159 | pwmview.cpp \ |
160 | pwmviewstyle_0.cpp \ | 160 | pwmviewstyle_0.cpp \ |
161 | pwmviewstyle_1.cpp \ | 161 | pwmviewstyle_1.cpp \ |
162 | pwmviewstyle.cpp \ | 162 | pwmviewstyle.cpp \ |
163 | randomizer.cpp \ | 163 | randomizer.cpp \ |
164 | rc2.cpp \ | 164 | rc2.cpp \ |
165 | rencatwnd.cpp \ | 165 | rencatwnd.cpp \ |
166 | serializer.cpp \ | 166 | serializer.cpp \ |
167 | setmasterpwwnd_emb.cpp \ | 167 | setmasterpwwnd_emb.cpp \ |
168 | setmasterpwwndimpl.cpp \ | 168 | setmasterpwwndimpl.cpp \ |
169 | sha1.cpp \ | 169 | sha1.cpp \ |
170 | waitwnd.cpp \ | 170 | waitwnd.cpp \ |
171 | kcmconfigs/kcmpwmconfig.cpp \ | 171 | kcmconfigs/kcmpwmconfig.cpp \ |
172 | kcmconfigs/pwmconfigwidget.cpp | 172 | kcmconfigs/pwmconfigwidget.cpp |
173 | 173 | ||
174 | 174 | ||
175 | 175 | ||
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 86b6273..129bf7b 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -1,252 +1,253 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.1 of pwmanager | 14 | * This file is originaly based on version 1.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmdoc.h" | 20 | #include "pwmdoc.h" |
21 | #include "pwmview.h" | 21 | #include "pwmview.h" |
22 | #include "blowfish.h" | 22 | #include "blowfish.h" |
23 | #include "sha1.h" | 23 | #include "sha1.h" |
24 | #include "globalstuff.h" | 24 | #include "globalstuff.h" |
25 | #include "gpasmanfile.h" | 25 | #include "gpasmanfile.h" |
26 | #include "serializer.h" | 26 | #include "serializer.h" |
27 | #include "compressgzip.h" | 27 | #include "compressgzip.h" |
28 | //US#include "compressbzip2.h" | 28 | //US#include "compressbzip2.h" |
29 | #include "randomizer.h" | 29 | #include "randomizer.h" |
30 | #include "pwminit.h" | 30 | #include "pwminit.h" |
31 | #include "libgcryptif.h" | 31 | #include "libgcryptif.h" |
32 | #ifdef PWM_EMBEDDED | 32 | #ifdef PWM_EMBEDDED |
33 | #include "pwmprefs.h" | 33 | #include "pwmprefs.h" |
34 | #include "kglobal.h" | 34 | #include "kglobal.h" |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #include <kmessagebox.h> | 37 | #include <kmessagebox.h> |
38 | #include <libkcal/syncdefines.h> | 38 | #include <libkcal/syncdefines.h> |
39 | 39 | ||
40 | 40 | ||
41 | #ifdef CONFIG_KWALLETIF | 41 | #ifdef CONFIG_KWALLETIF |
42 | # include "kwalletemu.h" | 42 | # include "kwalletemu.h" |
43 | #endif // CONFIG_KWALLETIF | 43 | #endif // CONFIG_KWALLETIF |
44 | 44 | ||
45 | #include <qdatetime.h> | 45 | #include <qdatetime.h> |
46 | #include <qsize.h> | 46 | #include <qsize.h> |
47 | #include <qfileinfo.h> | 47 | #include <qfileinfo.h> |
48 | #include <qfile.h> | 48 | #include <qfile.h> |
49 | 49 | ||
50 | #include <stdio.h> | 50 | #include <stdio.h> |
51 | #include <stdlib.h> | 51 | #include <stdlib.h> |
52 | #include <errno.h> | 52 | #include <errno.h> |
53 | #include <string.h> | 53 | #include <string.h> |
54 | //US#include <iostream> | 54 | //US#include <iostream> |
55 | #include <algorithm> | 55 | #include <algorithm> |
56 | #include <sys/types.h> | 56 | #include <sys/types.h> |
57 | #include <sys/stat.h> | 57 | #include <sys/stat.h> |
58 | #ifndef _WIN32_ | ||
58 | #include <unistd.h> | 59 | #include <unistd.h> |
59 | #include <stdint.h> | 60 | #include <stdint.h> |
60 | 61 | #endif | |
61 | 62 | ||
62 | #ifdef PWM_EMBEDDED | 63 | #ifdef PWM_EMBEDDED |
63 | #ifndef Q_LONG | 64 | #ifndef Q_LONG |
64 | #define Q_LONG long | 65 | #define Q_LONG long |
65 | #endif | 66 | #endif |
66 | 67 | ||
67 | #ifndef Q_ULONG | 68 | #ifndef Q_ULONG |
68 | #define Q_ULONG unsigned long | 69 | #define Q_ULONG unsigned long |
69 | #endif | 70 | #endif |
70 | #endif //PWM_EMBEDDED | 71 | #endif //PWM_EMBEDDED |
71 | 72 | ||
72 | 73 | ||
73 | //TODO: reset to its normal value. | 74 | //TODO: reset to its normal value. |
74 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ | 75 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ |
75 | 76 | ||
76 | using namespace std; | 77 | using namespace std; |
77 | 78 | ||
78 | 79 | ||
79 | void PwMDocList::add(PwMDoc *doc, const string &id) | 80 | void PwMDocList::add(PwMDoc *doc, const string &id) |
80 | { | 81 | { |
81 | #ifdef PWM_DEBUG | 82 | #ifdef PWM_DEBUG |
82 | // check for existance of object in debug mode only. | 83 | // check for existance of object in debug mode only. |
83 | vector<listItem>::iterator begin = docList.begin(), | 84 | vector<listItem>::iterator begin = docList.begin(), |
84 | end = docList.end(), | 85 | end = docList.end(), |
85 | i = begin; | 86 | i = begin; |
86 | while (i != end) { | 87 | while (i != end) { |
87 | if (i->doc == doc) { | 88 | if (i->doc == doc) { |
88 | BUG(); | 89 | BUG(); |
89 | return; | 90 | return; |
90 | } | 91 | } |
91 | ++i; | 92 | ++i; |
92 | } | 93 | } |
93 | #endif | 94 | #endif |
94 | listItem newItem; | 95 | listItem newItem; |
95 | newItem.doc = doc; | 96 | newItem.doc = doc; |
96 | newItem.docId = id; | 97 | newItem.docId = id; |
97 | docList.push_back(newItem); | 98 | docList.push_back(newItem); |
98 | } | 99 | } |
99 | 100 | ||
100 | void PwMDocList::edit(PwMDoc *doc, const string &newId) | 101 | void PwMDocList::edit(PwMDoc *doc, const string &newId) |
101 | { | 102 | { |
102 | vector<listItem>::iterator begin = docList.begin(), | 103 | vector<listItem>::iterator begin = docList.begin(), |
103 | end = docList.end(), | 104 | end = docList.end(), |
104 | i = begin; | 105 | i = begin; |
105 | while (i != end) { | 106 | while (i != end) { |
106 | if (i->doc == doc) { | 107 | if (i->doc == doc) { |
107 | i->docId = newId; | 108 | i->docId = newId; |
108 | return; | 109 | return; |
109 | } | 110 | } |
110 | ++i; | 111 | ++i; |
111 | } | 112 | } |
112 | } | 113 | } |
113 | 114 | ||
114 | void PwMDocList::del(PwMDoc *doc) | 115 | void PwMDocList::del(PwMDoc *doc) |
115 | { | 116 | { |
116 | vector<listItem>::iterator begin = docList.begin(), | 117 | vector<listItem>::iterator begin = docList.begin(), |
117 | end = docList.end(), | 118 | end = docList.end(), |
118 | i = begin; | 119 | i = begin; |
119 | while (i != end) { | 120 | while (i != end) { |
120 | if (i->doc == doc) { | 121 | if (i->doc == doc) { |
121 | docList.erase(i); | 122 | docList.erase(i); |
122 | return; | 123 | return; |
123 | } | 124 | } |
124 | ++i; | 125 | ++i; |
125 | } | 126 | } |
126 | } | 127 | } |
127 | 128 | ||
128 | bool PwMDocList::find(const string &id, listItem *ret) | 129 | bool PwMDocList::find(const string &id, listItem *ret) |
129 | { | 130 | { |
130 | vector<listItem>::iterator begin = docList.begin(), | 131 | vector<listItem>::iterator begin = docList.begin(), |
131 | end = docList.end(), | 132 | end = docList.end(), |
132 | i = begin; | 133 | i = begin; |
133 | while (i != end) { | 134 | while (i != end) { |
134 | if (i->docId == id) { | 135 | if (i->docId == id) { |
135 | if (ret) | 136 | if (ret) |
136 | *ret = *i; | 137 | *ret = *i; |
137 | return true; | 138 | return true; |
138 | } | 139 | } |
139 | ++i; | 140 | ++i; |
140 | } | 141 | } |
141 | return false; | 142 | return false; |
142 | } | 143 | } |
143 | 144 | ||
144 | 145 | ||
145 | 146 | ||
146 | DocTimer::DocTimer(PwMDoc *_doc) | 147 | DocTimer::DocTimer(PwMDoc *_doc) |
147 | : doc (_doc) | 148 | : doc (_doc) |
148 | , mpwLock (0) | 149 | , mpwLock (0) |
149 | , autoLockLock (0) | 150 | , autoLockLock (0) |
150 | , metaCheckLock (0) | 151 | , metaCheckLock (0) |
151 | { | 152 | { |
152 | mpwTimer = new QTimer; | 153 | mpwTimer = new QTimer; |
153 | autoLockTimer = new QTimer; | 154 | autoLockTimer = new QTimer; |
154 | metaCheckTimer = new QTimer; | 155 | metaCheckTimer = new QTimer; |
155 | connect(mpwTimer, SIGNAL(timeout()), | 156 | connect(mpwTimer, SIGNAL(timeout()), |
156 | this, SLOT(mpwTimeout())); | 157 | this, SLOT(mpwTimeout())); |
157 | connect(autoLockTimer, SIGNAL(timeout()), | 158 | connect(autoLockTimer, SIGNAL(timeout()), |
158 | this, SLOT(autoLockTimeout())); | 159 | this, SLOT(autoLockTimeout())); |
159 | connect(metaCheckTimer, SIGNAL(timeout()), | 160 | connect(metaCheckTimer, SIGNAL(timeout()), |
160 | this, SLOT(metaCheckTimeout())); | 161 | this, SLOT(metaCheckTimeout())); |
161 | } | 162 | } |
162 | 163 | ||
163 | DocTimer::~DocTimer() | 164 | DocTimer::~DocTimer() |
164 | { | 165 | { |
165 | delete mpwTimer; | 166 | delete mpwTimer; |
166 | delete autoLockTimer; | 167 | delete autoLockTimer; |
167 | delete metaCheckTimer; | 168 | delete metaCheckTimer; |
168 | } | 169 | } |
169 | 170 | ||
170 | void DocTimer::start(TimerIDs timer) | 171 | void DocTimer::start(TimerIDs timer) |
171 | { | 172 | { |
172 | switch (timer) { | 173 | switch (timer) { |
173 | case id_mpwTimer: | 174 | case id_mpwTimer: |
174 | if (mpwTimer->isActive()) | 175 | if (mpwTimer->isActive()) |
175 | mpwTimer->stop(); | 176 | mpwTimer->stop(); |
176 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 177 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
177 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); | 178 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); |
178 | break; | 179 | break; |
179 | case id_autoLockTimer: | 180 | case id_autoLockTimer: |
180 | if (autoLockTimer->isActive()) | 181 | if (autoLockTimer->isActive()) |
181 | autoLockTimer->stop(); | 182 | autoLockTimer->stop(); |
182 | if (conf()->confGlobLockTimeout() > 0) | 183 | if (conf()->confGlobLockTimeout() > 0) |
183 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); | 184 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); |
184 | break; | 185 | break; |
185 | case id_metaCheckTimer: | 186 | case id_metaCheckTimer: |
186 | if (metaCheckTimer->isActive()) | 187 | if (metaCheckTimer->isActive()) |
187 | metaCheckTimer->stop(); | 188 | metaCheckTimer->stop(); |
188 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 189 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
189 | break; | 190 | break; |
190 | } | 191 | } |
191 | } | 192 | } |
192 | 193 | ||
193 | void DocTimer::stop(TimerIDs timer) | 194 | void DocTimer::stop(TimerIDs timer) |
194 | { | 195 | { |
195 | switch (timer) { | 196 | switch (timer) { |
196 | case id_mpwTimer: | 197 | case id_mpwTimer: |
197 | mpwTimer->stop(); | 198 | mpwTimer->stop(); |
198 | break; | 199 | break; |
199 | case id_autoLockTimer: | 200 | case id_autoLockTimer: |
200 | autoLockTimer->stop(); | 201 | autoLockTimer->stop(); |
201 | break; | 202 | break; |
202 | case id_metaCheckTimer: | 203 | case id_metaCheckTimer: |
203 | metaCheckTimer->stop(); | 204 | metaCheckTimer->stop(); |
204 | break; | 205 | break; |
205 | } | 206 | } |
206 | } | 207 | } |
207 | 208 | ||
208 | void DocTimer::getLock(TimerIDs timer) | 209 | void DocTimer::getLock(TimerIDs timer) |
209 | { | 210 | { |
210 | switch (timer) { | 211 | switch (timer) { |
211 | case id_mpwTimer: | 212 | case id_mpwTimer: |
212 | ++mpwLock; | 213 | ++mpwLock; |
213 | break; | 214 | break; |
214 | case id_autoLockTimer: | 215 | case id_autoLockTimer: |
215 | ++autoLockLock; | 216 | ++autoLockLock; |
216 | break; | 217 | break; |
217 | case id_metaCheckTimer: | 218 | case id_metaCheckTimer: |
218 | ++metaCheckLock; | 219 | ++metaCheckLock; |
219 | break; | 220 | break; |
220 | } | 221 | } |
221 | } | 222 | } |
222 | 223 | ||
223 | void DocTimer::putLock(TimerIDs timer) | 224 | void DocTimer::putLock(TimerIDs timer) |
224 | { | 225 | { |
225 | switch (timer) { | 226 | switch (timer) { |
226 | case id_mpwTimer: | 227 | case id_mpwTimer: |
227 | if (mpwLock) | 228 | if (mpwLock) |
228 | --mpwLock; | 229 | --mpwLock; |
229 | break; | 230 | break; |
230 | case id_autoLockTimer: | 231 | case id_autoLockTimer: |
231 | if (autoLockLock) | 232 | if (autoLockLock) |
232 | --autoLockLock; | 233 | --autoLockLock; |
233 | break; | 234 | break; |
234 | case id_metaCheckTimer: | 235 | case id_metaCheckTimer: |
235 | if (metaCheckLock) | 236 | if (metaCheckLock) |
236 | --metaCheckLock; | 237 | --metaCheckLock; |
237 | break; | 238 | break; |
238 | } | 239 | } |
239 | } | 240 | } |
240 | 241 | ||
241 | void DocTimer::mpwTimeout() | 242 | void DocTimer::mpwTimeout() |
242 | { | 243 | { |
243 | if (mpwLock) { | 244 | if (mpwLock) { |
244 | mpwTimer->start(1000, true); | 245 | mpwTimer->start(1000, true); |
245 | return; | 246 | return; |
246 | } | 247 | } |
247 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 248 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
248 | } | 249 | } |
249 | 250 | ||
250 | void DocTimer::autoLockTimeout() | 251 | void DocTimer::autoLockTimeout() |
251 | { | 252 | { |
252 | if (autoLockLock) { | 253 | if (autoLockLock) { |
@@ -316,388 +317,390 @@ PwMDoc::PwMDoc(QObject *parent, const char *name) | |||
316 | timer()->start(DocTimer::id_autoLockTimer); | 317 | timer()->start(DocTimer::id_autoLockTimer); |
317 | timer()->start(DocTimer::id_metaCheckTimer); | 318 | timer()->start(DocTimer::id_metaCheckTimer); |
318 | addCategory(DEFAULT_CATEGORY, 0, false); | 319 | addCategory(DEFAULT_CATEGORY, 0, false); |
319 | listView = 0; | 320 | listView = 0; |
320 | emit docCreated(this); | 321 | emit docCreated(this); |
321 | } | 322 | } |
322 | 323 | ||
323 | PwMDoc::~PwMDoc() | 324 | PwMDoc::~PwMDoc() |
324 | { | 325 | { |
325 | emit docClosed(this); | 326 | emit docClosed(this); |
326 | getOpenDocList()->del(this); | 327 | getOpenDocList()->del(this); |
327 | delete _timer; | 328 | delete _timer; |
328 | } | 329 | } |
329 | 330 | ||
330 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) | 331 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) |
331 | { | 332 | { |
332 | PwMerror ret, e; | 333 | PwMerror ret, e; |
333 | string serialized; | 334 | string serialized; |
334 | QFile f; | 335 | QFile f; |
335 | QString tmpFileMoved(QString::null); | 336 | QString tmpFileMoved(QString::null); |
336 | bool wasDeepLocked; | 337 | bool wasDeepLocked; |
337 | QString savedFilename(filename); | 338 | QString savedFilename(filename); |
338 | 339 | ||
339 | if (!file) { | 340 | if (!file) { |
340 | if (filename == "") | 341 | if (filename == "") |
341 | return e_filename; | 342 | return e_filename; |
342 | if (isDeepLocked()) { | 343 | if (isDeepLocked()) { |
343 | /* We don't need to save any data. | 344 | /* We don't need to save any data. |
344 | * It's already all on disk, because | 345 | * It's already all on disk, because |
345 | * we are deeplocked. | 346 | * we are deeplocked. |
346 | */ | 347 | */ |
347 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 348 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
348 | ret = e_success; | 349 | ret = e_success; |
349 | return ret; | 350 | return ret; |
350 | } | 351 | } |
351 | } else { | 352 | } else { |
352 | if (*file == "" && filename == "") | 353 | if (*file == "" && filename == "") |
353 | return e_filename; | 354 | return e_filename; |
354 | if (*file != "") | 355 | if (*file != "") |
355 | filename = *file; | 356 | filename = *file; |
356 | } | 357 | } |
357 | 358 | ||
358 | wasDeepLocked = isDeepLocked(); | 359 | wasDeepLocked = isDeepLocked(); |
359 | if (wasDeepLocked) { | 360 | if (wasDeepLocked) { |
360 | /* We are deeplocked. That means all data is already | 361 | /* We are deeplocked. That means all data is already |
361 | * on disk. BUT we need to do saving procedure, | 362 | * on disk. BUT we need to do saving procedure, |
362 | * because *file != savedFilename. | 363 | * because *file != savedFilename. |
363 | * Additionally we need to tempoarly restore | 364 | * Additionally we need to tempoarly restore |
364 | * the old "filename", because deepLock() references it. | 365 | * the old "filename", because deepLock() references it. |
365 | */ | 366 | */ |
366 | QString newFilename(filename); | 367 | QString newFilename(filename); |
367 | filename = savedFilename; | 368 | filename = savedFilename; |
368 | getDataChangedLock(); | 369 | getDataChangedLock(); |
369 | e = deepLock(false); | 370 | e = deepLock(false); |
370 | putDataChangedLock(); | 371 | putDataChangedLock(); |
371 | filename = newFilename; | 372 | filename = newFilename; |
372 | switch (e) { | 373 | switch (e) { |
373 | case e_success: | 374 | case e_success: |
374 | break; | 375 | break; |
375 | case e_wrongPw: | 376 | case e_wrongPw: |
376 | case e_noPw: | 377 | case e_noPw: |
377 | emitDataChanged(this); | 378 | emitDataChanged(this); |
378 | return e; | 379 | return e; |
379 | default: | 380 | default: |
380 | emitDataChanged(this); | 381 | emitDataChanged(this); |
381 | return e_openFile; | 382 | return e_openFile; |
382 | } | 383 | } |
383 | } | 384 | } |
384 | 385 | ||
385 | if (!isPwAvailable()) { | 386 | if (!isPwAvailable()) { |
386 | /* password is not available. This means, the | 387 | /* password is not available. This means, the |
387 | * document wasn't saved, yet. | 388 | * document wasn't saved, yet. |
388 | */ | 389 | */ |
389 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 390 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
390 | QString pw(requestNewMpw(&useChipcard)); | 391 | QString pw(requestNewMpw(&useChipcard)); |
391 | if (pw != "") { | 392 | if (pw != "") { |
392 | currentPw = pw; | 393 | currentPw = pw; |
393 | } else { | 394 | } else { |
394 | return e_noPw; | 395 | return e_noPw; |
395 | } | 396 | } |
396 | if (useChipcard) { | 397 | if (useChipcard) { |
397 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 398 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
398 | } else { | 399 | } else { |
399 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 400 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
400 | } | 401 | } |
401 | } | 402 | } |
402 | 403 | ||
403 | int _cryptAlgo = conf()->confGlobCryptAlgo(); | 404 | int _cryptAlgo = conf()->confGlobCryptAlgo(); |
404 | int _hashAlgo = conf()->confGlobHashAlgo(); | 405 | int _hashAlgo = conf()->confGlobHashAlgo(); |
405 | 406 | ||
406 | // sanity check for the selected algorithms | 407 | // sanity check for the selected algorithms |
407 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || | 408 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || |
408 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { | 409 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { |
409 | printWarn("Invalid Crypto-Algorithm selected! " | 410 | printWarn("Invalid Crypto-Algorithm selected! " |
410 | "Config-file seems to be corrupt. " | 411 | "Config-file seems to be corrupt. " |
411 | "Falling back to Blowfish."); | 412 | "Falling back to Blowfish."); |
412 | _cryptAlgo = PWM_CRYPT_BLOWFISH; | 413 | _cryptAlgo = PWM_CRYPT_BLOWFISH; |
413 | } | 414 | } |
414 | if (_hashAlgo < PWM_HASH_SHA1 || | 415 | if (_hashAlgo < PWM_HASH_SHA1 || |
415 | _hashAlgo > PWM_HASH_TIGER) { | 416 | _hashAlgo > PWM_HASH_TIGER) { |
416 | printWarn("Invalid Hash-Algorithm selected! " | 417 | printWarn("Invalid Hash-Algorithm selected! " |
417 | "Config-file seems to be corrupt. " | 418 | "Config-file seems to be corrupt. " |
418 | "Falling back to SHA1."); | 419 | "Falling back to SHA1."); |
419 | _hashAlgo = PWM_HASH_SHA1; | 420 | _hashAlgo = PWM_HASH_SHA1; |
420 | } | 421 | } |
421 | char cryptAlgo = static_cast<char>(_cryptAlgo); | 422 | char cryptAlgo = static_cast<char>(_cryptAlgo); |
422 | char hashAlgo = static_cast<char>(_hashAlgo); | 423 | char hashAlgo = static_cast<char>(_hashAlgo); |
423 | 424 | ||
424 | if (conf()->confGlobMakeFileBackup()) { | 425 | if (conf()->confGlobMakeFileBackup()) { |
425 | if (!backupFile(filename)) | 426 | if (!backupFile(filename)) |
426 | return e_fileBackup; | 427 | return e_fileBackup; |
427 | } | 428 | } |
428 | if (QFile::exists(filename)) { | 429 | if (QFile::exists(filename)) { |
429 | /* Move the existing file to some tmp file. | 430 | /* Move the existing file to some tmp file. |
430 | * When saving file succeeds, delete tmp file. Otherwise | 431 | * When saving file succeeds, delete tmp file. Otherwise |
431 | * move tmp file back. See below. | 432 | * move tmp file back. See below. |
432 | */ | 433 | */ |
433 | Randomizer *rnd = Randomizer::obj(); | 434 | Randomizer *rnd = Randomizer::obj(); |
434 | char rnd_buf[5]; | 435 | char rnd_buf[5]; |
435 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, | 436 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, |
436 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); | 437 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); |
437 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; | 438 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; |
438 | if (!copyFile(filename, tmpFileMoved)) | 439 | if (!copyFile(filename, tmpFileMoved)) |
439 | return e_openFile; | 440 | return e_openFile; |
440 | if (!QFile::remove(filename)) { | 441 | if (!QFile::remove(filename)) { |
441 | printWarn(string("removing orig file ") | 442 | printWarn(string("removing orig file ") |
442 | + filename.latin1() | 443 | + filename.latin1() |
443 | + " failed!"); | 444 | + " failed!"); |
444 | } | 445 | } |
445 | } | 446 | } |
446 | f.setName(filename); | 447 | f.setName(filename); |
447 | if (!f.open(IO_ReadWrite)) { | 448 | if (!f.open(IO_ReadWrite)) { |
448 | ret = e_openFile; | 449 | ret = e_openFile; |
449 | goto out_moveback; | 450 | goto out_moveback; |
450 | } | 451 | } |
451 | e = writeFileHeader(hashAlgo, hashAlgo, | 452 | e = writeFileHeader(hashAlgo, hashAlgo, |
452 | cryptAlgo, compress, | 453 | cryptAlgo, compress, |
453 | ¤tPw, &f); | 454 | ¤tPw, &f); |
454 | if (e == e_hashNotImpl) { | 455 | if (e == e_hashNotImpl) { |
455 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); | 456 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); |
456 | f.close(); | 457 | f.close(); |
457 | ret = e_hashNotImpl; | 458 | ret = e_hashNotImpl; |
458 | goto out_moveback; | 459 | goto out_moveback; |
459 | } else if (e != e_success) { | 460 | } else if (e != e_success) { |
460 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); | 461 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); |
461 | f.close(); | 462 | f.close(); |
462 | ret = e_writeHeader; | 463 | ret = e_writeHeader; |
463 | goto out_moveback; | 464 | goto out_moveback; |
464 | } | 465 | } |
465 | if (!serializeDta(&serialized)) { | 466 | if (!serializeDta(&serialized)) { |
466 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); | 467 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); |
467 | f.close(); | 468 | f.close(); |
468 | ret = e_serializeDta; | 469 | ret = e_serializeDta; |
469 | goto out_moveback; | 470 | goto out_moveback; |
470 | } | 471 | } |
471 | e = writeDataHash(hashAlgo, &serialized, &f); | 472 | e = writeDataHash(hashAlgo, &serialized, &f); |
472 | if (e == e_hashNotImpl) { | 473 | if (e == e_hashNotImpl) { |
473 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); | 474 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); |
474 | f.close(); | 475 | f.close(); |
475 | ret = e_hashNotImpl; | 476 | ret = e_hashNotImpl; |
476 | goto out_moveback; | 477 | goto out_moveback; |
477 | } else if (e != e_success) { | 478 | } else if (e != e_success) { |
478 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); | 479 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); |
479 | f.close(); | 480 | f.close(); |
480 | ret = e_writeHeader; | 481 | ret = e_writeHeader; |
481 | goto out_moveback; | 482 | goto out_moveback; |
482 | } | 483 | } |
483 | if (!compressDta(&serialized, compress)) { | 484 | if (!compressDta(&serialized, compress)) { |
484 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); | 485 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); |
485 | f.close(); | 486 | f.close(); |
486 | ret = e_enc; | 487 | ret = e_enc; |
487 | goto out_moveback; | 488 | goto out_moveback; |
488 | } | 489 | } |
489 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo); | 490 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo); |
490 | if (e == e_weakPw) { | 491 | if (e == e_weakPw) { |
491 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); | 492 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); |
492 | f.close(); | 493 | f.close(); |
493 | ret = e_weakPw; | 494 | ret = e_weakPw; |
494 | goto out_moveback; | 495 | goto out_moveback; |
495 | } else if (e == e_cryptNotImpl) { | 496 | } else if (e == e_cryptNotImpl) { |
496 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); | 497 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); |
497 | f.close(); | 498 | f.close(); |
498 | ret = e_cryptNotImpl; | 499 | ret = e_cryptNotImpl; |
499 | goto out_moveback; | 500 | goto out_moveback; |
500 | } else if (e != e_success) { | 501 | } else if (e != e_success) { |
501 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); | 502 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); |
502 | f.close(); | 503 | f.close(); |
503 | ret = e_enc; | 504 | ret = e_enc; |
504 | goto out_moveback; | 505 | goto out_moveback; |
505 | } | 506 | } |
506 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 507 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
507 | f.close(); | 508 | f.close(); |
509 | #ifndef _WIN32_ | ||
508 | if (chmod(filename.latin1(), | 510 | if (chmod(filename.latin1(), |
509 | conf()->confGlobFilePermissions())) { | 511 | conf()->confGlobFilePermissions())) { |
510 | printWarn(string("chmod failed: ") + strerror(errno)); | 512 | printWarn(string("chmod failed: ") + strerror(errno)); |
511 | } | 513 | } |
514 | #endif | ||
512 | openDocList.edit(this, getTitle().latin1()); | 515 | openDocList.edit(this, getTitle().latin1()); |
513 | if (wasDeepLocked) { | 516 | if (wasDeepLocked) { |
514 | /* Do _not_ save the data with the deepLock() | 517 | /* Do _not_ save the data with the deepLock() |
515 | * call, because this will recurse | 518 | * call, because this will recurse |
516 | * into saveDoc() | 519 | * into saveDoc() |
517 | */ | 520 | */ |
518 | deepLock(true, false); | 521 | deepLock(true, false); |
519 | /* We don't check return value here, because | 522 | /* We don't check return value here, because |
520 | * it won't fail. See NOTE in deepLock() | 523 | * it won't fail. See NOTE in deepLock() |
521 | */ | 524 | */ |
522 | } | 525 | } |
523 | if (tmpFileMoved != QString::null) { | 526 | if (tmpFileMoved != QString::null) { |
524 | // now remove the moved file. | 527 | // now remove the moved file. |
525 | if (!QFile::remove(tmpFileMoved)) { | 528 | if (!QFile::remove(tmpFileMoved)) { |
526 | printWarn(string("removing file ") | 529 | printWarn(string("removing file ") |
527 | + tmpFileMoved.latin1() | 530 | + tmpFileMoved.latin1() |
528 | + " failed!"); | 531 | + " failed!"); |
529 | } | 532 | } |
530 | } | 533 | } |
531 | ret = e_success; | 534 | ret = e_success; |
532 | printDebug(string("writing file { name: ") | 535 | printDebug(string("writing file { name: ") |
533 | + filename.latin1() + " compress: " | 536 | + filename.latin1() + " compress: " |
534 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " | 537 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " |
535 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " | 538 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " |
536 | + tostr(static_cast<int>(hashAlgo)) | 539 | + tostr(static_cast<int>(hashAlgo)) |
537 | + " }"); | 540 | + " }"); |
538 | goto out; | 541 | goto out; |
539 | out_moveback: | 542 | out_moveback: |
540 | if (tmpFileMoved != QString::null) { | 543 | if (tmpFileMoved != QString::null) { |
541 | if (copyFile(tmpFileMoved, filename)) { | 544 | if (copyFile(tmpFileMoved, filename)) { |
542 | if (!QFile::remove(tmpFileMoved)) { | 545 | if (!QFile::remove(tmpFileMoved)) { |
543 | printWarn(string("removing tmp file ") | 546 | printWarn(string("removing tmp file ") |
544 | + filename.latin1() | 547 | + filename.latin1() |
545 | + " failed!"); | 548 | + " failed!"); |
546 | } | 549 | } |
547 | } else { | 550 | } else { |
548 | printWarn(string("couldn't copy file ") | 551 | printWarn(string("couldn't copy file ") |
549 | + tmpFileMoved.latin1() | 552 | + tmpFileMoved.latin1() |
550 | + " back to " | 553 | + " back to " |
551 | + filename.latin1()); | 554 | + filename.latin1()); |
552 | } | 555 | } |
553 | } | 556 | } |
554 | out: | 557 | out: |
555 | return ret; | 558 | return ret; |
556 | } | 559 | } |
557 | 560 | ||
558 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) | 561 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) |
559 | { | 562 | { |
560 | PWM_ASSERT(file); | 563 | PWM_ASSERT(file); |
561 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); | 564 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); |
562 | string decrypted, dataHash; | 565 | string decrypted, dataHash; |
563 | PwMerror ret; | 566 | PwMerror ret; |
564 | char cryptAlgo, dataHashType, compress; | 567 | char cryptAlgo, dataHashType, compress; |
565 | unsigned int headerLen; | 568 | unsigned int headerLen; |
566 | 569 | ||
567 | if (*file == "") | 570 | if (*file == "") |
568 | return e_readFile; | 571 | return e_readFile; |
569 | filename = *file; | 572 | filename = *file; |
570 | /* check if this file is already open. | 573 | /* check if this file is already open. |
571 | * This does not catch symlinks! | 574 | * This does not catch symlinks! |
572 | */ | 575 | */ |
573 | if (!isDeepLocked()) { | 576 | if (!isDeepLocked()) { |
574 | if (getOpenDocList()->find(filename.latin1())) | 577 | if (getOpenDocList()->find(filename.latin1())) |
575 | return e_alreadyOpen; | 578 | return e_alreadyOpen; |
576 | } | 579 | } |
577 | QFile f(filename); | 580 | QFile f(filename); |
578 | 581 | ||
579 | if (openLocked == 2) { | 582 | if (openLocked == 2) { |
580 | // open deep-locked | 583 | // open deep-locked |
581 | if (!QFile::exists(filename)) | 584 | if (!QFile::exists(filename)) |
582 | return e_openFile; | 585 | return e_openFile; |
583 | if (deepLock(true, false) != e_success) | 586 | if (deepLock(true, false) != e_success) |
584 | return e_openFile; | 587 | return e_openFile; |
585 | goto out_success; | 588 | goto out_success; |
586 | } | 589 | } |
587 | 590 | ||
588 | if (!f.open(IO_ReadOnly)) | 591 | if (!f.open(IO_ReadOnly)) |
589 | return e_openFile; | 592 | return e_openFile; |
590 | 593 | ||
591 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, | 594 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, |
592 | &dataHashType, &dataHash, &f); | 595 | &dataHashType, &dataHash, &f); |
593 | if (ret != e_success) { | 596 | if (ret != e_success) { |
594 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); | 597 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); |
595 | f.close(); | 598 | f.close(); |
596 | if (ret == e_wrongPw) { | 599 | if (ret == e_wrongPw) { |
597 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 600 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
598 | return ret; | 601 | return ret; |
599 | } else if (ret == e_noPw || | 602 | } else if (ret == e_noPw || |
600 | ret == e_fileVer || | 603 | ret == e_fileVer || |
601 | ret == e_fileFormat || | 604 | ret == e_fileFormat || |
602 | ret == e_hashNotImpl) { | 605 | ret == e_hashNotImpl) { |
603 | return ret; | 606 | return ret; |
604 | } else | 607 | } else |
605 | return e_readFile; | 608 | return e_readFile; |
606 | } | 609 | } |
607 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); | 610 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); |
608 | if (ret == e_cryptNotImpl) { | 611 | if (ret == e_cryptNotImpl) { |
609 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); | 612 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); |
610 | f.close(); | 613 | f.close(); |
611 | return e_cryptNotImpl; | 614 | return e_cryptNotImpl; |
612 | } else if (ret != e_success) { | 615 | } else if (ret != e_success) { |
613 | printDebug("PwMDoc::openDoc(): decrypt() failed"); | 616 | printDebug("PwMDoc::openDoc(): decrypt() failed"); |
614 | f.close(); | 617 | f.close(); |
615 | return e_readFile; | 618 | return e_readFile; |
616 | } | 619 | } |
617 | if (!decompressDta(&decrypted, compress)) { | 620 | if (!decompressDta(&decrypted, compress)) { |
618 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); | 621 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); |
619 | f.close(); | 622 | f.close(); |
620 | return e_fileCorrupt; | 623 | return e_fileCorrupt; |
621 | } | 624 | } |
622 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); | 625 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); |
623 | if (ret == e_hashNotImpl) { | 626 | if (ret == e_hashNotImpl) { |
624 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); | 627 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); |
625 | f.close(); | 628 | f.close(); |
626 | return e_hashNotImpl; | 629 | return e_hashNotImpl; |
627 | } else if (ret != e_success) { | 630 | } else if (ret != e_success) { |
628 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); | 631 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); |
629 | f.close(); | 632 | f.close(); |
630 | return e_fileCorrupt; | 633 | return e_fileCorrupt; |
631 | } | 634 | } |
632 | if (!deSerializeDta(&decrypted, openLocked == 1)) { | 635 | if (!deSerializeDta(&decrypted, openLocked == 1)) { |
633 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); | 636 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); |
634 | f.close(); | 637 | f.close(); |
635 | return e_readFile; | 638 | return e_readFile; |
636 | } | 639 | } |
637 | f.close(); | 640 | f.close(); |
638 | timer()->start(DocTimer::id_mpwTimer); | 641 | timer()->start(DocTimer::id_mpwTimer); |
639 | timer()->start(DocTimer::id_autoLockTimer); | 642 | timer()->start(DocTimer::id_autoLockTimer); |
640 | out_success: | 643 | out_success: |
641 | openDocList.edit(this, getTitle().latin1()); | 644 | openDocList.edit(this, getTitle().latin1()); |
642 | emit docOpened(this); | 645 | emit docOpened(this); |
643 | return e_success; | 646 | return e_success; |
644 | } | 647 | } |
645 | 648 | ||
646 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 649 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
647 | QString *pw, QFile *f) | 650 | QString *pw, QFile *f) |
648 | { | 651 | { |
649 | PWM_ASSERT(pw); | 652 | PWM_ASSERT(pw); |
650 | PWM_ASSERT(f); | 653 | PWM_ASSERT(f); |
651 | //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else | 654 | //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else |
652 | //Wenn I sync, I open a doc without a view => listView is 0 => Assertion | 655 | //Wenn I sync, I open a doc without a view => listView is 0 => Assertion |
653 | //USPWM_ASSERT(listView); | 656 | //USPWM_ASSERT(listView); |
654 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != | 657 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != |
655 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { | 658 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { |
656 | return e_writeFile; | 659 | return e_writeFile; |
657 | } | 660 | } |
658 | if (f->putch(PWM_FILE_VER) == -1 || | 661 | if (f->putch(PWM_FILE_VER) == -1 || |
659 | f->putch(keyHash) == -1 || | 662 | f->putch(keyHash) == -1 || |
660 | f->putch(dataHash) == -1 || | 663 | f->putch(dataHash) == -1 || |
661 | f->putch(crypt) == -1 || | 664 | f->putch(crypt) == -1 || |
662 | f->putch(compress) == -1 || | 665 | f->putch(compress) == -1 || |
663 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? | 666 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? |
664 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { | 667 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { |
665 | return e_writeFile; | 668 | return e_writeFile; |
666 | } | 669 | } |
667 | 670 | ||
668 | // write bytes of NUL-data. These bytes are reserved for future-use. | 671 | // write bytes of NUL-data. These bytes are reserved for future-use. |
669 | const int bufSize = 64; | 672 | const int bufSize = 64; |
670 | char tmp_buf[bufSize]; | 673 | char tmp_buf[bufSize]; |
671 | memset(tmp_buf, 0x00, bufSize); | 674 | memset(tmp_buf, 0x00, bufSize); |
672 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) | 675 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) |
673 | return e_writeFile; | 676 | return e_writeFile; |
674 | 677 | ||
675 | switch (keyHash) { | 678 | switch (keyHash) { |
676 | case PWM_HASH_SHA1: { | 679 | case PWM_HASH_SHA1: { |
677 | const int hashlen = SHA1_HASH_LEN_BYTE; | 680 | const int hashlen = SHA1_HASH_LEN_BYTE; |
678 | Sha1 hash; | 681 | Sha1 hash; |
679 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 682 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
680 | string ret = hash.sha1_read(); | 683 | string ret = hash.sha1_read(); |
681 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) | 684 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) |
682 | return e_writeFile; | 685 | return e_writeFile; |
683 | break; | 686 | break; |
684 | } | 687 | } |
685 | case PWM_HASH_SHA256: | 688 | case PWM_HASH_SHA256: |
686 | /*... fall through */ | 689 | /*... fall through */ |
687 | case PWM_HASH_SHA384: | 690 | case PWM_HASH_SHA384: |
688 | case PWM_HASH_SHA512: | 691 | case PWM_HASH_SHA512: |
689 | case PWM_HASH_MD5: | 692 | case PWM_HASH_MD5: |
690 | case PWM_HASH_RMD160: | 693 | case PWM_HASH_RMD160: |
691 | case PWM_HASH_TIGER: | 694 | case PWM_HASH_TIGER: |
692 | { | 695 | { |
693 | if (!LibGCryptIf::available()) | 696 | if (!LibGCryptIf::available()) |
694 | return e_hashNotImpl; | 697 | return e_hashNotImpl; |
695 | LibGCryptIf gc; | 698 | LibGCryptIf gc; |
696 | PwMerror err; | 699 | PwMerror err; |
697 | unsigned char *buf; | 700 | unsigned char *buf; |
698 | size_t hashLen; | 701 | size_t hashLen; |
699 | err = gc.hash(&buf, | 702 | err = gc.hash(&buf, |
700 | &hashLen, | 703 | &hashLen, |
701 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 704 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
702 | pw->length(), | 705 | pw->length(), |
703 | keyHash); | 706 | keyHash); |
@@ -2029,440 +2032,444 @@ void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int s | |||
2029 | 2032 | ||
2030 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, | 2033 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, |
2031 | caseSensitive, exactWordMatch, sortByLvp); | 2034 | caseSensitive, exactWordMatch, sortByLvp); |
2032 | } | 2035 | } |
2033 | 2036 | ||
2034 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, | 2037 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, |
2035 | bool exactWordMatch) | 2038 | bool exactWordMatch) |
2036 | { | 2039 | { |
2037 | QString _s1(s1.c_str()); | 2040 | QString _s1(s1.c_str()); |
2038 | QString _s2(s2.c_str()); | 2041 | QString _s2(s2.c_str()); |
2039 | if (!caseSensitive) { | 2042 | if (!caseSensitive) { |
2040 | _s1 = _s1.lower(); | 2043 | _s1 = _s1.lower(); |
2041 | _s2 = _s2.lower(); | 2044 | _s2 = _s2.lower(); |
2042 | } | 2045 | } |
2043 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) | 2046 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) |
2044 | return true; | 2047 | return true; |
2045 | return false; | 2048 | return false; |
2046 | } | 2049 | } |
2047 | 2050 | ||
2048 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) | 2051 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) |
2049 | { | 2052 | { |
2050 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2053 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2051 | end = dti.dta.end(); | 2054 | end = dti.dta.end(); |
2052 | while (i != end) { | 2055 | while (i != end) { |
2053 | if ((*i).name == name.latin1()) { | 2056 | if ((*i).name == name.latin1()) { |
2054 | if (index) { | 2057 | if (index) { |
2055 | *index = i - dti.dta.begin(); | 2058 | *index = i - dti.dta.begin(); |
2056 | } | 2059 | } |
2057 | return true; | 2060 | return true; |
2058 | } | 2061 | } |
2059 | ++i; | 2062 | ++i; |
2060 | } | 2063 | } |
2061 | return false; | 2064 | return false; |
2062 | } | 2065 | } |
2063 | 2066 | ||
2064 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) | 2067 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) |
2065 | { | 2068 | { |
2066 | unsigned int cat = 0; | 2069 | unsigned int cat = 0; |
2067 | 2070 | ||
2068 | if (!findCategory(category, &cat)) | 2071 | if (!findCategory(category, &cat)) |
2069 | return false; | 2072 | return false; |
2070 | 2073 | ||
2071 | return renameCategory(cat, newName); | 2074 | return renameCategory(cat, newName); |
2072 | } | 2075 | } |
2073 | 2076 | ||
2074 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, | 2077 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, |
2075 | bool dontFlagDirty) | 2078 | bool dontFlagDirty) |
2076 | { | 2079 | { |
2077 | if (category > numCategories() - 1) | 2080 | if (category > numCategories() - 1) |
2078 | return false; | 2081 | return false; |
2079 | 2082 | ||
2080 | dti.dta[category].name = newName.latin1(); | 2083 | dti.dta[category].name = newName.latin1(); |
2081 | if (!dontFlagDirty) | 2084 | if (!dontFlagDirty) |
2082 | flagDirty(); | 2085 | flagDirty(); |
2083 | 2086 | ||
2084 | return true; | 2087 | return true; |
2085 | } | 2088 | } |
2086 | 2089 | ||
2087 | bool PwMDoc::delCategory(const QString &category) | 2090 | bool PwMDoc::delCategory(const QString &category) |
2088 | { | 2091 | { |
2089 | unsigned int cat = 0; | 2092 | unsigned int cat = 0; |
2090 | 2093 | ||
2091 | if (!findCategory(category, &cat)) | 2094 | if (!findCategory(category, &cat)) |
2092 | return false; | 2095 | return false; |
2093 | 2096 | ||
2094 | return delCategory(cat); | 2097 | return delCategory(cat); |
2095 | } | 2098 | } |
2096 | 2099 | ||
2097 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) | 2100 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) |
2098 | { | 2101 | { |
2099 | if (category > numCategories() - 1) | 2102 | if (category > numCategories() - 1) |
2100 | return false; | 2103 | return false; |
2101 | 2104 | ||
2102 | // We don't delete it, if it is the last existing | 2105 | // We don't delete it, if it is the last existing |
2103 | // category! Instead we rename it to "Default". | 2106 | // category! Instead we rename it to "Default". |
2104 | if (numCategories() > 1) { | 2107 | if (numCategories() > 1) { |
2105 | dti.dta.erase(dti.dta.begin() + category); | 2108 | dti.dta.erase(dti.dta.begin() + category); |
2106 | } else { | 2109 | } else { |
2107 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); | 2110 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); |
2108 | return true; | 2111 | return true; |
2109 | } | 2112 | } |
2110 | if (!dontFlagDirty) | 2113 | if (!dontFlagDirty) |
2111 | flagDirty(); | 2114 | flagDirty(); |
2112 | 2115 | ||
2113 | return true; | 2116 | return true; |
2114 | } | 2117 | } |
2115 | 2118 | ||
2116 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) | 2119 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) |
2117 | { | 2120 | { |
2118 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), | 2121 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), |
2119 | end = dti.dta.end(), | 2122 | end = dti.dta.end(), |
2120 | i = begin; | 2123 | i = begin; |
2121 | while (i != end) { | 2124 | while (i != end) { |
2122 | if (i->d.empty()) { | 2125 | if (i->d.empty()) { |
2123 | delCategory(begin - i, dontFlagDirty); | 2126 | delCategory(begin - i, dontFlagDirty); |
2124 | } | 2127 | } |
2125 | ++i; | 2128 | ++i; |
2126 | } | 2129 | } |
2127 | } | 2130 | } |
2128 | 2131 | ||
2129 | void PwMDoc::getCategoryList(vector<string> *list) | 2132 | void PwMDoc::getCategoryList(vector<string> *list) |
2130 | { | 2133 | { |
2131 | PWM_ASSERT(list); | 2134 | PWM_ASSERT(list); |
2132 | list->clear(); | 2135 | list->clear(); |
2133 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2136 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2134 | end = dti.dta.end(); | 2137 | end = dti.dta.end(); |
2135 | while (i != end) { | 2138 | while (i != end) { |
2136 | list->push_back(i->name); | 2139 | list->push_back(i->name); |
2137 | ++i; | 2140 | ++i; |
2138 | } | 2141 | } |
2139 | } | 2142 | } |
2140 | 2143 | ||
2141 | void PwMDoc::getCategoryList(QStringList *list) | 2144 | void PwMDoc::getCategoryList(QStringList *list) |
2142 | { | 2145 | { |
2143 | PWM_ASSERT(list); | 2146 | PWM_ASSERT(list); |
2144 | list->clear(); | 2147 | list->clear(); |
2145 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2148 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2146 | end = dti.dta.end(); | 2149 | end = dti.dta.end(); |
2147 | while (i != end) { | 2150 | while (i != end) { |
2148 | #ifndef PWM_EMBEDDED | 2151 | #ifndef PWM_EMBEDDED |
2149 | list->push_back(i->name.c_str()); | 2152 | list->push_back(i->name.c_str()); |
2150 | #else | 2153 | #else |
2151 | list->append(i->name.c_str()); | 2154 | list->append(i->name.c_str()); |
2152 | #endif | 2155 | #endif |
2153 | ++i; | 2156 | ++i; |
2154 | } | 2157 | } |
2155 | } | 2158 | } |
2156 | 2159 | ||
2157 | void PwMDoc::getEntryList(const QString &category, QStringList *list) | 2160 | void PwMDoc::getEntryList(const QString &category, QStringList *list) |
2158 | { | 2161 | { |
2159 | PWM_ASSERT(list); | 2162 | PWM_ASSERT(list); |
2160 | unsigned int cat = 0; | 2163 | unsigned int cat = 0; |
2161 | if (!findCategory(category, &cat)) { | 2164 | if (!findCategory(category, &cat)) { |
2162 | list->clear(); | 2165 | list->clear(); |
2163 | return; | 2166 | return; |
2164 | } | 2167 | } |
2165 | getEntryList(cat, list); | 2168 | getEntryList(cat, list); |
2166 | } | 2169 | } |
2167 | 2170 | ||
2168 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) | 2171 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) |
2169 | { | 2172 | { |
2170 | PWM_ASSERT(list); | 2173 | PWM_ASSERT(list); |
2171 | unsigned int cat = 0; | 2174 | unsigned int cat = 0; |
2172 | if (!findCategory(category, &cat)) { | 2175 | if (!findCategory(category, &cat)) { |
2173 | list->clear(); | 2176 | list->clear(); |
2174 | return; | 2177 | return; |
2175 | } | 2178 | } |
2176 | getEntryList(cat, list); | 2179 | getEntryList(cat, list); |
2177 | } | 2180 | } |
2178 | 2181 | ||
2179 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) | 2182 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) |
2180 | { | 2183 | { |
2181 | PWM_ASSERT(list); | 2184 | PWM_ASSERT(list); |
2182 | list->clear(); | 2185 | list->clear(); |
2183 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2186 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2184 | end = dti.dta[category].d.end(), | 2187 | end = dti.dta[category].d.end(), |
2185 | i = begin; | 2188 | i = begin; |
2186 | while (i != end) { | 2189 | while (i != end) { |
2187 | list->push_back(i->desc); | 2190 | list->push_back(i->desc); |
2188 | ++i; | 2191 | ++i; |
2189 | } | 2192 | } |
2190 | } | 2193 | } |
2191 | 2194 | ||
2192 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) | 2195 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) |
2193 | { | 2196 | { |
2194 | PWM_ASSERT(list); | 2197 | PWM_ASSERT(list); |
2195 | list->clear(); | 2198 | list->clear(); |
2196 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2199 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2197 | end = dti.dta[category].d.end(), | 2200 | end = dti.dta[category].d.end(), |
2198 | i = begin; | 2201 | i = begin; |
2199 | while (i != end) { | 2202 | while (i != end) { |
2200 | #ifndef PWM_EMBEDDED | 2203 | #ifndef PWM_EMBEDDED |
2201 | list->push_back(i->desc.c_str()); | 2204 | list->push_back(i->desc.c_str()); |
2202 | #else | 2205 | #else |
2203 | list->append(i->desc.c_str()); | 2206 | list->append(i->desc.c_str()); |
2204 | #endif | 2207 | #endif |
2205 | ++i; | 2208 | ++i; |
2206 | } | 2209 | } |
2207 | } | 2210 | } |
2208 | 2211 | ||
2209 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) | 2212 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) |
2210 | { | 2213 | { |
2211 | unsigned int cat = 0; | 2214 | unsigned int cat = 0; |
2212 | 2215 | ||
2213 | if (!findCategory(category, &cat)) | 2216 | if (!findCategory(category, &cat)) |
2214 | return false; | 2217 | return false; |
2215 | 2218 | ||
2216 | return execLauncher(cat, entryIndex); | 2219 | return execLauncher(cat, entryIndex); |
2217 | } | 2220 | } |
2218 | 2221 | ||
2219 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) | 2222 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) |
2220 | { | 2223 | { |
2224 | #ifndef _WIN32_ | ||
2221 | if (geteuid() == 0) { | 2225 | if (geteuid() == 0) { |
2222 | rootAlertMsgBox(); | 2226 | rootAlertMsgBox(); |
2223 | return false; | 2227 | return false; |
2224 | } | 2228 | } |
2229 | #endif | ||
2225 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); | 2230 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); |
2226 | bool wasLocked = isLocked(category, entryIndex); | 2231 | bool wasLocked = isLocked(category, entryIndex); |
2227 | 2232 | ||
2228 | if (command.find("$p") != -1) { | 2233 | if (command.find("$p") != -1) { |
2229 | /* the user requested the password to be included | 2234 | /* the user requested the password to be included |
2230 | * into the command. We have to ask for the password, | 2235 | * into the command. We have to ask for the password, |
2231 | * if it's locked. We do that by unlocking the entry | 2236 | * if it's locked. We do that by unlocking the entry |
2232 | */ | 2237 | */ |
2233 | if (!lockAt(category, entryIndex, false)) | 2238 | if (!lockAt(category, entryIndex, false)) |
2234 | return false; | 2239 | return false; |
2235 | } | 2240 | } |
2236 | #ifndef PWM_EMBEDDED | 2241 | #ifndef PWM_EMBEDDED |
2237 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); | 2242 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); |
2238 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); | 2243 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); |
2239 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); | 2244 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); |
2240 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); | 2245 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); |
2241 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); | 2246 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); |
2242 | #else | 2247 | #else |
2243 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); | 2248 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); |
2244 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); | 2249 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); |
2245 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); | 2250 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); |
2246 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); | 2251 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); |
2247 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); | 2252 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); |
2248 | #endif | 2253 | #endif |
2249 | command.append(" &"); | 2254 | command.append(" &"); |
2250 | 2255 | ||
2251 | QString customXterm(conf()->confGlobXtermCommand()); | 2256 | QString customXterm(conf()->confGlobXtermCommand()); |
2252 | if (!customXterm.isEmpty()) | 2257 | if (!customXterm.isEmpty()) |
2253 | command = customXterm + " " + command; | 2258 | command = customXterm + " " + command; |
2254 | 2259 | ||
2255 | system(command.latin1()); | 2260 | system(command.latin1()); |
2256 | 2261 | ||
2257 | lockAt(category, entryIndex, wasLocked); | 2262 | lockAt(category, entryIndex, wasLocked); |
2258 | return true; | 2263 | return true; |
2259 | } | 2264 | } |
2260 | 2265 | ||
2261 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) | 2266 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) |
2262 | { | 2267 | { |
2263 | unsigned int cat = 0; | 2268 | unsigned int cat = 0; |
2264 | 2269 | ||
2265 | if (!findCategory(category, &cat)) | 2270 | if (!findCategory(category, &cat)) |
2266 | return false; | 2271 | return false; |
2267 | 2272 | ||
2268 | return goToURL(cat, entryIndex); | 2273 | return goToURL(cat, entryIndex); |
2269 | } | 2274 | } |
2270 | 2275 | ||
2271 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) | 2276 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) |
2272 | { | 2277 | { |
2278 | #ifndef _WIN32_ | ||
2273 | if (geteuid() == 0) { | 2279 | if (geteuid() == 0) { |
2274 | rootAlertMsgBox(); | 2280 | rootAlertMsgBox(); |
2275 | return false; | 2281 | return false; |
2276 | } | 2282 | } |
2283 | #endif | ||
2277 | QString url(dti.dta[category].d[entryIndex].url.c_str()); | 2284 | QString url(dti.dta[category].d[entryIndex].url.c_str()); |
2278 | if (url.isEmpty()) | 2285 | if (url.isEmpty()) |
2279 | return false; | 2286 | return false; |
2280 | 2287 | ||
2281 | QString customBrowser(conf()->confGlobBrowserCommand()); | 2288 | QString customBrowser(conf()->confGlobBrowserCommand()); |
2282 | if (!customBrowser.isEmpty()) { | 2289 | if (!customBrowser.isEmpty()) { |
2283 | browserProc.clearArguments(); | 2290 | browserProc.clearArguments(); |
2284 | browserProc << customBrowser << url; | 2291 | browserProc << customBrowser << url; |
2285 | if (browserProc.start(KProcess::DontCare)) | 2292 | if (browserProc.start(KProcess::DontCare)) |
2286 | return true; | 2293 | return true; |
2287 | } | 2294 | } |
2288 | 2295 | ||
2289 | browserProc.clearArguments(); | 2296 | browserProc.clearArguments(); |
2290 | browserProc << "konqueror" << url; | 2297 | browserProc << "konqueror" << url; |
2291 | if (browserProc.start(KProcess::DontCare)) | 2298 | if (browserProc.start(KProcess::DontCare)) |
2292 | return true; | 2299 | return true; |
2293 | 2300 | ||
2294 | browserProc.clearArguments(); | 2301 | browserProc.clearArguments(); |
2295 | browserProc << "mozilla" << url; | 2302 | browserProc << "mozilla" << url; |
2296 | if (browserProc.start(KProcess::DontCare)) | 2303 | if (browserProc.start(KProcess::DontCare)) |
2297 | return true; | 2304 | return true; |
2298 | 2305 | ||
2299 | browserProc.clearArguments(); | 2306 | browserProc.clearArguments(); |
2300 | browserProc << "opera" << url; | 2307 | browserProc << "opera" << url; |
2301 | if (browserProc.start(KProcess::DontCare)) | 2308 | if (browserProc.start(KProcess::DontCare)) |
2302 | return true; | 2309 | return true; |
2303 | return false; | 2310 | return false; |
2304 | } | 2311 | } |
2305 | 2312 | ||
2306 | PwMerror PwMDoc::exportToText(const QString *file) | 2313 | PwMerror PwMDoc::exportToText(const QString *file) |
2307 | { | 2314 | { |
2308 | PWM_ASSERT(file); | 2315 | PWM_ASSERT(file); |
2309 | if (QFile::exists(*file)) { | 2316 | if (QFile::exists(*file)) { |
2310 | if (!QFile::remove(*file)) | 2317 | if (!QFile::remove(*file)) |
2311 | return e_accessFile; | 2318 | return e_accessFile; |
2312 | } | 2319 | } |
2313 | QFile f(*file); | 2320 | QFile f(*file); |
2314 | if (!f.open(IO_ReadWrite)) | 2321 | if (!f.open(IO_ReadWrite)) |
2315 | return e_openFile; | 2322 | return e_openFile; |
2316 | 2323 | ||
2317 | if (!unlockAll_tempoary()) { | 2324 | if (!unlockAll_tempoary()) { |
2318 | f.close(); | 2325 | f.close(); |
2319 | return e_lock; | 2326 | return e_lock; |
2320 | } | 2327 | } |
2321 | 2328 | ||
2322 | // write header | 2329 | // write header |
2323 | string header = i18n("Password table generated by\nPwM v").latin1(); | 2330 | string header = i18n("Password table generated by\nPwM v").latin1(); |
2324 | header += PACKAGE_VER; | 2331 | header += PACKAGE_VER; |
2325 | header += i18n("\non ").latin1(); | 2332 | header += i18n("\non ").latin1(); |
2326 | QDate currDate = QDate::currentDate(); | 2333 | QDate currDate = QDate::currentDate(); |
2327 | QTime currTime = QTime::currentTime(); | 2334 | QTime currTime = QTime::currentTime(); |
2328 | 2335 | ||
2329 | #ifndef PWM_EMBEDDED | 2336 | #ifndef PWM_EMBEDDED |
2330 | header += currDate.toString("ddd MMMM d ").latin1(); | 2337 | header += currDate.toString("ddd MMMM d ").latin1(); |
2331 | header += currTime.toString("hh:mm:ss ").latin1(); | 2338 | header += currTime.toString("hh:mm:ss ").latin1(); |
2332 | #else | 2339 | #else |
2333 | QString dfs = KGlobal::locale()->dateFormatShort(); | 2340 | QString dfs = KGlobal::locale()->dateFormatShort(); |
2334 | bool ampm = KGlobal::locale()->use12Clock(); | 2341 | bool ampm = KGlobal::locale()->use12Clock(); |
2335 | KGlobal::locale()->setDateFormatShort("%A %B %d"); | 2342 | KGlobal::locale()->setDateFormatShort("%A %B %d"); |
2336 | KGlobal::locale()->setHore24Format(true); | 2343 | KGlobal::locale()->setHore24Format(true); |
2337 | 2344 | ||
2338 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1(); | 2345 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1(); |
2339 | header += KGlobal::locale()->formatTime(currTime, true).latin1(); | 2346 | header += KGlobal::locale()->formatTime(currTime, true).latin1(); |
2340 | KGlobal::locale()->setDateFormatShort(dfs); | 2347 | KGlobal::locale()->setDateFormatShort(dfs); |
2341 | KGlobal::locale()->setHore24Format(!ampm); | 2348 | KGlobal::locale()->setHore24Format(!ampm); |
2342 | 2349 | ||
2343 | #endif | 2350 | #endif |
2344 | header += tostr(currDate.year()); | 2351 | header += tostr(currDate.year()); |
2345 | header += "\n==============================\n\n"; | 2352 | header += "\n==============================\n\n"; |
2346 | 2353 | ||
2347 | 2354 | ||
2348 | #ifndef PWM_EMBEDDED | 2355 | #ifndef PWM_EMBEDDED |
2349 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { | 2356 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { |
2350 | unlockAll_tempoary(true); | 2357 | unlockAll_tempoary(true); |
2351 | f.close(); | 2358 | f.close(); |
2352 | return e_writeFile; | 2359 | return e_writeFile; |
2353 | } | 2360 | } |
2354 | #else | 2361 | #else |
2355 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { | 2362 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { |
2356 | unlockAll_tempoary(true); | 2363 | unlockAll_tempoary(true); |
2357 | f.close(); | 2364 | f.close(); |
2358 | return e_writeFile; | 2365 | return e_writeFile; |
2359 | } | 2366 | } |
2360 | #endif | 2367 | #endif |
2361 | unsigned int i, numCat = numCategories(); | 2368 | unsigned int i, numCat = numCategories(); |
2362 | unsigned int j, numEnt; | 2369 | unsigned int j, numEnt; |
2363 | string exp; | 2370 | string exp; |
2364 | for (i = 0; i < numCat; ++i) { | 2371 | for (i = 0; i < numCat; ++i) { |
2365 | numEnt = numEntries(i); | 2372 | numEnt = numEntries(i); |
2366 | 2373 | ||
2367 | exp = "\n== Category: "; | 2374 | exp = "\n== Category: "; |
2368 | exp += dti.dta[i].name; | 2375 | exp += dti.dta[i].name; |
2369 | exp += " ==\n"; | 2376 | exp += " ==\n"; |
2370 | #ifndef PWM_EMBEDDED | 2377 | #ifndef PWM_EMBEDDED |
2371 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2378 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2372 | unlockAll_tempoary(true); | 2379 | unlockAll_tempoary(true); |
2373 | f.close(); | 2380 | f.close(); |
2374 | return e_writeFile; | 2381 | return e_writeFile; |
2375 | } | 2382 | } |
2376 | #else | 2383 | #else |
2377 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2384 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2378 | unlockAll_tempoary(true); | 2385 | unlockAll_tempoary(true); |
2379 | f.close(); | 2386 | f.close(); |
2380 | return e_writeFile; | 2387 | return e_writeFile; |
2381 | } | 2388 | } |
2382 | #endif | 2389 | #endif |
2383 | for (j = 0; j < numEnt; ++j) { | 2390 | for (j = 0; j < numEnt; ++j) { |
2384 | exp = "\n-- "; | 2391 | exp = "\n-- "; |
2385 | exp += dti.dta[i].d[j].desc; | 2392 | exp += dti.dta[i].d[j].desc; |
2386 | exp += " --\n"; | 2393 | exp += " --\n"; |
2387 | 2394 | ||
2388 | exp += i18n("Username: ").latin1(); | 2395 | exp += i18n("Username: ").latin1(); |
2389 | exp += dti.dta[i].d[j].name; | 2396 | exp += dti.dta[i].d[j].name; |
2390 | exp += "\n"; | 2397 | exp += "\n"; |
2391 | 2398 | ||
2392 | exp += i18n("Password: ").latin1(); | 2399 | exp += i18n("Password: ").latin1(); |
2393 | exp += dti.dta[i].d[j].pw; | 2400 | exp += dti.dta[i].d[j].pw; |
2394 | exp += "\n"; | 2401 | exp += "\n"; |
2395 | 2402 | ||
2396 | exp += i18n("Comment: ").latin1(); | 2403 | exp += i18n("Comment: ").latin1(); |
2397 | exp += dti.dta[i].d[j].comment; | 2404 | exp += dti.dta[i].d[j].comment; |
2398 | exp += "\n"; | 2405 | exp += "\n"; |
2399 | 2406 | ||
2400 | exp += i18n("URL: ").latin1(); | 2407 | exp += i18n("URL: ").latin1(); |
2401 | exp += dti.dta[i].d[j].url; | 2408 | exp += dti.dta[i].d[j].url; |
2402 | exp += "\n"; | 2409 | exp += "\n"; |
2403 | 2410 | ||
2404 | exp += i18n("Launcher: ").latin1(); | 2411 | exp += i18n("Launcher: ").latin1(); |
2405 | exp += dti.dta[i].d[j].launcher; | 2412 | exp += dti.dta[i].d[j].launcher; |
2406 | exp += "\n"; | 2413 | exp += "\n"; |
2407 | 2414 | ||
2408 | #ifndef PWM_EMBEDDED | 2415 | #ifndef PWM_EMBEDDED |
2409 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2416 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2410 | unlockAll_tempoary(true); | 2417 | unlockAll_tempoary(true); |
2411 | f.close(); | 2418 | f.close(); |
2412 | return e_writeFile; | 2419 | return e_writeFile; |
2413 | } | 2420 | } |
2414 | #else | 2421 | #else |
2415 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2422 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2416 | unlockAll_tempoary(true); | 2423 | unlockAll_tempoary(true); |
2417 | f.close(); | 2424 | f.close(); |
2418 | return e_writeFile; | 2425 | return e_writeFile; |
2419 | } | 2426 | } |
2420 | #endif | 2427 | #endif |
2421 | } | 2428 | } |
2422 | } | 2429 | } |
2423 | unlockAll_tempoary(true); | 2430 | unlockAll_tempoary(true); |
2424 | f.close(); | 2431 | f.close(); |
2425 | 2432 | ||
2426 | return e_success; | 2433 | return e_success; |
2427 | } | 2434 | } |
2428 | 2435 | ||
2429 | PwMerror PwMDoc::importFromText(const QString *file, int format) | 2436 | PwMerror PwMDoc::importFromText(const QString *file, int format) |
2430 | { | 2437 | { |
2431 | PWM_ASSERT(file); | 2438 | PWM_ASSERT(file); |
2432 | if (format == 0) | 2439 | if (format == 0) |
2433 | return importText_PwM(file); | 2440 | return importText_PwM(file); |
2434 | else if (format == -1) { | 2441 | else if (format == -1) { |
2435 | // probe for all formats | 2442 | // probe for all formats |
2436 | if (importText_PwM(file) == e_success) | 2443 | if (importText_PwM(file) == e_success) |
2437 | return e_success; | 2444 | return e_success; |
2438 | dti.clear(); | 2445 | dti.clear(); |
2439 | emitDataChanged(this); | 2446 | emitDataChanged(this); |
2440 | // add next format here... | 2447 | // add next format here... |
2441 | return e_fileFormat; | 2448 | return e_fileFormat; |
2442 | } | 2449 | } |
2443 | return e_invalidArg; | 2450 | return e_invalidArg; |
2444 | } | 2451 | } |
2445 | 2452 | ||
2446 | PwMerror PwMDoc::importText_PwM(const QString *file) | 2453 | PwMerror PwMDoc::importText_PwM(const QString *file) |
2447 | { | 2454 | { |
2448 | #ifndef PWM_EMBEDDED | 2455 | #ifndef PWM_EMBEDDED |
2449 | PWM_ASSERT(file); | 2456 | PWM_ASSERT(file); |
2450 | FILE *f; | 2457 | FILE *f; |
2451 | int tmp; | 2458 | int tmp; |
2452 | ssize_t ret; | 2459 | ssize_t ret; |
2453 | string curCat; | 2460 | string curCat; |
2454 | unsigned int entriesRead = 0; | 2461 | unsigned int entriesRead = 0; |
2455 | PwMDataItem currItem; | 2462 | PwMDataItem currItem; |
2456 | f = fopen(file->latin1(), "r"); | 2463 | f = fopen(file->latin1(), "r"); |
2457 | if (!f) | 2464 | if (!f) |
2458 | return e_openFile; | 2465 | return e_openFile; |
2459 | size_t ch_tmp_size = 1024; | 2466 | size_t ch_tmp_size = 1024; |
2460 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2467 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2461 | if (!ch_tmp) { | 2468 | if (!ch_tmp) { |
2462 | fclose(f); | 2469 | fclose(f); |
2463 | return e_outOfMem; | 2470 | return e_outOfMem; |
2464 | } | 2471 | } |
2465 | 2472 | ||
2466 | // - check header | 2473 | // - check header |
2467 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. | 2474 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. |
2468 | goto formatError; | 2475 | goto formatError; |
diff --git a/pwmanager/pwmanager/spinforsignal.h b/pwmanager/pwmanager/spinforsignal.h index ec6103b..f3cabee 100644 --- a/pwmanager/pwmanager/spinforsignal.h +++ b/pwmanager/pwmanager/spinforsignal.h | |||
@@ -1,55 +1,57 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #ifndef SPINFORSIGNAL_H | 20 | #ifndef SPINFORSIGNAL_H |
21 | #define SPINFORSIGNAL_H | 21 | #define SPINFORSIGNAL_H |
22 | 22 | ||
23 | #include <qobject.h> | 23 | #include <qobject.h> |
24 | 24 | ||
25 | #ifndef _WIN32_ | ||
25 | #include <stdint.h> | 26 | #include <stdint.h> |
27 | #endif | ||
26 | #include <string> | 28 | #include <string> |
27 | using std::string; | 29 | using std::string; |
28 | 30 | ||
29 | /** non-ui-blocking spin for a QT-signal */ | 31 | /** non-ui-blocking spin for a QT-signal */ |
30 | class SpinForSignal : public QObject | 32 | class SpinForSignal : public QObject |
31 | { | 33 | { |
32 | Q_OBJECT | 34 | Q_OBJECT |
33 | public: | 35 | public: |
34 | SpinForSignal(); | 36 | SpinForSignal(); |
35 | ~SpinForSignal() {} | 37 | ~SpinForSignal() {} |
36 | 38 | ||
37 | /** do spin for signal */ | 39 | /** do spin for signal */ |
38 | void spin(uint32_t *u32, string *str); | 40 | void spin(uint32_t *u32, string *str); |
39 | /** cancel spinning */ | 41 | /** cancel spinning */ |
40 | void cancelSpin(); | 42 | void cancelSpin(); |
41 | 43 | ||
42 | public slots: | 44 | public slots: |
43 | void u32_str_slot(uint32_t u32, const string &str); | 45 | void u32_str_slot(uint32_t u32, const string &str); |
44 | 46 | ||
45 | protected: | 47 | protected: |
46 | volatile bool doSpin; | 48 | volatile bool doSpin; |
47 | uint32_t u32_storage; | 49 | uint32_t u32_storage; |
48 | string str_storage; | 50 | string str_storage; |
49 | 51 | ||
50 | protected: | 52 | protected: |
51 | inline void spinSleep(); | 53 | inline void spinSleep(); |
52 | void _spin(); | 54 | void _spin(); |
53 | }; | 55 | }; |
54 | 56 | ||
55 | #endif | 57 | #endif |