During the helper conversion to C++ I found that the various SMB lookup
helpers had a lot of duplicate code as each included the entire
smbval/smblib validation library as inline code.
I've managed to consolidate just about all of the files into a shared
library but there remains two problems:
1) the MSNT helper which performs proper domain-controller lookups
make use of the available domain and encryption details. And a few other
things the smb_lm helper did not.
unidiff patch attached if anyone who knows what SMB is meant to do can
give their opinion on the best way to merge these bits.
2) I'm unable to actually test the merged code still works. A lot of
castings and void* types have been removed in the upgrade so I want to
be really sure before it gets merged in.
Is anyone able to pull down the lp:~yadi/squid/helpers branch and
give the new basic_msnt_auth and ntlm_smb_lm_auth helpers a whirl?
NP: there is a fair bit of header cleanups still to be done/ongoing
which will require another test later, but I'd like some confidence that
the basic code still works.
Amos
--- valid.cc 2009-12-09 01:08:18.0 +1300
+++ valid.cc.MSNT 2009-12-07 17:49:38.0 +1300
@@ -16,22 +13,24 @@
#include string.h
#endif
+#include smblib-priv.h
+#include smblib.h
+#include valid.h
+
int
Valid_User(char *username, char *password, char *server, char *backup, char *domain)
{
-int pass_is_precrypted_p = 0;
-char const *supportedDialects[] = {
-/* PC NETWORK PROGRAM 1.0, */
-/* MICROSOFT NETWORKS 1.03, */
-/* MICROSOFT NETWORKS 3.0, */
-LANMAN1.0,
-LM1.2X002,
-Samba,
-/* NT LM 0.12, */
-/* NT LANMAN 1.0, */
-NULL
-};
-SMB_Handle_Type con;
+const char *SMB_Prots[] = {PC NETWORK PROGRAM 1.0,
+ MICROSOFT NETWORKS 1.03,
+ MICROSOFT NETWORKS 3.0,
+ LANMAN1.0,
+ LM1.2X002,
+ Samba,
+ NT LM 0.12,
+ NT LANMAN 1.0,
+ NULL
+ };
+void *con;
SMB_Init();
con = SMB_Connect_Server(NULL, server, domain);
@@ -41,16 +40,11 @@
return (NTV_SERVER_ERROR);
}
}
-if (SMB_Negotiate(con, supportedDialects) 0) { /* An error */
-SMB_Discon(con, 0);
-return (NTV_PROTOCOL_ERROR);
-}
-/* Test for a server in share level mode do not authenticate against it */
-if (con-Security == 0) {
+if (SMB_Negotiate(con, SMB_Prots) 0) { /* An error */
SMB_Discon(con, 0);
return (NTV_PROTOCOL_ERROR);
}
-if (SMB_Logon_Server(con, username, password, domain, pass_is_precrypted_p) 0) {
+if (SMB_Logon_Server(con, username, password) 0) {
SMB_Discon(con, 0);
return (NTV_LOGON_ERROR);
}
--- smblib.cc 2009-12-07 16:43:51.0 +1300
+++ smblib.cc.MSNT 2009-12-07 17:21:00.0 +1300
@@ -145,17 +145,7 @@
strcpy(con-LMType, SMBLIB_DEFAULT_LMTYPE);
con-first_tree = con-last_tree = NULL;
-/* ugh. This is horribly broken. */
-/* SMB_Get_My_Name(con - myname, sizeof(con - myname)); */
-/* hacked by Kinkie */
-if (-1 == gethostname(con-myname, sizeof(con-myname))) {
-strcpy(con-myname, unknown);
-} else {
-if (NULL != (address = strchr(con-myname, '.'))) {
-*address = '\0'; /* truncate at first '.' */
-}
-}
-
+SMB_Get_My_Name(con-myname, sizeof(con-myname));
con-port = 0; /* No port selected */
@@ -324,7 +314,7 @@
int
SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName,
- char *PassWord, char *UserDomain, int precrypted)
+ char *PassWord)
{
struct RFCNB_Pkt *pkt;
int param_len, pkt_len, pass_len;
@@ -340,24 +330,22 @@
return (SMBlibE_BAD);
}
-if (precrypted) {
+strcpy(pword, PassWord);
+#ifdef PAM_SMB_ENC_PASS
+if (Con_Handle-encrypt_passwords) {
pass_len = 24;
-memcpy(pword, PassWord, 24);
-} else {
-strcpy(pword, PassWord);
-if (Con_Handle-encrypt_passwords) {
-pass_len = 24;
-SMBencrypt((uchar *) PassWord, (uchar *) Con_Handle-Encrypt_Key, (uchar *) pword);
-} else
-pass_len = strlen(pword);
-}
+SMBencrypt((uchar *) PassWord, (uchar *) Con_Handle-Encrypt_Key, (uchar *) pword);
+} else
+#endif
+pass_len = strlen(pword);
+
/* Now build the correct structure */
if (Con_Handle-protocol SMB_P_NT1) {
param_len = strlen(UserName) + 1 + pass_len + 1 +
-strlen(UserDomain) + 1 +
+strlen(Con_Handle-PDomain) + 1 +