100-pubkey_path.patch 2.5 KB

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