pwd_cache.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. (void) pwd;
  40. }
  41. /****************************************************************************
  42. obfuscates a password
  43. ****************************************************************************/
  44. static void pwd_obfuscate(struct pwd_info *pwd)
  45. {
  46. (void) pwd;
  47. }
  48. /****************************************************************************
  49. sets the obfuscation key info
  50. ****************************************************************************/
  51. void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key)
  52. {
  53. (void) pwd;
  54. (void) int_key;
  55. (void) str_key;
  56. }
  57. #if 0
  58. /****************************************************************************
  59. reads a password
  60. ****************************************************************************/
  61. void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt)
  62. {
  63. /* grab a password */
  64. char *user_pass;
  65. pwd_init(pwd);
  66. user_pass = (char*)getpass(passwd_report);
  67. if (user_pass == NULL || user_pass[0] == 0)
  68. {
  69. pwd_set_nullpwd(pwd);
  70. }
  71. else if (do_encrypt)
  72. {
  73. pwd_make_lm_nt_16(pwd, user_pass);
  74. }
  75. else
  76. {
  77. pwd_set_cleartext(pwd, user_pass);
  78. }
  79. }
  80. #endif
  81. /****************************************************************************
  82. stores a cleartext password
  83. ****************************************************************************/
  84. void pwd_set_nullpwd(struct pwd_info *pwd)
  85. {
  86. pwd_init(pwd);
  87. pwd->cleartext = False;
  88. pwd->null_pwd = True;
  89. pwd->crypted = False;
  90. }
  91. /****************************************************************************
  92. stores a cleartext password
  93. ****************************************************************************/
  94. void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
  95. {
  96. pwd_init(pwd);
  97. fstrcpy(pwd->password, clr);
  98. pwd->cleartext = True;
  99. pwd->null_pwd = False;
  100. pwd->crypted = False;
  101. pwd_obfuscate(pwd);
  102. }
  103. /****************************************************************************
  104. gets a cleartext password
  105. ****************************************************************************/
  106. void pwd_get_cleartext(struct pwd_info *pwd, char *clr)
  107. {
  108. pwd_deobfuscate(pwd);
  109. if (pwd->cleartext)
  110. {
  111. fstrcpy(clr, pwd->password);
  112. }
  113. else
  114. {
  115. clr[0] = 0;
  116. }
  117. pwd_obfuscate(pwd);
  118. }
  119. /****************************************************************************
  120. stores lm and nt hashed passwords
  121. ****************************************************************************/
  122. void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
  123. {
  124. pwd_init(pwd);
  125. if (lm_pwd)
  126. {
  127. memcpy(pwd->smb_lm_pwd, lm_pwd, 16);
  128. }
  129. else
  130. {
  131. memset((char *)pwd->smb_lm_pwd, '\0', 16);
  132. }
  133. if (nt_pwd)
  134. {
  135. memcpy(pwd->smb_nt_pwd, nt_pwd, 16);
  136. }
  137. else
  138. {
  139. memset((char *)pwd->smb_nt_pwd, '\0', 16);
  140. }
  141. pwd->null_pwd = False;
  142. pwd->cleartext = False;
  143. pwd->crypted = False;
  144. pwd_obfuscate(pwd);
  145. }
  146. /****************************************************************************
  147. gets lm and nt hashed passwords
  148. ****************************************************************************/
  149. void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
  150. {
  151. pwd_deobfuscate(pwd);
  152. if (lm_pwd != NULL)
  153. {
  154. memcpy(lm_pwd, pwd->smb_lm_pwd, 16);
  155. }
  156. if (nt_pwd != NULL)
  157. {
  158. memcpy(nt_pwd, pwd->smb_nt_pwd, 16);
  159. }
  160. pwd_obfuscate(pwd);
  161. }
  162. /****************************************************************************
  163. makes lm and nt hashed passwords
  164. ****************************************************************************/
  165. void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr)
  166. {
  167. pwd_init(pwd);
  168. nt_lm_owf_gen(clr, pwd->smb_nt_pwd, pwd->smb_lm_pwd);
  169. pwd->null_pwd = False;
  170. pwd->cleartext = False;
  171. pwd->crypted = False;
  172. pwd_obfuscate(pwd);
  173. }
  174. /****************************************************************************
  175. makes lm and nt OWF crypts
  176. ****************************************************************************/
  177. void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8])
  178. {
  179. pwd_deobfuscate(pwd);
  180. #ifdef DEBUG_PASSWORD
  181. DEBUG(100,("client cryptkey: "));
  182. dump_data(100, (char *)cryptkey, 8);
  183. #endif
  184. SMBOWFencrypt(pwd->smb_nt_pwd, cryptkey, pwd->smb_nt_owf);
  185. #ifdef DEBUG_PASSWORD
  186. DEBUG(100,("nt_owf_passwd: "));
  187. dump_data(100, (char *)pwd->smb_nt_owf, sizeof(pwd->smb_nt_owf));
  188. DEBUG(100,("nt_sess_pwd: "));
  189. dump_data(100, (char *)pwd->smb_nt_pwd, sizeof(pwd->smb_nt_pwd));
  190. #endif
  191. SMBOWFencrypt(pwd->smb_lm_pwd, cryptkey, pwd->smb_lm_owf);
  192. #ifdef DEBUG_PASSWORD
  193. DEBUG(100,("lm_owf_passwd: "));
  194. dump_data(100, (char *)pwd->smb_lm_owf, sizeof(pwd->smb_lm_owf));
  195. DEBUG(100,("lm_sess_pwd: "));
  196. dump_data(100, (char *)pwd->smb_lm_pwd, sizeof(pwd->smb_lm_pwd));
  197. #endif
  198. pwd->crypted = True;
  199. pwd_obfuscate(pwd);
  200. }
  201. /****************************************************************************
  202. gets lm and nt crypts
  203. ****************************************************************************/
  204. void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
  205. {
  206. pwd_deobfuscate(pwd);
  207. if (lm_owf != NULL)
  208. {
  209. memcpy(lm_owf, pwd->smb_lm_owf, 24);
  210. }
  211. if (nt_owf != NULL)
  212. {
  213. memcpy(nt_owf, pwd->smb_nt_owf, 24);
  214. }
  215. pwd_obfuscate(pwd);
  216. }