dns-and-server-ref-counts-20040530
[openafs.git] / src / WINNT / afsd / smb_ioctl.c
index 0fdf2ce..db5cbf0 100644 (file)
@@ -1,16 +1,18 @@
-/* 
- * Copyright (C) 1998, 1989 Transarc Corporation - All rights reserved
- *
- * (C) COPYRIGHT IBM CORPORATION 1987, 1988
- * LICENSED MATERIALS - PROPERTY OF IBM
- *
- *
+/*
+ * Copyright 2000, International Business Machines Corporation and others.
+ * All Rights Reserved.
+ * 
+ * This software has been released under the terms of the IBM Public
+ * License.  For details, see the LICENSE file in the top-level source
+ * directory or online at http://www.openafs.org/dl/license10.html
  */
 
 #include <afs/param.h>
 #include <afs/stds.h>
 
+#ifndef DJGPP
 #include <windows.h>
+#endif /* !DJGPP */
 #include <stdlib.h>
 #include <malloc.h>
 #include <string.h>
@@ -25,6 +27,8 @@
 
 smb_ioctlProc_t *smb_ioctlProcsp[SMB_IOCTL_MAXPROCS];
 
+/*extern unsigned char smb_LANadapter;*/
+
 void smb_InitIoctl(void)
 {
        smb_ioctlProcsp[VIOCGETAL] = cm_IoctlGetACL;
@@ -62,6 +66,14 @@ void smb_InitIoctl(void)
        smb_ioctlProcsp[VIOC_LISTSYMLINK] = cm_IoctlListlink;
        smb_ioctlProcsp[VIOC_DELSYMLINK] = cm_IoctlDeletelink;
        smb_ioctlProcsp[VIOC_MAKESUBMOUNT] = cm_IoctlMakeSubmount;
+       smb_ioctlProcsp[VIOC_GETRXKCRYPT] = cm_IoctlGetRxkcrypt;
+       smb_ioctlProcsp[VIOC_SETRXKCRYPT] = cm_IoctlSetRxkcrypt;
+       smb_ioctlProcsp[VIOC_ISSYMLINK] = cm_IoctlIslink;
+#ifdef DJGPP
+       smb_ioctlProcsp[VIOC_SHUTDOWN] = cm_IoctlShutdown;
+#endif
+       smb_ioctlProcsp[VIOC_TRACEMEMDUMP] = cm_IoctlMemoryDump;
+       smb_ioctlProcsp[VIOC_ISSYMLINK] = cm_IoctlIslink;
 }
 
 /* called to make a fid structure into an IOCTL fid structure */
@@ -77,6 +89,7 @@ void smb_SetupIoctlFid(smb_fid_t *fidp, cm_space_t *prefix)
                iop = malloc(sizeof(*iop));
                 memset(iop, 0, sizeof(*iop));
                 fidp->ioctlp = iop;
+                               iop->fidp = fidp;
         }
        if (prefix) {
                copyPrefix = cm_GetSpace();
@@ -138,6 +151,10 @@ void smb_IoctlPrepareWrite(smb_fid_t *fidp, smb_ioctl_t *ioctlp)
        if (!ioctlp->inAllocp) ioctlp->inAllocp = malloc(SMB_IOCTL_MAXDATA);
         if (!ioctlp->outAllocp) ioctlp->outAllocp = malloc(SMB_IOCTL_MAXDATA);
 
+       /* Fixes fs la problem.  We do a StrToOEM later and if this data isn't initialized we get memory issues. */
+       (void) memset(ioctlp->inAllocp, 0, SMB_IOCTL_MAXDATA);
+       (void) memset(ioctlp->outAllocp, 0, SMB_IOCTL_MAXDATA);
+
        /* and make sure that we've reset our state for the new incoming request */
        if (!(ioctlp->flags & SMB_IOCTLFLAG_DATAIN)) {
                ioctlp->inCopied = 0;
@@ -174,11 +191,6 @@ long smb_IoctlRead(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp,
                return code;
         }
 
-       if (iop->flags & SMB_IOCTLFLAG_LOGON) {
-               vcp->logonDLLUser = userp;
-               userp->flags |= CM_USERFLAG_WASLOGON;
-       }
-
        leftToCopy = (iop->outDatap - iop->outAllocp) - iop->outCopied;
         if (count > leftToCopy) count = leftToCopy;
         
@@ -193,8 +205,8 @@ long smb_IoctlRead(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp,
 
         op = smb_GetSMBData(outp, NULL);
         *op++ = 1;
-        *op++ = count & 0xff;
-        *op++ = (count >> 8) & 0xff;
+        *op++ = (char)(count & 0xff);
+        *op++ = (char)((count >> 8) & 0xff);
         
        /* now copy the data into the response packet */
         memcpy(op, iop->outCopied + iop->outAllocp, count);
@@ -217,7 +229,7 @@ long smb_IoctlWrite(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_packe
         long count;
         long code;
         char *op;
-        long inDataBlockCount;
+        int inDataBlockCount;
 
        code = 0;
        count = smb_GetSMBParm(inp, 1);
@@ -264,15 +276,25 @@ long smb_IoctlV3Read(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_pack
         count = smb_GetSMBParm(inp, 5);
        
        userp = smb_GetUser(vcp, inp);
+       osi_assert(userp != 0);
 
        {
                smb_user_t *uidp;
 
                uidp = smb_FindUID(vcp, ((smb_t *)inp)->uid, 0);
-               osi_Log3(afsd_logp, "Ioctl uid %d user %x name %s",
-                        uidp->userID, userp,
-                        osi_LogSaveString(afsd_logp, uidp->name));
-               smb_ReleaseUID(uidp);
+               if (uidp && uidp->unp)
+                   osi_Log3(afsd_logp, "Ioctl uid %d user %x name %s",
+                            uidp->userID, userp,
+                            osi_LogSaveString(afsd_logp, uidp->unp->name));
+               else {
+                       if (uidp)
+                   osi_Log2(afsd_logp, "Ioctl uid %d user %x no name",
+                            uidp->userID, userp);
+                       else
+                   osi_Log1(afsd_logp, "Ioctl no uid user %x no name",
+                            userp);
+               }
+               if (uidp) smb_ReleaseUID(uidp);
        }
 
        iop->tidPathp = smb_GetTIDPath(vcp, ((smb_t *)inp)->tid);
@@ -284,11 +306,6 @@ long smb_IoctlV3Read(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_pack
                return code;
         }
 
-       if (iop->flags & SMB_IOCTLFLAG_LOGON) {
-               vcp->logonDLLUser = userp;
-               userp->flags |= CM_USERFLAG_WASLOGON;
-       }
-
        leftToCopy = (iop->outDatap - iop->outAllocp) - iop->outCopied;
         if (count > leftToCopy) count = leftToCopy;
         
@@ -332,13 +349,26 @@ long smb_IoctlV3Read(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_pack
 
 /* called from Read Raw to handle IOCTL descriptor reads */
 long smb_IoctlReadRaw(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp,
-       smb_packet_t *outp)
+       smb_packet_t *outp
+#ifdef DJGPP
+, dos_ptr rawBuf
+#endif /* DJGPP */
+)
 {
        smb_ioctl_t *iop;
        long leftToCopy;
        NCB *ncbp;
        long code;
        cm_user_t *userp;
+#ifdef DJGPP
+        dos_ptr dos_ncb;
+
+        if (rawBuf == 0)
+        {
+                osi_Log0(afsd_logp, "Failed to get raw buf for smb_IoctlReadRaw");
+                return -1;
+        }
+#endif /* DJGPP */
 
        iop = fidp->ioctlp;
 
@@ -348,10 +378,17 @@ long smb_IoctlReadRaw(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp,
                smb_user_t *uidp;
 
                uidp = smb_FindUID(vcp, ((smb_t *)inp)->uid, 0);
-               osi_Log3(afsd_logp, "Ioctl uid %d user %x name %s",
-                        uidp->userID, userp,
-                        osi_LogSaveString(afsd_logp, uidp->name));
-               smb_ReleaseUID(uidp);
+               if (uidp && uidp->unp)
+                   osi_Log3(afsd_logp, "Ioctl uid %d user %x name %s",
+                            uidp->userID, userp,
+                            osi_LogSaveString(afsd_logp, uidp->unp->name));
+               else if (uidp)
+                   osi_Log2(afsd_logp, "Ioctl uid %d user %x no name",
+                            uidp->userID, userp);
+        else 
+                   osi_Log1(afsd_logp, "Ioctl no uid user %x no name",
+                            userp);
+               if (uidp) smb_ReleaseUID(uidp);
        }
 
        iop->tidPathp = smb_GetTIDPath(vcp, ((smb_t *)inp)->tid);
@@ -363,11 +400,6 @@ long smb_IoctlReadRaw(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp,
                return code;
        }
 
-       if (iop->flags & SMB_IOCTLFLAG_LOGON) {
-               vcp->logonDLLUser = userp;
-               userp->flags |= CM_USERFLAG_WASLOGON;
-       }
-
        leftToCopy = (iop->outDatap - iop->outAllocp) - iop->outCopied;
 
        ncbp = outp->ncbp;
@@ -376,9 +408,19 @@ long smb_IoctlReadRaw(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp,
        ncbp->ncb_length = (unsigned short) leftToCopy;
        ncbp->ncb_lsn = (unsigned char) vcp->lsn;
        ncbp->ncb_command = NCBSEND;
-       ncbp->ncb_buffer = iop->outCopied + iop->outAllocp;
+    /*ncbp->ncb_lana_num = smb_LANadapter;*/
+       ncbp->ncb_lana_num = vcp->lana;
 
+#ifndef DJGPP
+       ncbp->ncb_buffer = iop->outCopied + iop->outAllocp;
        code = Netbios(ncbp);
+#else /* DJGPP */
+        dosmemput(iop->outCopied + iop->outAllocp, ncbp->ncb_length, rawBuf);
+        ncbp->ncb_buffer = rawBuf;
+        dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb;
+       code = Netbios(ncbp, dos_ncb);
+#endif /* !DJGPP */
+
        if (code != 0)
                osi_Log1(afsd_logp, "ReadRaw send failure code %d", code);