Skip to content

Commit

Permalink
Merge pull request #252 from 1000TurquoisePogs/feature/more-type-vali…
Browse files Browse the repository at this point in the history
…dation

Write dataset type validation
  • Loading branch information
1000TurquoisePogs authored Oct 13, 2021
2 parents f87f1a0 + 8354077 commit d246131
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions c/datasetjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,43 @@ static int isPartionedDataset(char *dscb) {
}
#endif

static bool isSupportedWriteDsorg(char *dscb, bool *isPds) {
int posOffset = 44;
int dsorgHigh = dscb[82-posOffset];

if (dsorgHigh & 0x40){/*Physical Sequential / PS*/
return true;
}
else if (dsorgHigh & 0x20){/*Direct Organization / DA*/
return false;
}
else if (dsorgHigh & 0x10){/*BTAM or QTAM / CX*/
return false;
}
else if (dsorgHigh & 0x02){ /*Partitioned / PO*/
int pdsCheck = dscb[78-posOffset] & 0x0a;
if (pdsCheck == 0x0a){/*pdse & pdsex = hfs*/
return false;
}
else{
*isPds = true;
return true;
}
}
if (dsorgHigh & 0x01){//"unmovable"
return false;
}

int dsorgLow = dscb[83-posOffset];

if (dsorgLow & 0x80){/*Graphics / GS*/
return false;
}
else if (dsorgLow & 0x08){/*VSAM*/
return false;
}
}

static int obtainDSCB1(const char *dsname, unsigned int dsnameLength,
const char *volser, unsigned int volserLength,
char *dscb1) {
Expand Down Expand Up @@ -885,6 +922,25 @@ static void updateDatasetWithJSONInternal(HttpResponse* response,
zowelog(NULL, LOG_COMP_RESTDATASET, ZOWE_LOG_DEBUG, "DSCB for %.*s found\n", sizeof(dsn->value), dsn->value);
dumpbuffer(dscb,INDEXED_DSCB);
}
bool isPds = false;
if (!isSupportedWriteDsorg(dscb, &isPds)) {
respondWithError(response, HTTP_STATUS_BAD_REQUEST,"Unsupported dataset type");
return;
} else if (isPds) {
bool isMember = false;
int memberStart=44;
int memberEnd=memberStart+8;
for (int i = memberStart; i < memberEnd; i++){
if (*(dsn->value+i) != 0x40){
isMember = true;
break;
}
}
if (!isMember){
respondWithError(response, HTTP_STATUS_BAD_REQUEST, "Overwrite of PDS not supported");
return;
}
}

maxRecordLength = getMaxRecordLength(dscb);
char recordType = getRecordLengthType(dscb);
Expand All @@ -910,6 +966,16 @@ static void updateDatasetWithJSONInternal(HttpResponse* response,
zowelog(NULL, LOG_COMP_RESTDATASET, ZOWE_LOG_DEBUG, "FLData request rc=0x%x\n",returnCode);
fflush(stdout);
if (!returnCode) {
zowelog(NULL, LOG_COMP_RESTDATASET, ZOWE_LOG_WARNING,
"fldata concat=%d, mem=%d, hiper=%d, temp=%d, vsam=%d, hfs=%d, device=%s\n",
fileinfo.__dsorgConcat, fileinfo.__dsorgMem, fileinfo.__dsorgHiper,
fileinfo.__dsorgTemp, fileinfo.__dsorgVSAM, fileinfo.__dsorgHFS, fileinfo.__device);

if (fileinfo.__dsorgVSAM || fileinfo.__dsorgHFS || fileinfo.__dsorgHiper) {
respondWithError(response, HTTP_STATUS_BAD_REQUEST, "Dataset type not supported");
fclose(datasetRead);
return;
}
if (fileinfo.__maxreclen){
maxRecordLength = fileinfo.__maxreclen;
}
Expand Down

0 comments on commit d246131

Please sign in to comment.