From: <dat...@us...> - 2006-08-17 01:06:31
|
Revision: 16801 Author: datallah Date: 2006-08-16 18:06:27 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16801&view=rev Log Message: ----------- Make the silc key permission checks safer and cover more cases (e.g. private key exists, but is not readable by you). Modified Paths: -------------- trunk/src/protocols/silc/util.c Modified: trunk/src/protocols/silc/util.c =================================================================== --- trunk/src/protocols/silc/util.c 2006-08-16 20:50:16 UTC (rev 16800) +++ trunk/src/protocols/silc/util.c 2006-08-17 01:06:27 UTC (rev 16801) @@ -234,25 +234,44 @@ } #endif - fd = open(file_private_key, O_RDONLY); - if ((g_stat(file_private_key, &st)) == -1) { + if ((fd = g_open(file_private_key, O_RDONLY)) != -1) { + if ((fstat(fd, &st)) == -1) { + gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", + file_private_key, strerror(errno)); + close(fd); + return FALSE; + } + } else if ((g_stat(file_private_key, &st)) == -1) { /* If file doesn't exist */ if (errno == ENOENT) { gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); - silc_create_key_pair(SILCGAIM_DEF_PKCS, + if (!silc_create_key_pair(SILCGAIM_DEF_PKCS, SILCGAIM_DEF_PKCS_LEN, file_public_key, file_private_key, NULL, (gc->password == NULL) ? "" : gc->password, - NULL, NULL, NULL, FALSE); - if (fd != -1) - close(fd); - fd = open(file_private_key, O_RDONLY); - g_stat(file_private_key, &st); + NULL, NULL, NULL, FALSE)) { + gaim_debug_error("silc", "Couldn't create key pair\n"); + return FALSE; + } + + if ((fd = g_open(file_private_key, O_RDONLY)) != -1) { + if ((fstat(fd, &st)) == -1) { + gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", + file_private_key, strerror(errno)); + close(fd); + return FALSE; + } + } + /* This shouldn't really happen because silc_create_key_pair() + * will set the permissions */ + else if ((g_stat(file_private_key, &st)) == -1) { + gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", + file_private_key, strerror(errno)); + return FALSE; + } } else { gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", file_private_key, strerror(errno)); - if (fd != -1) - close(fd); return FALSE; } } @@ -270,7 +289,7 @@ if ((st.st_mode & 0777) != 0600) { gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" "Trying to change them ...\n", file_private_key); - if ((fd != -1) && (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { + if ((fd == -1) || (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { gaim_debug_error("silc", "Failed to change permissions for private key file!\n" "Permissions for your private key file must be 0600.\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |