aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_rsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/crypto_rsa.c')
-rw-r--r--src/util/crypto_rsa.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index c5a6140f6..650df814e 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -559,7 +559,10 @@ rsa_decode_key (const struct RsaPrivateKeyBinaryEncoded *encoding)
559struct GNUNET_CRYPTO_RsaPrivateKey * 559struct GNUNET_CRYPTO_RsaPrivateKey *
560GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) 560GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
561{ 561{
562#ifndef MINGW
563 // FIXME NILS
562 struct flock fl; 564 struct flock fl;
565#endif
563 struct GNUNET_CRYPTO_RsaPrivateKey *ret; 566 struct GNUNET_CRYPTO_RsaPrivateKey *ret;
564 struct RsaPrivateKeyBinaryEncoded *enc; 567 struct RsaPrivateKeyBinaryEncoded *enc;
565 struct stat sbuf; 568 struct stat sbuf;
@@ -581,11 +584,13 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
581 "open", filename); 584 "open", filename);
582 return NULL; 585 return NULL;
583 } 586 }
587#ifndef MINGW
584 memset (&fl, 0, sizeof (struct flock)); 588 memset (&fl, 0, sizeof (struct flock));
585 fl.l_type = F_WRLCK; 589 fl.l_type = F_WRLCK;
586 fl.l_whence = SEEK_SET; 590 fl.l_whence = SEEK_SET;
587 fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded); 591 fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded);
588 cnt = 0; 592 cnt = 0;
593
589 while (0 != fcntl (fd, F_SETLK, &fl)) 594 while (0 != fcntl (fd, F_SETLK, &fl))
590 { 595 {
591 sleep (1); 596 sleep (1);
@@ -604,6 +609,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
604 fl.l_whence = SEEK_SET; 609 fl.l_whence = SEEK_SET;
605 fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded); 610 fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded);
606 } 611 }
612#endif
607 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 613 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
608 _("Creating a new private key. This may take a while.\n")); 614 _("Creating a new private key. This may take a while.\n"));
609 ret = GNUNET_CRYPTO_rsa_key_create (); 615 ret = GNUNET_CRYPTO_rsa_key_create ();
@@ -612,6 +618,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
612 GNUNET_assert (enc != NULL); 618 GNUNET_assert (enc != NULL);
613 GNUNET_assert (ntohs (enc->len) == WRITE (fd, enc, ntohs (enc->len))); 619 GNUNET_assert (ntohs (enc->len) == WRITE (fd, enc, ntohs (enc->len)));
614 GNUNET_free (enc); 620 GNUNET_free (enc);
621#ifndef MINGW
615 fdatasync (fd); 622 fdatasync (fd);
616 memset (&fl, 0, sizeof (struct flock)); 623 memset (&fl, 0, sizeof (struct flock));
617 fl.l_type = F_UNLCK; 624 fl.l_type = F_UNLCK;
@@ -621,6 +628,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
621 if (0 != fcntl (fd, F_SETLK, &fl)) 628 if (0 != fcntl (fd, F_SETLK, &fl))
622 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 629 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
623 "fcntl", filename); 630 "fcntl", filename);
631#endif
624 GNUNET_assert (0 == CLOSE (fd)); 632 GNUNET_assert (0 == CLOSE (fd));
625 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 633 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
626 _("Stored new private key in `%s'.\n"), filename); 634 _("Stored new private key in `%s'.\n"), filename);
@@ -636,6 +644,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
636 cnt = 0; 644 cnt = 0;
637 while (1) 645 while (1)
638 { 646 {
647#ifndef MINGW
639 memset (&fl, 0, sizeof (struct flock)); 648 memset (&fl, 0, sizeof (struct flock));
640 fl.l_type = F_RDLCK; 649 fl.l_type = F_RDLCK;
641 fl.l_whence = SEEK_SET; 650 fl.l_whence = SEEK_SET;
@@ -658,11 +667,13 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
658 sleep (1); 667 sleep (1);
659 continue; 668 continue;
660 } 669 }
670#endif
661 if (0 != STAT (filename, &sbuf)) 671 if (0 != STAT (filename, &sbuf))
662 { 672 {
663 /* eh, what!? File we opened is now gone!? */ 673 /* eh, what!? File we opened is now gone!? */
664 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 674 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
665 "stat", filename); 675 "stat", filename);
676#ifndef MINGW
666 memset (&fl, 0, sizeof (struct flock)); 677 memset (&fl, 0, sizeof (struct flock));
667 fl.l_type = F_UNLCK; 678 fl.l_type = F_UNLCK;
668 fl.l_whence = SEEK_SET; 679 fl.l_whence = SEEK_SET;
@@ -671,10 +682,12 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
671 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 682 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
672 "fcntl", filename); 683 "fcntl", filename);
673 GNUNET_assert (0 == CLOSE (fd)); 684 GNUNET_assert (0 == CLOSE (fd));
685#endif
674 return NULL; 686 return NULL;
675 } 687 }
676 if (sbuf.st_size < sizeof (struct RsaPrivateKeyBinaryEncoded)) 688 if (sbuf.st_size < sizeof (struct RsaPrivateKeyBinaryEncoded))
677 { 689 {
690#ifndef MINGW
678 /* maybe we got the read lock before the hostkey generating 691 /* maybe we got the read lock before the hostkey generating
679 process had a chance to get the write lock; give it up! */ 692 process had a chance to get the write lock; give it up! */
680 memset (&fl, 0, sizeof (struct flock)); 693 memset (&fl, 0, sizeof (struct flock));
@@ -698,6 +711,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
698 } 711 }
699 sleep (2); /* wait a bit longer! */ 712 sleep (2); /* wait a bit longer! */
700 continue; 713 continue;
714#endif
701 } 715 }
702 break; 716 break;
703 } 717 }
@@ -713,12 +727,14 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
713 filename); 727 filename);
714 GNUNET_free (enc); 728 GNUNET_free (enc);
715 } 729 }
730#ifndef MINGW
716 memset (&fl, 0, sizeof (struct flock)); 731 memset (&fl, 0, sizeof (struct flock));
717 fl.l_type = F_UNLCK; 732 fl.l_type = F_UNLCK;
718 fl.l_whence = SEEK_SET; 733 fl.l_whence = SEEK_SET;
719 fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded); 734 fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded);
720 if (0 != fcntl (fd, F_SETLK, &fl)) 735 if (0 != fcntl (fd, F_SETLK, &fl))
721 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 736 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
737#endif
722 GNUNET_assert (0 == CLOSE (fd)); 738 GNUNET_assert (0 == CLOSE (fd));
723 return ret; 739 return ret;
724} 740}