Nfsv4CompoundProcCtx.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Nfsv4CompoundProcCtx = void 0;
  4. const tslib_1 = require("tslib");
  5. const msg = tslib_1.__importStar(require("../messages"));
  6. const format_1 = require("../format");
  7. class Nfsv4CompoundProcCtx {
  8. constructor(connection, req) {
  9. this.connection = connection;
  10. this.req = req;
  11. this.cfh = null;
  12. this.sfh = null;
  13. }
  14. getPrincipal() {
  15. return 'none';
  16. }
  17. async exec() {
  18. const { req, connection } = this;
  19. const { ops, debug, logger } = connection;
  20. const { argarray, tag } = req;
  21. const length = argarray.length;
  22. let status = 0;
  23. const resarray = [];
  24. OPS_LOOP: for (let i = 0; i < length; i++) {
  25. const op = argarray[i];
  26. const opReq = op;
  27. let fn = void 0;
  28. let Response = void 0;
  29. if (op instanceof msg.Nfsv4AccessRequest)
  30. (fn = ops.ACCESS), (Response = msg.Nfsv4AccessResponse);
  31. else if (op instanceof msg.Nfsv4PutrootfhRequest)
  32. (fn = ops.PUTROOTFH), (Response = msg.Nfsv4PutrootfhResponse);
  33. else if (op instanceof msg.Nfsv4PutpubfhRequest)
  34. (fn = ops.PUTPUBFH), (Response = msg.Nfsv4PutpubfhResponse);
  35. else if (op instanceof msg.Nfsv4PutfhRequest)
  36. (fn = ops.PUTFH), (Response = msg.Nfsv4PutfhResponse);
  37. else if (op instanceof msg.Nfsv4GetfhRequest)
  38. (fn = ops.GETFH), (Response = msg.Nfsv4GetfhResponse);
  39. else if (op instanceof msg.Nfsv4SavefhRequest)
  40. (fn = ops.SAVEFH), (Response = msg.Nfsv4SavefhResponse);
  41. else if (op instanceof msg.Nfsv4ReadRequest)
  42. (fn = ops.READ), (Response = msg.Nfsv4ReadResponse);
  43. else if (op instanceof msg.Nfsv4ReaddirRequest)
  44. (fn = ops.READDIR), (Response = msg.Nfsv4ReaddirResponse);
  45. else if (op instanceof msg.Nfsv4ReadlinkRequest)
  46. (fn = ops.READLINK), (Response = msg.Nfsv4ReadlinkResponse);
  47. else if (op instanceof msg.Nfsv4WriteRequest)
  48. (fn = ops.WRITE), (Response = msg.Nfsv4WriteResponse);
  49. else if (op instanceof msg.Nfsv4OpenRequest)
  50. (fn = ops.OPEN), (Response = msg.Nfsv4OpenResponse);
  51. else if (op instanceof msg.Nfsv4CloseRequest)
  52. (fn = ops.CLOSE), (Response = msg.Nfsv4CloseResponse);
  53. else if (op instanceof msg.Nfsv4RemoveRequest)
  54. (fn = ops.REMOVE), (Response = msg.Nfsv4RemoveResponse);
  55. else if (op instanceof msg.Nfsv4RenameRequest)
  56. (fn = ops.RENAME), (Response = msg.Nfsv4RenameResponse);
  57. else if (op instanceof msg.Nfsv4OpenattrRequest)
  58. (fn = ops.OPENATTR), (Response = msg.Nfsv4OpenattrResponse);
  59. else if (op instanceof msg.Nfsv4GetattrRequest)
  60. (fn = ops.GETATTR), (Response = msg.Nfsv4GetattrResponse);
  61. else if (op instanceof msg.Nfsv4SetattrRequest)
  62. (fn = ops.SETATTR), (Response = msg.Nfsv4SetattrResponse);
  63. else if (op instanceof msg.Nfsv4CreateRequest)
  64. (fn = ops.CREATE), (Response = msg.Nfsv4CreateResponse);
  65. else if (op instanceof msg.Nfsv4SetclientidRequest)
  66. (fn = ops.SETCLIENTID), (Response = msg.Nfsv4SetclientidResponse);
  67. else if (op instanceof msg.Nfsv4SetclientidConfirmRequest)
  68. (fn = ops.SETCLIENTID_CONFIRM), (Response = msg.Nfsv4SetclientidConfirmResponse);
  69. else if (op instanceof msg.Nfsv4OpenConfirmRequest)
  70. (fn = ops.OPEN_CONFIRM), (Response = msg.Nfsv4OpenConfirmResponse);
  71. else if (op instanceof msg.Nfsv4OpenDowngradeRequest)
  72. (fn = ops.OPEN_DOWNGRADE), (Response = msg.Nfsv4OpenDowngradeResponse);
  73. else if (op instanceof msg.Nfsv4CommitRequest)
  74. (fn = ops.COMMIT), (Response = msg.Nfsv4CommitResponse);
  75. else if (op instanceof msg.Nfsv4LinkRequest)
  76. (fn = ops.LINK), (Response = msg.Nfsv4LinkResponse);
  77. else if (op instanceof msg.Nfsv4RenewRequest)
  78. (fn = ops.RENEW), (Response = msg.Nfsv4RenewResponse);
  79. else if (op instanceof msg.Nfsv4DelegpurgeRequest)
  80. (fn = ops.DELEGPURGE), (Response = msg.Nfsv4DelegpurgeResponse);
  81. else if (op instanceof msg.Nfsv4DelegreturnRequest)
  82. (fn = ops.DELEGRETURN), (Response = msg.Nfsv4DelegreturnResponse);
  83. else if (op instanceof msg.Nfsv4RestorefhRequest)
  84. (fn = ops.RESTOREFH), (Response = msg.Nfsv4RestorefhResponse);
  85. else if (op instanceof msg.Nfsv4SecinfoRequest)
  86. (fn = ops.SECINFO), (Response = msg.Nfsv4SecinfoResponse);
  87. else if (op instanceof msg.Nfsv4VerifyRequest)
  88. (fn = ops.VERIFY), (Response = msg.Nfsv4VerifyResponse);
  89. else if (op instanceof msg.Nfsv4LockRequest)
  90. (fn = ops.LOCK), (Response = msg.Nfsv4LockResponse);
  91. else if (op instanceof msg.Nfsv4LocktRequest)
  92. (fn = ops.LOCKT), (Response = msg.Nfsv4LocktResponse);
  93. else if (op instanceof msg.Nfsv4LockuRequest)
  94. (fn = ops.LOCKU), (Response = msg.Nfsv4LockuResponse);
  95. else if (op instanceof msg.Nfsv4LookupRequest)
  96. (fn = ops.LOOKUP), (Response = msg.Nfsv4LookupResponse);
  97. else if (op instanceof msg.Nfsv4LookuppRequest)
  98. (fn = ops.LOOKUPP), (Response = msg.Nfsv4LookuppResponse);
  99. else if (op instanceof msg.Nfsv4NverifyRequest)
  100. (fn = ops.NVERIFY), (Response = msg.Nfsv4NverifyResponse);
  101. else if (op instanceof msg.Nfsv4ReleaseLockOwnerRequest)
  102. (fn = ops.RELEASE_LOCKOWNER), (Response = msg.Nfsv4ReleaseLockOwnerResponse);
  103. else if (op instanceof msg.Nfsv4IllegalRequest)
  104. (fn = ops.ILLEGAL), (Response = msg.Nfsv4IllegalResponse);
  105. if (!fn || !Response)
  106. return new msg.Nfsv4CompoundResponse(10044, tag, resarray);
  107. EXEC_OP: try {
  108. if (debug)
  109. logger.log((0, format_1.formatNfsv4Request)(opReq));
  110. const opResponse = await fn.call(ops, opReq, this);
  111. if (!(opResponse instanceof Response))
  112. throw new Error('Unexpected response, fn = ' + fn.name);
  113. if (debug)
  114. logger.log(': ' + (0, format_1.formatNfsv4Response)(opResponse));
  115. status = opResponse.status;
  116. resarray.push(opResponse);
  117. }
  118. catch (err) {
  119. if (debug)
  120. logger.error(': ERROR', fn.name, err);
  121. if (err instanceof Response) {
  122. if (err.status !== 0) {
  123. status = err.status;
  124. resarray.push(err);
  125. break EXEC_OP;
  126. }
  127. else {
  128. logger.error('Operation [' + fn.name + '] threw response with NFS4_OK');
  129. err = 10006;
  130. }
  131. }
  132. FIND_STATUS_CODE: {
  133. if (typeof err === 'number') {
  134. if (err > 0 && err <= 16777215) {
  135. status = err;
  136. break FIND_STATUS_CODE;
  137. }
  138. status = 10006;
  139. logger.error('Invalid status [code = ' + err + ', fn = ' + fn.name + ']');
  140. break FIND_STATUS_CODE;
  141. }
  142. status = 10006;
  143. logger.error(fn.name, err);
  144. }
  145. const opResponse = new Response(status);
  146. resarray.push(opResponse);
  147. }
  148. if (status !== 0)
  149. break OPS_LOOP;
  150. }
  151. return new msg.Nfsv4CompoundResponse(status, tag, resarray);
  152. }
  153. }
  154. exports.Nfsv4CompoundProcCtx = Nfsv4CompoundProcCtx;
  155. //# sourceMappingURL=Nfsv4CompoundProcCtx.js.map