| 77 struct passwd *pw; |
77 struct passwd *pw; |
| 78 int fd; |
78 int fd; |
| 79 |
79 |
| 80 pw = getpwuid(getuid()); |
80 pw = getpwuid(getuid()); |
| 81 if (!pw) { |
81 if (!pw) { |
| 82 purple_debug_error("silc", "silc: %s\n", strerror(errno)); |
82 purple_debug_error("silc", "silc: %s\n", g_strerror(errno)); |
| 83 return FALSE; |
83 return FALSE; |
| 84 } |
84 } |
| 85 |
85 |
| 86 g_snprintf(filename, sizeof(filename) - 1, "%s", silcpurple_silcdir()); |
86 g_snprintf(filename, sizeof(filename) - 1, "%s", silcpurple_silcdir()); |
| 87 g_snprintf(servfilename, sizeof(servfilename) - 1, "%s" G_DIR_SEPARATOR_S "serverkeys", |
87 g_snprintf(servfilename, sizeof(servfilename) - 1, "%s" G_DIR_SEPARATOR_S "serverkeys", |
| 106 purple_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
106 purple_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 107 filename); |
107 filename); |
| 108 return FALSE; |
108 return FALSE; |
| 109 } |
109 } |
| 110 } else { |
110 } else { |
| 111 purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, strerror(errno)); |
111 purple_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, g_strerror(errno)); |
| 112 return FALSE; |
112 return FALSE; |
| 113 } |
113 } |
| 114 } else { |
114 } else { |
| 115 #ifndef _WIN32 |
115 #ifndef _WIN32 |
| 116 /* Check the owner of the dir */ |
116 /* Check the owner of the dir */ |
| 216 return FALSE; |
216 return FALSE; |
| 217 } |
217 } |
| 218 |
218 |
| 219 if ((g_stat(file_public_key, &st)) == -1) { |
219 if ((g_stat(file_public_key, &st)) == -1) { |
| 220 purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
220 purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
| 221 file_public_key, strerror(errno)); |
221 file_public_key, g_strerror(errno)); |
| 222 return FALSE; |
222 return FALSE; |
| 223 } |
223 } |
| 224 } else { |
224 } else { |
| 225 purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
225 purple_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
| 226 file_public_key, strerror(errno)); |
226 file_public_key, g_strerror(errno)); |
| 227 return FALSE; |
227 return FALSE; |
| 228 } |
228 } |
| 229 } |
229 } |
| 230 |
230 |
| 231 #ifndef _WIN32 |
231 #ifndef _WIN32 |
| 237 #endif |
237 #endif |
| 238 |
238 |
| 239 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
239 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
| 240 if ((fstat(fd, &st)) == -1) { |
240 if ((fstat(fd, &st)) == -1) { |
| 241 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
241 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| 242 file_private_key, strerror(errno)); |
242 file_private_key, g_strerror(errno)); |
| 243 close(fd); |
243 close(fd); |
| 244 return FALSE; |
244 return FALSE; |
| 245 } |
245 } |
| 246 } else if ((g_stat(file_private_key, &st)) == -1) { |
246 } else if ((g_stat(file_private_key, &st)) == -1) { |
| 247 /* If file doesn't exist */ |
247 /* If file doesn't exist */ |
| 259 } |
259 } |
| 260 |
260 |
| 261 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
261 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { |
| 262 if ((fstat(fd, &st)) == -1) { |
262 if ((fstat(fd, &st)) == -1) { |
| 263 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
263 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| 264 file_private_key, strerror(errno)); |
264 file_private_key, g_strerror(errno)); |
| 265 close(fd); |
265 close(fd); |
| 266 return FALSE; |
266 return FALSE; |
| 267 } |
267 } |
| 268 } |
268 } |
| 269 /* This shouldn't really happen because silc_create_key_pair() |
269 /* This shouldn't really happen because silc_create_key_pair() |
| 270 * will set the permissions */ |
270 * will set the permissions */ |
| 271 else if ((g_stat(file_private_key, &st)) == -1) { |
271 else if ((g_stat(file_private_key, &st)) == -1) { |
| 272 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
272 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| 273 file_private_key, strerror(errno)); |
273 file_private_key, g_strerror(errno)); |
| 274 return FALSE; |
274 return FALSE; |
| 275 } |
275 } |
| 276 } else { |
276 } else { |
| 277 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
277 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| 278 file_private_key, strerror(errno)); |
278 file_private_key, g_strerror(errno)); |
| 279 return FALSE; |
279 return FALSE; |
| 280 } |
280 } |
| 281 } |
281 } |
| 282 |
282 |
| 283 #ifndef _WIN32 |
283 #ifndef _WIN32 |
| 345 silc_pubkey = silc_pkcs_get_context(SILC_PKCS_SILC, public_key); |
345 silc_pubkey = silc_pkcs_get_context(SILC_PKCS_SILC, public_key); |
| 346 ident = &silc_pubkey->identifier; |
346 ident = &silc_pubkey->identifier; |
| 347 key_len = silc_pkcs_public_key_get_len(public_key); |
347 key_len = silc_pkcs_public_key_get_len(public_key); |
| 348 |
348 |
| 349 pk = silc_pkcs_public_key_encode(public_key, &pk_len); |
349 pk = silc_pkcs_public_key_encode(public_key, &pk_len); |
| |
350 if (!pk) |
| |
351 return; |
| 350 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); |
352 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); |
| 351 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); |
353 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); |
| |
354 if (!fingerprint || !babbleprint) |
| |
355 return; |
| 352 |
356 |
| 353 s = g_string_new(""); |
357 s = g_string_new(""); |
| 354 if (ident->realname) |
358 if (ident->realname) |
| 355 /* Hint for translators: Please check the tabulator width here and in |
359 /* Hint for translators: Please check the tabulator width here and in |
| 356 the next strings (short strings: 2 tabs, longer strings 1 tab, |
360 the next strings (short strings: 2 tabs, longer strings 1 tab, |