100-pubkey_path.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. diff -ur dropbear-0.52.orig/svr-authpubkey.c dropbear-0.52/svr-authpubkey.c
  2. --- dropbear-0.52.orig/svr-authpubkey.c 2009-04-08 00:32:16.000000000 +0200
  3. +++ dropbear-0.52/svr-authpubkey.c 2009-04-08 00:44:11.000000000 +0200
  4. @@ -209,17 +209,21 @@
  5. goto out;
  6. }
  7. - /* we don't need to check pw and pw_dir for validity, since
  8. - * its been done in checkpubkeyperms. */
  9. - len = strlen(ses.authstate.pw_dir);
  10. - /* allocate max required pathname storage,
  11. - * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  12. - filename = m_malloc(len + 22);
  13. - snprintf(filename, len + 22, "%s/.ssh/authorized_keys",
  14. - ses.authstate.pw_dir);
  15. -
  16. - /* open the file */
  17. - authfile = fopen(filename, "r");
  18. + if (ses.authstate.pw_uid != 0) {
  19. + /* we don't need to check pw and pw_dir for validity, since
  20. + * its been done in checkpubkeyperms. */
  21. + len = strlen(ses.authstate.pw_dir);
  22. + /* allocate max required pathname storage,
  23. + * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  24. + filename = m_malloc(len + 22);
  25. + snprintf(filename, len + 22, "%s/.ssh/authorized_keys",
  26. + ses.authstate.pw_dir);
  27. +
  28. + /* open the file */
  29. + authfile = fopen(filename, "r");
  30. + } else {
  31. + authfile = fopen("/etc/dropbear/authorized_keys","r");
  32. + }
  33. if (authfile == NULL) {
  34. goto out;
  35. }
  36. @@ -372,26 +376,35 @@
  37. goto out;
  38. }
  39. - /* allocate max required pathname storage,
  40. - * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  41. - filename = m_malloc(len + 22);
  42. - strncpy(filename, ses.authstate.pw_dir, len+1);
  43. -
  44. - /* check ~ */
  45. - if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  46. - goto out;
  47. - }
  48. -
  49. - /* check ~/.ssh */
  50. - strncat(filename, "/.ssh", 5); /* strlen("/.ssh") == 5 */
  51. - if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  52. - goto out;
  53. - }
  54. -
  55. - /* now check ~/.ssh/authorized_keys */
  56. - strncat(filename, "/authorized_keys", 16);
  57. - if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  58. - goto out;
  59. + if (ses.authstate.pw_uid == 0) {
  60. + if (checkfileperm("/etc/dropbear") != DROPBEAR_SUCCESS) {
  61. + goto out;
  62. + }
  63. + if (checkfileperm("/etc/dropbear/authorized_keys") != DROPBEAR_SUCCESS) {
  64. + goto out;
  65. + }
  66. + } else {
  67. + /* allocate max required pathname storage,
  68. + * = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
  69. + filename = m_malloc(len + 22);
  70. + strncpy(filename, ses.authstate.pw_dir, len+1);
  71. +
  72. + /* check ~ */
  73. + if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  74. + goto out;
  75. + }
  76. +
  77. + /* check ~/.ssh */
  78. + strncat(filename, "/.ssh", 5); /* strlen("/.ssh") == 5 */
  79. + if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  80. + goto out;
  81. + }
  82. +
  83. + /* now check ~/.ssh/authorized_keys */
  84. + strncat(filename, "/authorized_keys", 16);
  85. + if (checkfileperm(filename) != DROPBEAR_SUCCESS) {
  86. + goto out;
  87. + }
  88. }
  89. /* file looks ok, return success */