r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[vlendec/samba-autobuild/.git] / source3 / smbd / sesssetup.c
index 188b7bfb8182bc76f7a0218b916454a2b0847240..320d2835752326f00879fda066cc36d396e11350 100644 (file)
@@ -8,7 +8,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -17,8 +17,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -177,7 +176,7 @@ static BOOL make_krb5_skew_error(DATA_BLOB *pblob_out)
        char *host_princ_s = NULL;
        BOOL ret = False;
 
-       *pblob_out = data_blob(NULL,0);
+       *pblob_out = data_blob_null;
 
        initialize_krb5_error_table();
        kerr = krb5_init_context(&context);
@@ -243,9 +242,9 @@ static int reply_spnego_kerberos(connection_struct *conn,
        PAC_DATA *pac_data;
        DATA_BLOB ap_rep, ap_rep_wrapped, response;
        auth_serversupplied_info *server_info = NULL;
-       DATA_BLOB session_key = data_blob(NULL, 0);
+       DATA_BLOB session_key = data_blob_null;
        uint8 tok_id[2];
-       DATA_BLOB nullblob = data_blob(NULL, 0);
+       DATA_BLOB nullblob = data_blob_null;
        fstring real_username;
        BOOL map_domainuser_to_guest = False;
        BOOL username_was_mapped;
@@ -270,7 +269,9 @@ static int reply_spnego_kerberos(connection_struct *conn,
                return ERROR_NT(nt_status_squash(NT_STATUS_LOGON_FAILURE));
        }
 
-       ret = ads_verify_ticket(mem_ctx, lp_realm(), 0, &ticket, &client, &pac_data, &ap_rep, &session_key);
+       ret = ads_verify_ticket(mem_ctx, lp_realm(), 0, &ticket, 
+                               &client, &pac_data, &ap_rep, 
+                               &session_key, True);
 
        data_blob_free(&ticket);
 
@@ -539,7 +540,7 @@ static int reply_spnego_kerberos(connection_struct *conn,
        if (NT_STATUS_IS_OK(ret)) {
                ap_rep_wrapped = spnego_gen_krb5_wrap(ap_rep, TOK_ID_KRB_AP_REP);
        } else {
-               ap_rep_wrapped = data_blob(NULL, 0);
+               ap_rep_wrapped = data_blob_null;
        }
        response = spnego_gen_auth_response(&ap_rep_wrapped, ret, OID_KERBEROS5_OLD);
        reply_sesssetup_blob(conn, inbuf, outbuf, response, ret);
@@ -582,7 +583,7 @@ static BOOL reply_spnego_ntlmssp(connection_struct *conn, char *inbuf, char *out
 
        if (NT_STATUS_IS_OK(nt_status)) {
                int sess_vuid;
-               DATA_BLOB nullblob = data_blob(NULL, 0);
+               DATA_BLOB nullblob = data_blob_null;
                DATA_BLOB session_key = data_blob((*auth_ntlmssp_state)->ntlmssp_state->session_key.data, (*auth_ntlmssp_state)->ntlmssp_state->session_key.length);
 
                /* register_vuid keeps the server info */
@@ -748,9 +749,9 @@ static int reply_spnego_auth(connection_struct *conn, char *inbuf, char *outbuf,
                             DATA_BLOB blob1,
                             AUTH_NTLMSSP_STATE **auth_ntlmssp_state)
 {
-       DATA_BLOB auth = data_blob(NULL,0);
-       DATA_BLOB auth_reply = data_blob(NULL,0);
-       DATA_BLOB secblob = data_blob(NULL,0);
+       DATA_BLOB auth = data_blob_null;
+       DATA_BLOB auth_reply = data_blob_null;
+       DATA_BLOB secblob = data_blob_null;
        NTSTATUS status = NT_STATUS_INVALID_PARAMETER;
 
        if (!spnego_parse_auth(blob1, &auth)) {
@@ -990,8 +991,7 @@ static NTSTATUS check_spnego_blob_complete(uint16 smbpid, uint16 vuid, DATA_BLOB
        }
 
        /* We must store this blob until complete. */
-       pad = SMB_MALLOC(sizeof(struct pending_auth_data));
-       if (!pad) {
+       if (!(pad = SMB_MALLOC_P(struct pending_auth_data))) {
                return NT_STATUS_NO_MEMORY;
        }
        pad->needed_len = needed_len - pblob->length;
@@ -1028,6 +1028,7 @@ static int reply_sesssetup_and_X_spnego(connection_struct *conn, char *inbuf,
        user_struct *vuser = NULL;
        NTSTATUS status = NT_STATUS_OK;
        uint16 smbpid = SVAL(inbuf,smb_pid);
+       uint16 smb_flag2 = SVAL(inbuf, smb_flg2);
 
        DEBUG(3,("Doing spnego session setup\n"));
 
@@ -1056,9 +1057,12 @@ static int reply_sesssetup_and_X_spnego(connection_struct *conn, char *inbuf,
 #endif
 
        p2 = inbuf + smb_vwv13 + data_blob_len;
-       p2 += srvstr_pull_buf(inbuf, native_os, p2, sizeof(native_os), STR_TERMINATE);
-       p2 += srvstr_pull_buf(inbuf, native_lanman, p2, sizeof(native_lanman), STR_TERMINATE);
-       p2 += srvstr_pull_buf(inbuf, primary_domain, p2, sizeof(primary_domain), STR_TERMINATE);
+       p2 += srvstr_pull_buf(inbuf, smb_flag2, native_os, p2,
+                             sizeof(native_os), STR_TERMINATE);
+       p2 += srvstr_pull_buf(inbuf, smb_flag2, native_lanman, p2,
+                             sizeof(native_lanman), STR_TERMINATE);
+       p2 += srvstr_pull_buf(inbuf, smb_flag2, primary_domain, p2,
+                             sizeof(primary_domain), STR_TERMINATE);
        DEBUG(3,("NativeOS=[%s] NativeLanMan=[%s] PrimaryDomain=[%s]\n", 
                native_os, native_lanman, primary_domain));
 
@@ -1090,7 +1094,7 @@ static int reply_sesssetup_and_X_spnego(connection_struct *conn, char *inbuf,
        }
 
        if (!vuser) {
-               vuid = register_vuid(NULL, data_blob(NULL, 0), data_blob(NULL, 0), NULL);
+               vuid = register_vuid(NULL, data_blob_null, data_blob_null, NULL);
                if (vuid == UID_FIELD_INVALID ) {
                        data_blob_free(&blob1);
                        return ERROR_NT(nt_status_squash(NT_STATUS_INVALID_PARAMETER));
@@ -1175,26 +1179,27 @@ static int reply_sesssetup_and_X_spnego(connection_struct *conn, char *inbuf,
  a new session setup with VC==0 is ignored.
 ****************************************************************************/
 
-static int shutdown_other_smbds(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
-                               void *p)
+static int shutdown_other_smbds(struct db_record *rec,
+                               const struct connections_key *key,
+                               const struct connections_data *crec,
+                               void *private_data)
 {
-       struct sessionid *sessionid = (struct sessionid *)dbuf.dptr;
-       const char *ip = (const char *)p;
+       const char *ip = (const char *)private_data;
 
-       if (!process_exists(pid_to_procid(sessionid->pid))) {
+       if (!process_exists(crec->pid)) {
                return 0;
        }
 
-       if (sessionid->pid == sys_getpid()) {
+       if (procid_is_me(&crec->pid)) {
                return 0;
        }
 
-       if (strcmp(ip, sessionid->ip_addr) != 0) {
+       if (strcmp(ip, crec->addr) != 0) {
                return 0;
        }
 
-       message_send_pid(pid_to_procid(sessionid->pid), MSG_SHUTDOWN,
-                        NULL, 0, True);
+       messaging_send(smbd_messaging_context(), crec->pid, MSG_SHUTDOWN,
+                      &data_blob_null);
        return 0;
 }
 
@@ -1206,7 +1211,7 @@ static void setup_new_vc_session(void)
        invalidate_all_vuids();
 #endif
        if (lp_reset_on_zero_vc()) {
-               session_traverse(shutdown_other_smbds, client_addr());
+               connections_forall(shutdown_other_smbds, client_addr());
        }
 }
 
@@ -1231,6 +1236,7 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
        static BOOL done_sesssetup = False;
        auth_usersupplied_info *user_info = NULL;
        auth_serversupplied_info *server_info = NULL;
+       uint16 smb_flag2 = SVAL(inbuf, smb_flg2);
 
        NTSTATUS nt_status;
 
@@ -1244,12 +1250,12 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
        ZERO_STRUCT(nt_resp);
        ZERO_STRUCT(plaintext_password);
 
-       DEBUG(3,("wct=%d flg2=0x%x\n", CVAL(inbuf, smb_wct), SVAL(inbuf, smb_flg2)));
+       DEBUG(3,("wct=%d flg2=0x%x\n", CVAL(inbuf, smb_wct), smb_flag2));
 
        /* a SPNEGO session setup has 12 command words, whereas a normal
           NT1 session setup has 13. See the cifs spec. */
        if (CVAL(inbuf, smb_wct) == 12 &&
-           (SVAL(inbuf, smb_flg2) & FLAGS2_EXTENDED_SECURITY)) {
+           (smb_flag2 & FLAGS2_EXTENDED_SECURITY)) {
                if (!global_spnego_negotiated) {
                        DEBUG(0,("reply_sesssetup_and_X:  Rejecting attempt at SPNEGO session setup when it was not negoitiated.\n"));
                        return ERROR_NT(nt_status_squash(NT_STATUS_LOGON_FAILURE));
@@ -1281,7 +1287,9 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
                        plaintext_password.data[passlen1] = 0;
                }
 
-               srvstr_pull_buf(inbuf, user, smb_buf(inbuf)+passlen1, sizeof(user), STR_TERMINATE);
+               srvstr_pull_buf(inbuf, smb_flag2, user,
+                               smb_buf(inbuf)+passlen1, sizeof(user),
+                               STR_TERMINATE);
                *domain = 0;
 
        } else {
@@ -1349,7 +1357,7 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
                        nt_resp = data_blob(p+passlen1, passlen2);
                } else {
                        pstring pass;
-                       BOOL unic=SVAL(inbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS;
+                       BOOL unic= smb_flag2 & FLAGS2_UNICODE_STRINGS;
 
 #if 0
                        /* This was the previous fix. Not sure if it's still valid. JRA. */
@@ -1361,21 +1369,28 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
 
                        if (unic && (passlen2 == 0) && passlen1) {
                                /* Only a ascii plaintext password was sent. */
-                               srvstr_pull(inbuf, pass, smb_buf(inbuf), sizeof(pass),
-                                       passlen1, STR_TERMINATE|STR_ASCII);
+                               srvstr_pull(inbuf, smb_flag2, pass,
+                                           smb_buf(inbuf), sizeof(pass),
+                                           passlen1, STR_TERMINATE|STR_ASCII);
                        } else {
-                               srvstr_pull(inbuf, pass, smb_buf(inbuf), 
-                                       sizeof(pass),  unic ? passlen2 : passlen1, 
-                                       STR_TERMINATE);
+                               srvstr_pull(inbuf, smb_flag2, pass,
+                                           smb_buf(inbuf), sizeof(pass),
+                                           unic ? passlen2 : passlen1,
+                                           STR_TERMINATE);
                        }
                        plaintext_password = data_blob(pass, strlen(pass)+1);
                }
                
                p += passlen1 + passlen2;
-               p += srvstr_pull_buf(inbuf, user, p, sizeof(user), STR_TERMINATE);
-               p += srvstr_pull_buf(inbuf, domain, p, sizeof(domain), STR_TERMINATE);
-               p += srvstr_pull_buf(inbuf, native_os, p, sizeof(native_os), STR_TERMINATE);
-               p += srvstr_pull_buf(inbuf, native_lanman, p, sizeof(native_lanman), STR_TERMINATE);
+               p += srvstr_pull_buf(inbuf, smb_flag2, user, p,
+                                    sizeof(user), STR_TERMINATE);
+               p += srvstr_pull_buf(inbuf, smb_flag2, domain, p,
+                                    sizeof(domain), STR_TERMINATE);
+               p += srvstr_pull_buf(inbuf, smb_flag2, native_os,
+                                    p, sizeof(native_os), STR_TERMINATE);
+               p += srvstr_pull_buf(inbuf, smb_flag2,
+                                    native_lanman, p, sizeof(native_lanman),
+                                    STR_TERMINATE);
 
                /* not documented or decoded by Ethereal but there is one more string 
                   in the extra bytes which is the same as the PrimaryDomain when using 
@@ -1385,7 +1400,10 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
                
                byte_count = SVAL(inbuf, smb_vwv13);
                if ( PTR_DIFF(p, save_p) < byte_count)
-                       p += srvstr_pull_buf(inbuf, primary_domain, p, sizeof(primary_domain), STR_TERMINATE);
+                       p += srvstr_pull_buf(inbuf, smb_flag2,
+                                            primary_domain, p,
+                                            sizeof(primary_domain),
+                                            STR_TERMINATE);
                else 
                        fstrcpy( primary_domain, "null" );
 
@@ -1510,7 +1528,7 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
        if (server_info->user_session_key.data) {
                session_key = data_blob(server_info->user_session_key.data, server_info->user_session_key.length);
        } else {
-               session_key = data_blob(NULL, 0);
+               session_key = data_blob_null;
        }
 
        data_blob_clear_free(&plaintext_password);