patch-svr-authpubkey_c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. --- dropbear-2017.75.orig/svr-authpubkey.c 2017-05-18 16:47:02.000000000 +0200
  2. +++ dropbear-2017.75/svr-authpubkey.c 2017-05-24 00:12:02.175883130 +0200
  3. @@ -220,24 +220,31 @@ static int checkpubkey(char* algo, unsig
  4. goto out;
  5. }
  6. - /* we don't need to check pw and pw_dir for validity, since
  7. - * its been done in checkpubkeyperms. */
  8. - len = strlen(ses.authstate.pw_dir);
  9. - /* allocate max required pathname storage,
  10. - * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  11. - filename = m_malloc(len + 22);
  12. - snprintf(filename, len + 22, "%s/.ssh/authorized_keys",
  13. - ses.authstate.pw_dir);
  14. + /* special case for root authorized_keys in /etc/dropbear/authorized_keys */
  15. + if (ses.authstate.pw_uid != 0) {
  16. - /* open the file as the authenticating user. */
  17. - origuid = getuid();
  18. - origgid = getgid();
  19. - if ((setegid(ses.authstate.pw_gid)) < 0 ||
  20. - (seteuid(ses.authstate.pw_uid)) < 0) {
  21. - dropbear_exit("Failed to set euid");
  22. - }
  23. + /* we don't need to check pw and pw_dir for validity, since
  24. + * its been done in checkpubkeyperms. */
  25. + len = strlen(ses.authstate.pw_dir);
  26. + /* allocate max required pathname storage,
  27. + * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  28. + filename = m_malloc(len + 22);
  29. + snprintf(filename, len + 22, "%s/.ssh/authorized_keys",
  30. + ses.authstate.pw_dir);
  31. - authfile = fopen(filename, "r");
  32. + /* open the file as the authenticating user. */
  33. + origuid = getuid();
  34. + origgid = getgid();
  35. + if ((setegid(ses.authstate.pw_gid)) < 0 ||
  36. + (seteuid(ses.authstate.pw_uid)) < 0) {
  37. + dropbear_exit("Failed to set euid");
  38. + }
  39. +
  40. + authfile = fopen(filename, "r");
  41. +
  42. + } else {
  43. + authfile = fopen("/etc/dropbear/authorized_keys","r");
  44. + }
  45. if ((seteuid(origuid)) < 0 ||
  46. (setegid(origgid)) < 0) {
  47. @@ -396,26 +403,39 @@ static int checkpubkeyperms() {
  48. goto out;
  49. }
  50. - /* allocate max required pathname storage,
  51. - * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  52. - filename = m_malloc(len + 22);
  53. - strncpy(filename, ses.authstate.pw_dir, len+1);
  54. + if (ses.authstate.pw_uid != 0) {
  55. - /* check ~ */
  56. - if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  57. - goto out;
  58. - }
  59. + /* allocate max required pathname storage,
  60. + * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  61. + filename = m_malloc(len + 22);
  62. + strncpy(filename, ses.authstate.pw_dir, len+1);
  63. - /* check ~/.ssh */
  64. - strncat(filename, "/.ssh", 5); /* strlen("/.ssh") == 5 */
  65. - if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  66. - goto out;
  67. - }
  68. + /* check ~ */
  69. + if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  70. + goto out;
  71. + }
  72. +
  73. + /* check ~/.ssh */
  74. + strncat(filename, "/.ssh", 5); /* strlen("/.ssh") == 5 */
  75. + if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  76. + goto out;
  77. + }
  78. +
  79. + /* now check ~/.ssh/authorized_keys */
  80. + strncat(filename, "/authorized_keys", 16);
  81. + if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  82. + goto out;
  83. + }
  84. +
  85. + } else {
  86. +
  87. + if (checkfileperm("/etc/dropbear") != DROPBEAR_SUCCESS) {
  88. + goto out;
  89. + }
  90. + if (checkfileperm("/etc/dropbear/authorized_keys") != DROPBEAR_SUCCESS) {
  91. + goto out;
  92. + }
  93. - /* now check ~/.ssh/authorized_keys */
  94. - strncat(filename, "/authorized_keys", 16);
  95. - if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  96. - goto out;
  97. }
  98. /* file looks ok, return success */