| 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 GNU General Public License for more details. |
16 GNU General Public License for more details. |
| 17 |
17 |
| 18 */ |
18 */ |
| 19 |
19 |
| 20 #include "internal.h" |
20 #ifdef HAVE_CONFIG_H |
| 21 #include <purple.h> |
21 # include <config.h> |
| 22 |
22 #endif |
| 23 PURPLE_BEGIN_IGNORE_CAST_ALIGN |
23 |
| 24 #include "silc.h" |
24 #ifdef HAVE_FCNTL_H |
| 25 PURPLE_END_IGNORE_CAST_ALIGN |
25 # include <fcntl.h> |
| 26 #include "silcclient.h" |
26 #endif |
| |
27 |
| |
28 #include <glib/gi18n-lib.h> |
| |
29 #include <glib/gstdio.h> |
| |
30 |
| 27 #include "silcpurple.h" |
31 #include "silcpurple.h" |
| 28 |
32 |
| 29 /**************************** Utility Routines *******************************/ |
33 /**************************** Utility Routines *******************************/ |
| 30 |
34 |
| 31 static char str[256], str2[256]; |
35 static char str[256], str2[256]; |
| 65 } |
69 } |
| 66 |
70 |
| 67 return FALSE; |
71 return FALSE; |
| 68 } |
72 } |
| 69 |
73 |
| |
74 /* A fstat alternative, like g_stat for stat. */ |
| |
75 static int |
| |
76 silcpurple_fstat(int fd, GStatBuf *st) |
| |
77 { |
| |
78 int ret; |
| |
79 |
| |
80 g_return_val_if_fail(st != NULL, -1); |
| |
81 |
| |
82 #ifdef _WIN32 |
| |
83 ret = _fstat(fd, st); |
| |
84 #else |
| |
85 ret = fstat(fd, st); |
| |
86 #endif |
| |
87 |
| |
88 return ret; |
| |
89 } |
| |
90 |
| 70 /* This checks stats for various SILC files and directories. First it |
91 /* This checks stats for various SILC files and directories. First it |
| 71 checks if ~/.silc directory exist and is owned by the correct user. If |
92 checks if ~/.silc directory exist and is owned by the correct user. If |
| 72 it doesn't exist, it will create the directory. After that it checks if |
93 it doesn't exist, it will create the directory. After that it checks if |
| 73 user's Public and Private key files exists and creates them if needed. */ |
94 user's Public and Private key files exists and creates them if needed. */ |
| 74 |
95 |
| 190 return FALSE; |
211 return FALSE; |
| 191 } |
212 } |
| 192 #endif |
213 #endif |
| 193 |
214 |
| 194 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
215 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
| 195 if (_purple_fstat(fd, &st) == -1) { |
216 if (silcpurple_fstat(fd, &st) == -1) { |
| 196 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
217 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| 197 file_private_key, g_strerror(errno)); |
218 file_private_key, g_strerror(errno)); |
| 198 close(fd); |
219 close(fd); |
| 199 return FALSE; |
220 return FALSE; |
| 200 } |
221 } |
| 212 _("Unable to create SILC key pair")); |
233 _("Unable to create SILC key pair")); |
| 213 return FALSE; |
234 return FALSE; |
| 214 } |
235 } |
| 215 |
236 |
| 216 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
237 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
| 217 if (_purple_fstat(fd, &st) == -1) { |
238 if (silcpurple_fstat(fd, &st) == -1) { |
| 218 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
239 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| 219 file_private_key, g_strerror(errno)); |
240 file_private_key, g_strerror(errno)); |
| 220 close(fd); |
241 close(fd); |
| 221 return FALSE; |
242 return FALSE; |
| 222 } |
243 } |
| 244 |
265 |
| 245 /* Check the permissions for the private key */ |
266 /* Check the permissions for the private key */ |
| 246 if ((st.st_mode & 0777) != 0600) { |
267 if ((st.st_mode & 0777) != 0600) { |
| 247 purple_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
268 purple_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
| 248 "Trying to change them ...\n", file_private_key); |
269 "Trying to change them ...\n", file_private_key); |
| 249 if ((fd == -1) || (g_fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { |
270 if ((fd == -1) || (fchmod(fd, S_IRUSR | S_IWUSR) == -1)) { |
| 250 purple_debug_error("silc", |
271 purple_debug_error("silc", |
| 251 "Failed to change permissions for private key file!\n" |
272 "Failed to change permissions for private key file!\n" |
| 252 "Permissions for your private key file must be 0600.\n"); |
273 "Permissions for your private key file must be 0600.\n"); |
| 253 if (fd != -1) |
274 if (fd != -1) |
| 254 close(fd); |
275 close(fd); |