- Timestamp:
- 2011-11-28T08:34:46Z (13 years ago)
- Branches:
- master
- Children:
- 191ac9d
- Parents:
- c77406a (diff), c7b94ef (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
otr.c
rc77406a rddcff199 185 185 /* find a private key by fingerprint prefix (given as any number of hex strings) */ 186 186 OtrlPrivKey *match_privkey(irc_t *irc, const char **args); 187 188 /* check whether a string is safe to use in a path component */ 189 int strsane(const char *s); 187 190 188 191 /* functions to be called for certain events */ … … 275 278 int kg=0; 276 279 277 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, irc->user->nick); 278 e = otrl_privkey_read(irc->otr->us, s); 279 if(e && e!=enoent) { 280 irc_rootmsg(irc, "otr load: %s: %s", s, gcry_strerror(e)); 281 } 282 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->user->nick); 283 e = otrl_privkey_read_fingerprints(irc->otr->us, s, NULL, NULL); 284 if(e && e!=enoent) { 285 irc_rootmsg(irc, "otr load: %s: %s", s, gcry_strerror(e)); 280 if(strsane(irc->user->nick)) { 281 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, irc->user->nick); 282 e = otrl_privkey_read(irc->otr->us, s); 283 if(e && e!=enoent) { 284 irc_rootmsg(irc, "otr load: %s: %s", s, gcry_strerror(e)); 285 } 286 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->user->nick); 287 e = otrl_privkey_read_fingerprints(irc->otr->us, s, NULL, NULL); 288 if(e && e!=enoent) { 289 irc_rootmsg(irc, "otr load: %s: %s", s, gcry_strerror(e)); 290 } 286 291 } 287 292 … … 306 311 gcry_error_t e; 307 312 308 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->user->nick); 309 e = otrl_privkey_write_fingerprints(irc->otr->us, s); 310 if(e) { 311 irc_rootmsg(irc, "otr save: %s: %s", s, gcry_strerror(e)); 312 } 313 chmod(s, 0600); 313 if(strsane(irc->user->nick)) { 314 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->user->nick); 315 e = otrl_privkey_write_fingerprints(irc->otr->us, s); 316 if(e) { 317 irc_rootmsg(irc, "otr save: %s: %s", s, gcry_strerror(e)); 318 } 319 chmod(s, 0600); 320 } 314 321 } 315 322 … … 318 325 char s[512]; 319 326 320 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, nick); 321 unlink(s); 322 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, nick); 323 unlink(s); 327 if(strsane(nick)) { 328 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, nick); 329 unlink(s); 330 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, nick); 331 unlink(s); 332 } 324 333 } 325 334 … … 328 337 char s[512], t[512]; 329 338 330 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, onick); 331 g_snprintf(t, 511, "%s%s.otr_keys", global.conf->configdir, nnick); 332 rename(s,t); 333 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, onick); 334 g_snprintf(t, 511, "%s%s.otr_fprints", global.conf->configdir, nnick); 335 rename(s,t); 339 if(strsane(nnick) && strsane(onick)) { 340 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, onick); 341 g_snprintf(t, 511, "%s%s.otr_keys", global.conf->configdir, nnick); 342 rename(s,t); 343 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, onick); 344 g_snprintf(t, 511, "%s%s.otr_fprints", global.conf->configdir, nnick); 345 rename(s,t); 346 } 336 347 } 337 348 … … 1777 1788 irc_rootmsg(irc, "%s", msg); 1778 1789 if(filename[0]) { 1779 char *kf = g_strdup_printf("%s%s.otr_keys", global.conf->configdir, irc->user->nick); 1780 char *tmp = g_strdup_printf("%s.new", kf); 1781 copyfile(filename, tmp); 1782 unlink(filename); 1783 rename(tmp,kf); 1784 otrl_privkey_read(irc->otr->us, kf); 1785 g_free(kf); 1786 g_free(tmp); 1790 if(strsane(irc->user->nick)) { 1791 char *kf = g_strdup_printf("%s%s.otr_keys", global.conf->configdir, irc->user->nick); 1792 char *tmp = g_strdup_printf("%s.new", kf); 1793 copyfile(filename, tmp); 1794 unlink(filename); 1795 rename(tmp,kf); 1796 otrl_privkey_read(irc->otr->us, kf); 1797 g_free(kf); 1798 g_free(tmp); 1799 } else { 1800 otrl_privkey_read(irc->otr->us, filename); 1801 unlink(filename); 1802 } 1787 1803 } 1788 1804 … … 1859 1875 } 1860 1876 1877 /* check whether a string is safe to use in a path component */ 1878 int strsane(const char *s) 1879 { 1880 return strpbrk(s, "/\\") == NULL; 1881 } 1882 1861 1883 /* vim: set noet ts=4 sw=4: */
Note: See TracChangeset
for help on using the changeset viewer.