libpurple/protocols/silc/util.c

changeset 33940
b44d15793c83
parent 33811
5ab172aeeff2
child 34331
c8486462bb63
equal deleted inserted replaced
33939:7255754cc708 33940:b44d15793c83
62 } 62 }
63 63
64 return FALSE; 64 return FALSE;
65 } 65 }
66 66
67 /* there is no fstat alternative for GStatBuf */
68 static int g_fstat(int fd, GStatBuf *st)
69 {
70 struct stat sst;
71 int ret;
72
73 g_return_val_if_fail(st != NULL, -1);
74
75 ret = fstat(fd, &sst);
76 if (ret != 0)
77 return ret;
78
79 memset(st, 0, sizeof(GStatBuf));
80 /* only these two are used here */
81 st->st_uid = sst.st_uid;
82 st->st_mode = sst.st_mode;
83
84 return 0;
85 }
86
67 /* This checks stats for various SILC files and directories. First it 87 /* This checks stats for various SILC files and directories. First it
68 checks if ~/.silc directory exist and is owned by the correct user. If 88 checks if ~/.silc directory exist and is owned by the correct user. If
69 it doesn't exist, it will create the directory. After that it checks if 89 it doesn't exist, it will create the directory. After that it checks if
70 user's Public and Private key files exists and creates them if needed. */ 90 user's Public and Private key files exists and creates them if needed. */
71 91
72 gboolean silcpurple_check_silc_dir(PurpleConnection *gc) 92 gboolean silcpurple_check_silc_dir(PurpleConnection *gc)
73 { 93 {
74 char filename[256], file_public_key[256], file_private_key[256]; 94 char filename[256], file_public_key[256], file_private_key[256];
75 char servfilename[256], clientfilename[256], friendsfilename[256]; 95 char servfilename[256], clientfilename[256], friendsfilename[256];
76 char pkd[256], prd[256]; 96 char pkd[256], prd[256];
77 struct stat st; 97 GStatBuf st;
78 struct passwd *pw; 98 struct passwd *pw;
79 int fd; 99 int fd;
80 100
81 pw = getpwuid(getuid()); 101 pw = getpwuid(getuid());
82 if (!pw) { 102 if (!pw) {
236 return FALSE; 256 return FALSE;
237 } 257 }
238 #endif 258 #endif
239 259
240 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { 260 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) {
241 if ((fstat(fd, &st)) == -1) { 261 if ((g_fstat(fd, &st)) == -1) {
242 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", 262 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n",
243 file_private_key, g_strerror(errno)); 263 file_private_key, g_strerror(errno));
244 close(fd); 264 close(fd);
245 return FALSE; 265 return FALSE;
246 } 266 }
258 _("Unable to create SILC key pair")); 278 _("Unable to create SILC key pair"));
259 return FALSE; 279 return FALSE;
260 } 280 }
261 281
262 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { 282 if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) {
263 if ((fstat(fd, &st)) == -1) { 283 if ((g_fstat(fd, &st)) == -1) {
264 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", 284 purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n",
265 file_private_key, g_strerror(errno)); 285 file_private_key, g_strerror(errno));
266 close(fd); 286 close(fd);
267 return FALSE; 287 return FALSE;
268 } 288 }

mercurial