pwd_cache.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. Unix SMB/Netbios implementation.
  3. Version 1.9.
  4. Password cacheing. obfuscation is planned
  5. Copyright (C) Luke Kenneth Casson Leighton 1996-1998
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #include "includes.h"
  19. extern int DEBUGLEVEL;
  20. /****************************************************************************
  21. initialises a password structure
  22. ****************************************************************************/
  23. void pwd_init(struct pwd_info *pwd)
  24. {
  25. memset((char *)pwd->password , '\0', sizeof(pwd->password ));
  26. memset((char *)pwd->smb_lm_pwd, '\0', sizeof(pwd->smb_lm_pwd));
  27. memset((char *)pwd->smb_nt_pwd, '\0', sizeof(pwd->smb_nt_pwd));
  28. memset((char *)pwd->smb_lm_owf, '\0', sizeof(pwd->smb_lm_owf));
  29. memset((char *)pwd->smb_nt_owf, '\0', sizeof(pwd->smb_nt_owf));
  30. pwd->null_pwd = True; /* safest option... */
  31. pwd->cleartext = False;
  32. pwd->crypted = False;
  33. }
  34. /****************************************************************************
  35. de-obfuscates a password
  36. ****************************************************************************/
  37. static void pwd_deobfuscate(struct pwd_info *pwd)
  38. {
  39. }
  40. /****************************************************************************
  41. obfuscates a password
  42. ****************************************************************************/
  43. static void pwd_obfuscate(struct pwd_info *pwd)
  44. {
  45. }
  46. /****************************************************************************
  47. sets the obfuscation key info
  48. ****************************************************************************/
  49. void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key)
  50. {
  51. }
  52. #if 0
  53. /****************************************************************************
  54. reads a password
  55. ****************************************************************************/
  56. void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt)
  57. {
  58. /* grab a password */
  59. char *user_pass;
  60. pwd_init(pwd);
  61. user_pass = (char*)getpass(passwd_report);
  62. if (user_pass == NULL || user_pass[0] == 0)
  63. {
  64. pwd_set_nullpwd(pwd);
  65. }
  66. else if (do_encrypt)
  67. {
  68. pwd_make_lm_nt_16(pwd, user_pass);
  69. }
  70. else
  71. {
  72. pwd_set_cleartext(pwd, user_pass);
  73. }
  74. }
  75. #endif
  76. /****************************************************************************
  77. stores a cleartext password
  78. ****************************************************************************/
  79. void pwd_set_nullpwd(struct pwd_info *pwd)
  80. {
  81. pwd_init(pwd);
  82. pwd->cleartext = False;
  83. pwd->null_pwd = True;
  84. pwd->crypted = False;
  85. }
  86. /****************************************************************************
  87. stores a cleartext password
  88. ****************************************************************************/
  89. void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
  90. {
  91. pwd_init(pwd);
  92. fstrcpy(pwd->password, clr);
  93. pwd->cleartext = True;
  94. pwd->null_pwd = False;
  95. pwd->crypted = False;
  96. pwd_obfuscate(pwd);
  97. }
  98. /****************************************************************************
  99. gets a cleartext password
  100. ****************************************************************************/
  101. void pwd_get_cleartext(struct pwd_info *pwd, char *clr)
  102. {
  103. pwd_deobfuscate(pwd);
  104. if (pwd->cleartext)
  105. {
  106. fstrcpy(clr, pwd->password);
  107. }
  108. else
  109. {
  110. clr[0] = 0;
  111. }
  112. pwd_obfuscate(pwd);
  113. }
  114. /****************************************************************************
  115. stores lm and nt hashed passwords
  116. ****************************************************************************/
  117. void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
  118. {
  119. pwd_init(pwd);
  120. if (lm_pwd)
  121. {
  122. memcpy(pwd->smb_lm_pwd, lm_pwd, 16);
  123. }
  124. else
  125. {
  126. memset((char *)pwd->smb_lm_pwd, '\0', 16);
  127. }
  128. if (nt_pwd)
  129. {
  130. memcpy(pwd->smb_nt_pwd, nt_pwd, 16);
  131. }
  132. else
  133. {
  134. memset((char *)pwd->smb_nt_pwd, '\0', 16);
  135. }
  136. pwd->null_pwd = False;
  137. pwd->cleartext = False;
  138. pwd->crypted = False;
  139. pwd_obfuscate(pwd);
  140. }
  141. /****************************************************************************
  142. gets lm and nt hashed passwords
  143. ****************************************************************************/
  144. void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
  145. {
  146. pwd_deobfuscate(pwd);
  147. if (lm_pwd != NULL)
  148. {
  149. memcpy(lm_pwd, pwd->smb_lm_pwd, 16);
  150. }
  151. if (nt_pwd != NULL)
  152. {
  153. memcpy(nt_pwd, pwd->smb_nt_pwd, 16);
  154. }
  155. pwd_obfuscate(pwd);
  156. }
  157. /****************************************************************************
  158. makes lm and nt hashed passwords
  159. ****************************************************************************/
  160. void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr)
  161. {
  162. pwd_init(pwd);
  163. nt_lm_owf_gen(clr, pwd->smb_nt_pwd, pwd->smb_lm_pwd);
  164. pwd->null_pwd = False;
  165. pwd->cleartext = False;
  166. pwd->crypted = False;
  167. pwd_obfuscate(pwd);
  168. }
  169. /****************************************************************************
  170. makes lm and nt OWF crypts
  171. ****************************************************************************/
  172. void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8])
  173. {
  174. pwd_deobfuscate(pwd);
  175. #ifdef DEBUG_PASSWORD
  176. DEBUG(100,("client cryptkey: "));
  177. dump_data(100, (char *)cryptkey, 8);
  178. #endif
  179. SMBOWFencrypt(pwd->smb_nt_pwd, cryptkey, pwd->smb_nt_owf);
  180. #ifdef DEBUG_PASSWORD
  181. DEBUG(100,("nt_owf_passwd: "));
  182. dump_data(100, (char *)pwd->smb_nt_owf, sizeof(pwd->smb_nt_owf));
  183. DEBUG(100,("nt_sess_pwd: "));
  184. dump_data(100, (char *)pwd->smb_nt_pwd, sizeof(pwd->smb_nt_pwd));
  185. #endif
  186. SMBOWFencrypt(pwd->smb_lm_pwd, cryptkey, pwd->smb_lm_owf);
  187. #ifdef DEBUG_PASSWORD
  188. DEBUG(100,("lm_owf_passwd: "));
  189. dump_data(100, (char *)pwd->smb_lm_owf, sizeof(pwd->smb_lm_owf));
  190. DEBUG(100,("lm_sess_pwd: "));
  191. dump_data(100, (char *)pwd->smb_lm_pwd, sizeof(pwd->smb_lm_pwd));
  192. #endif
  193. pwd->crypted = True;
  194. pwd_obfuscate(pwd);
  195. }
  196. /****************************************************************************
  197. gets lm and nt crypts
  198. ****************************************************************************/
  199. void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
  200. {
  201. pwd_deobfuscate(pwd);
  202. if (lm_owf != NULL)
  203. {
  204. memcpy(lm_owf, pwd->smb_lm_owf, 24);
  205. }
  206. if (nt_owf != NULL)
  207. {
  208. memcpy(nt_owf, pwd->smb_nt_owf, 24);
  209. }
  210. pwd_obfuscate(pwd);
  211. }