patch-pwsafe_cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. $OpenBSD: patch-pwsafe_cpp,v 1.2 2005/10/20 09:02:52 mbalmer Exp $
  2. --- pwsafe.cpp.orig Fri Sep 30 12:30:56 2005
  3. +++ pwsafe.cpp Sat Oct 8 22:53:08 2005
  4. @@ -371,8 +371,8 @@ secstring operator+(const secstring& t1,
  5. // The name the program was run with, stripped of any leading path
  6. const char *program_name = "pwsafe"; // make sure program_name always points to something valid so we can use it in constructors of globals
  7. -uid_t saved_uid;
  8. -gid_t saved_gid;
  9. +// uid_t saved_uid;
  10. +// gid_t saved_gid;
  11. // database version
  12. enum Version { VERSION_UNKNOWN, VERSION_1_7, VERSION_2_0 };
  13. @@ -893,14 +893,14 @@ int main(int argc, char **argv) {
  14. try {
  15. try {
  16. - saved_uid = geteuid();
  17. - saved_gid = getegid();
  18. + // saved_uid = geteuid();
  19. + // saved_gid = getegid();
  20. // if we are running suid, drop privileges now; we use seteuid() instead of setuid() so the saved uid remains root and we can become root again in order to mlock()
  21. - if (saved_uid != getuid() || saved_gid != getgid()) {
  22. - setegid(getgid());
  23. - seteuid(getuid());
  24. - }
  25. + // if (saved_uid != getuid() || saved_gid != getgid()) {
  26. + // setegid(getgid());
  27. + // seteuid(getuid());
  28. + // }
  29. #if WITH_READLINE
  30. rl_readline_name = const_cast<char*>(program_name); // so readline() can parse its config files and handle if (pwsafe) sections; some older readline's type rl_readline_name as char*, hence the const_cast
  31. @@ -918,10 +918,11 @@ int main(int argc, char **argv) {
  32. const char* home = getenv("HOME");
  33. if (home && datname[0] != '/') {
  34. - char* dbname = reinterpret_cast<char*>(malloc(strlen(home)+1+strlen(datname)+1));
  35. - strcpy(dbname, home);
  36. - strcat(dbname, "/");
  37. - strcat(dbname, datname);
  38. + size_t dbnamelen = strlen(home)+1+strlen(datname)+1;
  39. + char* dbname = reinterpret_cast<char*>(malloc(dbnamelen));
  40. + strlcpy(dbname, home, dbnamelen);
  41. + strlcat(dbname, "/", dbnamelen);
  42. + strlcat(dbname, datname, dbnamelen);
  43. arg_dbname = dbname;
  44. } else {
  45. // datname is already an absolute path
  46. @@ -1130,7 +1131,7 @@ int main(int argc, char **argv) {
  47. }
  48. // save the rng seed for next time
  49. - if (rng_filename[0]) {
  50. + if (rng_filename[0] && strncmp(rng_filename, "/dev/", 5)) {
  51. int rc = RAND_write_file(rng_filename);
  52. if (arg_verbose > 0) printf("wrote %d bytes to %s\n", rc, rng_filename);
  53. } // else they already got an error above when we tried to read rng_filename
  54. @@ -1619,7 +1621,7 @@ static secstring random_password() {
  55. snprintf(ent_buf, sizeof(ent_buf), "%d", entropy_needed);
  56. ent_buf[sizeof(ent_buf)-1] = '\0';
  57. char len_buf[24];
  58. - snprintf(len_buf, sizeof(len_buf), "%d", pw.length());
  59. + snprintf(len_buf, sizeof(len_buf), "%d", (int)pw.length());
  60. len_buf[sizeof(len_buf)-1] = '\0';
  61. switch (tolower(get1char("Use "+pw+"\ntype "+type_name+", length "+len_buf+", "+ent_buf+" bits of entropy [y/N/ /+/-/q/?] ? ", 'n'))) {
  62. case 'y':
  63. @@ -2380,7 +2382,7 @@ bool DB::open(const secstring* pw_to_try
  64. version = VERSION_1_7;
  65. }
  66. - if (arg_verbose > 1) printf("read in %u entries\n", entries.size());
  67. + if (arg_verbose > 1) printf("read in %u entries\n", (unsigned int)entries.size());
  68. opened = true;
  69. return true;
  70. @@ -2601,7 +2603,7 @@ const DB::Entry& DB::find1(const char* r
  71. for (matches_t::const_iterator i=matches.begin(); i!=matches.end() && count < 3; ++i, ++count)
  72. printf("%s%s", (count?", ":""), (*i)->groupname().c_str());
  73. if (count != matches.size())
  74. - printf(", ... (%u more) ", matches.size()-3);
  75. + printf(", ... (%u more) ", (unsigned int)matches.size()-3);
  76. printf(".\n");
  77. throw FailEx();
  78. }
  79. @@ -3235,26 +3237,26 @@ secalloc::Pool::Pool(size_t n) : next(0)
  80. top = z + ((bottom-z+pagesize+n+pagesize) & ~(pagesize-1)); // round top down to a page boundary
  81. // mark level..top as non-swapabble
  82. - int rc = mlock(level,top-level);
  83. + // int rc = mlock(level,top-level);
  84. // Redhat FC3 returns ENOMEM if not root, not EPERM, so dont bother checking for EPERM error from mlock(); treat any error to mean 'try mlock() against as SUID user'
  85. - if (rc && (saved_uid != geteuid() || saved_gid != getegid())) {
  86. + // if (rc && (saved_uid != geteuid() || saved_gid != getegid())) {
  87. // try again as root (or whoever saved_uid really is)
  88. - if (saved_uid != geteuid())
  89. - seteuid(saved_uid);
  90. - if (saved_gid != getegid())
  91. - setegid(saved_gid);
  92. - rc = mlock(level,top-level);
  93. - setegid(getgid());
  94. - seteuid(getuid());
  95. - }
  96. - if (rc) {
  97. - static bool reported = false;
  98. - if (!reported) {
  99. - if (arg_verbose >= 0)
  100. - fprintf(stderr, "WARNING: %s unable to use secure ram (need to be setuid root)\n", program_name);
  101. - reported = true;
  102. - }
  103. - }
  104. + // if (saved_uid != geteuid())
  105. + // seteuid(saved_uid);
  106. + // if (saved_gid != getegid())
  107. + // setegid(saved_gid);
  108. + // rc = mlock(level,top-level);
  109. + // setegid(getgid());
  110. + // seteuid(getuid());
  111. + // }
  112. + // if (rc) {
  113. + // static bool reported = false;
  114. + // if (!reported) {
  115. + // if (arg_verbose >= 0)
  116. + // fprintf(stderr, "WARNING: %s unable to use secure ram (need to be setuid root)\n", program_name);
  117. + // reported = true;
  118. + // }
  119. + // }
  120. }
  121. secalloc::Pool::~Pool() {