1
0

100-pubkey_path.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. --- a/svr-authpubkey.c
  2. +++ b/svr-authpubkey.c
  3. @@ -218,17 +218,21 @@ 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. -
  15. - /* open the file */
  16. - authfile = fopen(filename, "r");
  17. + if (ses.authstate.pw_uid != 0) {
  18. + /* we don't need to check pw and pw_dir for validity, since
  19. + * its been done in checkpubkeyperms. */
  20. + len = strlen(ses.authstate.pw_dir);
  21. + /* allocate max required pathname storage,
  22. + * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  23. + filename = m_malloc(len + 22);
  24. + snprintf(filename, len + 22, "%s/.ssh/authorized_keys",
  25. + ses.authstate.pw_dir);
  26. +
  27. + /* open the file */
  28. + authfile = fopen(filename, "r");
  29. + } else {
  30. + authfile = fopen("/etc/dropbear/authorized_keys","r");
  31. + }
  32. if (authfile == NULL) {
  33. goto out;
  34. }
  35. @@ -381,26 +385,35 @@ static int checkpubkeyperms() {
  36. goto out;
  37. }
  38. - /* allocate max required pathname storage,
  39. - * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  40. - filename = m_malloc(len + 22);
  41. - strncpy(filename, ses.authstate.pw_dir, len+1);
  42. -
  43. - /* check ~ */
  44. - if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  45. - goto out;
  46. - }
  47. -
  48. - /* check ~/.ssh */
  49. - strncat(filename, "/.ssh", 5); /* strlen("/.ssh") == 5 */
  50. - if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  51. - goto out;
  52. - }
  53. -
  54. - /* now check ~/.ssh/authorized_keys */
  55. - strncat(filename, "/authorized_keys", 16);
  56. - if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  57. - goto out;
  58. + if (ses.authstate.pw_uid == 0) {
  59. + if (checkfileperm("/etc/dropbear") != DROPBEAR_SUCCESS) {
  60. + goto out;
  61. + }
  62. + if (checkfileperm("/etc/dropbear/authorized_keys") != DROPBEAR_SUCCESS) {
  63. + goto out;
  64. + }
  65. + } else {
  66. + /* allocate max required pathname storage,
  67. + * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  68. + filename = m_malloc(len + 22);
  69. + strncpy(filename, ses.authstate.pw_dir, len+1);
  70. +
  71. + /* check ~ */
  72. + if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  73. + goto out;
  74. + }
  75. +
  76. + /* check ~/.ssh */
  77. + strncat(filename, "/.ssh", 5); /* strlen("/.ssh") == 5 */
  78. + if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  79. + goto out;
  80. + }
  81. +
  82. + /* now check ~/.ssh/authorized_keys */
  83. + strncat(filename, "/authorized_keys", 16);
  84. + if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  85. + goto out;
  86. + }
  87. }
  88. /* file looks ok, return success */