clang-10: use AFS_FALLTHROUGH for case fallthrough
[openafs.git] / src / WINNT / afsd / rpc_srvsvc.c
index ceacc66..899e2ad 100644 (file)
  * SOFTWARE.
  */
 
+
+#include <afsconfig.h>
+#include <afs/param.h>
+#include <roken.h>
+
 #include<windows.h>
 #include <wchar.h>
 #define _CRT_RAND_S
@@ -583,17 +588,17 @@ NET_API_STATUS NetrShareEnum(
     case 2:
         if (space_limited)
             space_available -= sizeof(InfoStruct->ShareInfo.Level2);
-        InfoStruct->ShareInfo.Level2->Buffer = calloc((enump->count - enump->next), sizeof(SHARE_INFO_2));
+        InfoStruct->ShareInfo.Level2->Buffer = MIDL_user_allocate((enump->count - enump->next) * sizeof(SHARE_INFO_2));
         break;
     case 1:
         if (space_limited)
             space_available -= sizeof(InfoStruct->ShareInfo.Level1);
-        InfoStruct->ShareInfo.Level1->Buffer = calloc((enump->count - enump->next), sizeof(SHARE_INFO_1));
+        InfoStruct->ShareInfo.Level1->Buffer = MIDL_user_allocate((enump->count - enump->next) * sizeof(SHARE_INFO_1));
         break;
     case 0:
         if (space_limited)
             space_available -= sizeof(InfoStruct->ShareInfo.Level0);
-        InfoStruct->ShareInfo.Level0->Buffer = calloc((enump->count - enump->next), sizeof(SHARE_INFO_0));
+        InfoStruct->ShareInfo.Level0->Buffer = MIDL_user_allocate((enump->count - enump->next) * sizeof(SHARE_INFO_0));
         break;
     }
 
@@ -623,7 +628,7 @@ NET_API_STATUS NetrShareEnum(
             continue;
         }
 
-        cm_GetSCache(&entryp->fid, &scp, userp, &req);
+        cm_GetSCache(&entryp->fid, NULL, &scp, userp, &req);
 
         switch (InfoStruct->Level) {
         case 2:
@@ -730,22 +735,7 @@ NET_API_STATUS NetrShareGetInfo(
 
     dscp = cm_RootSCachep(userp, &req);
 
-    /* Allocate the memory for the response */
-    switch (Level) {
-    case 2:
-        InfoStruct->ShareInfo2 = calloc(1, sizeof(SHARE_INFO_2));
-        break;
-    case 1:
-        InfoStruct->ShareInfo1 = calloc(1, sizeof(SHARE_INFO_1));
-        break;
-    case 0:
-        InfoStruct->ShareInfo0 = calloc(1, sizeof(SHARE_INFO_0));
-        break;
-    }
-
-    if (InfoStruct->ShareInfo0 == NULL) {
-        return ERROR_NOT_ENOUGH_MEMORY;
-    }
+    InfoStruct->ShareInfo0 = NULL;
 
     /*
      * NetName will be:
@@ -805,7 +795,10 @@ NET_API_STATUS NetrShareGetInfo(
         if (allSubmount) {
             scp = dscp;
             cm_HoldSCache(scp);
-        }
+           code = 0;
+       } else {
+           code = CM_ERROR_NOSUCHPATH;
+       }
     } else {
         /*
          * Could be a Submount, a directory entry, or a cell name we
@@ -835,14 +828,45 @@ NET_API_STATUS NetrShareGetInfo(
 
             if (cblen) {
                 code = cm_NameI(dscp, pathstr, CM_FLAG_FOLLOW, userp, NULL, &req, &scp);
-                if (code && code != CM_ERROR_NOACCESS)
+                if (code == CM_ERROR_NOSUCHFILE ||
+                    code == CM_ERROR_NOSUCHPATH ||
+                    code == CM_ERROR_BPLUS_NOMATCH)
                     code = cm_NameI(dscp, pathstr, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
-                                      userp, NULL, &req, &scp);
-            }
+                                    userp, NULL, &req, &scp);
+           } else {
+               code = CM_ERROR_NOSUCHPATH;
+           }
         }
     }
 
     if (scp) {
+       /* Allocate the memory for the response */
+       switch (Level) {
+       case 2:
+           InfoStruct->ShareInfo2 = MIDL_user_allocate(sizeof(SHARE_INFO_2));
+           break;
+       case 1:
+           InfoStruct->ShareInfo1 = MIDL_user_allocate(sizeof(SHARE_INFO_1));
+           break;
+       case 0:
+           InfoStruct->ShareInfo0 = MIDL_user_allocate(sizeof(SHARE_INFO_0));
+           break;
+       case 501:
+       case 502:
+       case 503:
+       case 1004:
+       case 1005:
+       case 1006:
+       default:
+           cm_ReleaseSCache(scp);
+           return HRESULT_FROM_WIN32(ERROR_INVALID_LEVEL);
+       }
+
+       if (InfoStruct->ShareInfo0 == NULL) {
+           cm_ReleaseSCache(scp);
+           return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
+       }
+
         switch (Level) {
         case 2:
             /* for share level security */
@@ -853,12 +877,12 @@ NET_API_STATUS NetrShareGetInfo(
                 NetrIntGenerateSharePath(ServerName, &scp->fid);
             /* must be the empty string */
             InfoStruct->ShareInfo2->shi2_passwd = wcsdup(L"");
-            /* fall-through */
+            AFS_FALLTHROUGH;
         case 1:
             InfoStruct->ShareInfo1->shi1_type = STYPE_DISKTREE;
             InfoStruct->ShareInfo1->shi1_remark =
                 NetrIntGenerateShareRemark(scp, &scp->fid);
-            /* fall-through */
+            AFS_FALLTHROUGH;
         case 0:
             /* Canonicalized version of NetName parameter */
             InfoStruct->ShareInfo0->shi0_netname = wcsdup(NetName);
@@ -945,16 +969,16 @@ NET_API_STATUS NetrServerGetInfo(
      */
     switch (Level) {
     case 103:
-        InfoStruct->ServerInfo103 = calloc(1, sizeof(SERVER_INFO_103));
+        InfoStruct->ServerInfo103 = MIDL_user_allocate(sizeof(SERVER_INFO_103));
         break;
     case 102:
-        InfoStruct->ServerInfo102 = calloc(1, sizeof(SERVER_INFO_102));
+        InfoStruct->ServerInfo102 = MIDL_user_allocate(sizeof(SERVER_INFO_102));
         break;
     case 101:
-        InfoStruct->ServerInfo101 = calloc(1, sizeof(SERVER_INFO_101));
+        InfoStruct->ServerInfo101 = MIDL_user_allocate(sizeof(SERVER_INFO_101));
         break;
     case 100:
-        InfoStruct->ServerInfo100 = calloc(1, sizeof(SERVER_INFO_100));
+        InfoStruct->ServerInfo100 = MIDL_user_allocate(sizeof(SERVER_INFO_100));
         break;
     }
 
@@ -971,7 +995,7 @@ NET_API_STATUS NetrServerGetInfo(
     switch (Level) {
     case 103:
         InfoStruct->ServerInfo103->sv103_capabilities = 0;
-        /* fall-through */
+        AFS_FALLTHROUGH;
     case 102:
         InfoStruct->ServerInfo102->sv102_users = 0xFFFFFFFF;
         InfoStruct->ServerInfo102->sv102_disc = SV_NODISC;
@@ -980,13 +1004,13 @@ NET_API_STATUS NetrServerGetInfo(
         InfoStruct->ServerInfo102->sv102_anndelta = 0;
         InfoStruct->ServerInfo102->sv102_licenses = 0;
         InfoStruct->ServerInfo102->sv102_userpath = wcsdup(L"C:\\");
-        /* fall-through */
+        AFS_FALLTHROUGH;
     case 101:
         InfoStruct->ServerInfo101->sv101_version_major = AFSPRODUCT_VERSION_MAJOR;
         InfoStruct->ServerInfo101->sv101_version_minor = AFSPRODUCT_VERSION_MINOR;
         InfoStruct->ServerInfo101->sv101_type = SV_TYPE_WORKSTATION | SV_TYPE_SERVER | SV_TYPE_SERVER_UNIX;
         InfoStruct->ServerInfo101->sv101_comment = wcsdup(wAFSVersion);
-        /* fall-through */
+        AFS_FALLTHROUGH;
     case 100:
         InfoStruct->ServerInfo100->sv100_platform_id = SV_PLATFORM_ID_AFS;
         /* The Netbios Name */
@@ -1402,18 +1426,6 @@ void __RPC_USER SHARE_DEL_HANDLE_rundown( SHARE_DEL_HANDLE h)
 {
 }
 
-#if 0
-/* [nocode] */ void Opnum3NotUsedOnWire(
-    /* [in] */ handle_t IDL_handle)
-{
-}
-
-/* [nocode] */ void Opnum4NotUsedOnWire(
-    /* [in] */ handle_t IDL_handle)
-{
-}
-#endif
-
 /* [nocode] */ void Opnum5NotUsedOnWire(
     /* [in] */ handle_t IDL_handle)
 {