Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
1000TurquoisePogs committed Nov 9, 2020
2 parents f913d11 + f881aa9 commit 84148da
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 15 deletions.
20 changes: 20 additions & 0 deletions c/httpfileservice.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,24 @@ void respondWithUnixFileMetadata(HttpResponse *response, char *absolutePath) {
int unixTime = fileInfoUnixCreationTime(&info);
convertUnixToISO(unixTime, &timeStamp);

char owner[USER_NAME_LEN+1] = {0};
status = userGetName(info.ownerUID, owner, &returnCode, &reasonCode);
if (status != 0) {
zowelog(NULL, LOG_COMP_HTTPSERVER, ZOWE_LOG_DEBUG,
"failed to obtain user name for uid=%d, returnCode: %d, reasonCode: 0x%08x\n",
info.ownerUID, returnCode, reasonCode);
}
trimRight(owner, USER_NAME_LEN);

char group[GROUP_NAME_LEN+1] = {0};
status = groupGetName(info.ownerGID, group, &returnCode, &reasonCode);
if (status != 0) {
zowelog(NULL, LOG_COMP_HTTPSERVER, ZOWE_LOG_DEBUG,
"failed to obtain group name for gid=%d, returnCode: %d, reasonCode: 0x%08x\n",
info.ownerGID, returnCode, reasonCode);
}
trimRight(group, GROUP_NAME_LEN);

jsonStart(out);
{
jsonAddString(out, "path", absolutePath);
Expand All @@ -574,6 +592,8 @@ void respondWithUnixFileMetadata(HttpResponse *response, char *absolutePath) {
jsonAddInt(out, "ccsid", fileInfoCCSID(&info));
jsonAddString(out, "createdAt", timeStamp.data);
jsonAddInt(out, "mode", octalMode);
jsonAddString(out, "owner", owner);
jsonAddString(out, "group", group);
}
jsonEnd(out);

Expand Down
20 changes: 20 additions & 0 deletions c/httpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -4619,6 +4619,24 @@ int makeJSONForDirectory(HttpResponse *response, char *dirname, int includeDotte
int unixTime = fileInfoUnixCreationTime(&info);
convertUnixToISO(unixTime, &timeStamp);

char owner[USER_NAME_LEN+1] = {0};
int status = userGetName(info.ownerUID, owner, &returnCode, &reasonCode);
if (status != 0) {
zowelog(NULL, LOG_COMP_HTTPSERVER, ZOWE_LOG_DEBUG,
"failed to obtain user name for uid=%d, returnCode: %d, reasonCode: 0x%08x\n",
info.ownerUID, returnCode, reasonCode);
}
trimRight(owner, USER_NAME_LEN);

char group[GROUP_NAME_LEN+1] = {0};
status = groupGetName(info.ownerGID, group, &returnCode, &reasonCode);
if (status != 0) {
zowelog(NULL, LOG_COMP_HTTPSERVER, ZOWE_LOG_DEBUG,
"failed to obtain group name for gid=%d, returnCode: %d, reasonCode: 0x%08x\n",
info.ownerGID, returnCode, reasonCode);
}
trimRight(group, GROUP_NAME_LEN);

/* if(status == 0) { */
jsonStartObject(out, NULL);
{
Expand All @@ -4629,6 +4647,8 @@ int makeJSONForDirectory(HttpResponse *response, char *dirname, int includeDotte
jsonAddInt(out, "ccsid", fileInfoCCSID(&info));
jsonAddString(out, "createdAt", timeStamp.data);
jsonAddInt(out, "mode", octalMode);
jsonAddString(out, "owner", owner);
jsonAddString(out, "group", group);
}
jsonEndObject(out);
/* }
Expand Down
11 changes: 11 additions & 0 deletions c/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,17 @@ const char* strrstr(const char * base, const char * find) {
return returnPtr;
}

/* trimRight removes whitespace from the end of a string. */
void trimRight(char *str, int length) {
int i;
for (i = length - 1; i >= 0; i--) {
if (str[i] != ' ') {
break;
}
str[i] = '\0';
}
}

/*
This program and the accompanying materials are
made available under the terms of the Eclipse Public License v2.0 which accompanies
Expand Down
129 changes: 129 additions & 0 deletions c/zosaccounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,28 @@ static int accountTrace = FALSE;

#ifdef _LP64
# pragma linkage(BPX4GGN,OS)
# pragma linkage(BPX4GGI,OS)
# pragma linkage(BPX4GPN,OS)
# pragma linkage(BPX4GPU,OS)
# pragma linkage(BPX4PWD,OS)

# define BPXGGN BPX4GGN
# define BPXGGI BPX4GGI
# define BPXGPN BPX4GPN
# define BPXGPU BPX4GPU
# define BPXPWD BPX4PWD

#else
# pragma linkage(BPX1GGN,OS)
# pragma linkage(BPX1GGI,OS)
# pragma linkage(BPX1GPN,OS)
# pragma linkage(BPX1GPU,OS)
# pragma linkage(BPX1PWD,OS)

# define BPXGGN BPX1GGN
# define BPXGGI BPX1GGI
# define BPXGPN BPX1GPN
# define BPXGPU BPX1GPU
# define BPXPWD BPX1PWD
#endif

Expand Down Expand Up @@ -107,6 +115,51 @@ int gidGetUserInfo(const char *userName, UserInfo * info,
return retValue;
}

/* Obtain the user information structure using UID */
int getUserInfo(int uid, UserInfo *info, int *returnCode, int *reasonCode) {
int *reasonCodePtr;
int returnValue;
int retValue = -1;

UserInfo *ptrInfo;

#ifndef _LP64
reasonCodePtr = (int*) (0x80000000 | ((int)reasonCode));
#else
reasonCodePtr = reasonCode;
#endif

BPXGPU(uid,
&returnValue,
returnCode,
reasonCodePtr);

if (returnValue != 0) {
memcpy (info, (char *)returnValue, sizeof (UserInfo));
retValue = 0;
}

if (accountTrace) {
if(returnValue == 0) {
#ifdef METTLE
zowelog(NULL, LOG_COMP_ZOS, ZOWE_LOG_DEBUG,
"BPXGPU (%d) FAILED: returnValue: %d, returnCode: %d, reasonCode: 0x%08x\n",
uid, returnValue, *returnCode, *reasonCode);
#else
zowelog(NULL, LOG_COMP_ZOS, ZOWE_LOG_DEBUG,
"BPXGPU (%d) FAILED: returnValue: %d, returnCode: %d, reasonCode: 0x%08x, strError: (%s)\n",
uid, returnValue, *returnCode, *reasonCode,
strerror(*returnCode));
#endif
}
else {
zowelog(NULL, LOG_COMP_ZOS, ZOWE_LOG_DEBUG, "BPXGPU (%d) OK: returnVal: %d\n", uid, returnValue);
}
}

return retValue;
}

/* Obtain the user information structure from user name */
int resetZosUserPassword(const char *userName, const char *password, const char *newPassword,
int *returnCode, int *reasonCode) {
Expand Down Expand Up @@ -202,6 +255,50 @@ int gidGetGroupInfo(const char *groupName, GroupInfo *info,
return retValue;
}

/* Obtain the group information structure using GID */
int getGroupInfo(int gid, GroupInfo *info, int *returnCode, int *reasonCode) {
int *reasonCodePtr;
int returnValue;
int retValue = -1;
*returnCode = *reasonCode = 0;

#ifndef _LP64
reasonCodePtr = (int*) (0x80000000 | ((int)reasonCode));
#else
reasonCodePtr = reasonCode;
#endif

BPXGGI(gid,
&returnValue,
returnCode,
reasonCodePtr);

if (returnValue > 0) {
memcpy (info, (char *)returnValue, sizeof (GroupInfo));
retValue = 0;
}

if (accountTrace) {
if(returnValue == 0) {
#ifdef METTLE
zowelog(NULL, LOG_COMP_ZOS, ZOWE_LOG_DEBUG,
"BPXGGI (%d) FAILED: returnValue: %d, returnCode: %d, reasonCode: 0x%08x\n",,
gid, returnValue, *returnCode, *reasonCode);
#else
zowelog(NULL, LOG_COMP_ZOS, ZOWE_LOG_DEBUG,
"BPXGGI (%d) FAILED: returnValue: %d, returnCode: %d, reasonCode: 0x%08x, strError: (%s)\n",
gid, returnValue, *returnCode, *reasonCode,
strerror(*returnCode));
#endif
}
else {
zowelog(NULL, LOG_COMP_ZOS, ZOWE_LOG_DEBUG, "BPXGGI (%d) OK: returnVal: %d\n", gid, returnValue);
}
}

return retValue;
}

/* Return userId from user info structure */
int userInfoGetUserId (UserInfo *info) {
int *temp = (int *)info;
Expand All @@ -211,6 +308,11 @@ int userInfoGetUserId (UserInfo *info) {
return userId;
}

/* Copy user name from User Info structure into userNameBuffer */
void userInfoGetUserName (UserInfo *info, char *userNameBuffer) {
memcpy(userNameBuffer, (const char*)&info->GIDN_U_NAME, info->GIDN_U_LEN);
}

/* Return groupId from group info structure */
int groupInfoGetGroupId (GroupInfo *info) {
int *temp = (int *)info;
Expand All @@ -220,6 +322,11 @@ int groupInfoGetGroupId (GroupInfo *info) {
return groupId;
}

/* Copy group name from Group Info structure into groupNameBuffer*/
void groupInfoGetGroupName (GroupInfo *info, char *groupNameBuffer) {
memcpy(groupNameBuffer, (const char*)&info->GIDS_G_NAME, info->GIDS_G_LEN);
}

/* Obtain userId from character string */
int userIdGet (char *string, int *returnCode, int *reasonCode) {
UserInfo userInfo = {0};
Expand All @@ -243,6 +350,17 @@ int userIdGet (char *string, int *returnCode, int *reasonCode) {
return userId;
}

/* Obtain user name by UID. userNameBuffer must be at least 8 chars long */
int userGetName(int uid, char *userNameBuffer, int *returnCode, int *reasonCode) {
int status = 0;
UserInfo userInfo = {0};
status = getUserInfo(uid, &userInfo, returnCode, reasonCode);
if (status == 0) {
userInfoGetUserName(&userInfo, userNameBuffer);
}
return status;
}

/* Obtain groupId from character string */
int groupIdGet (char *string, int *returnCode, int *reasonCode) {
GroupInfo groupInfo = {0};
Expand All @@ -266,6 +384,17 @@ int groupIdGet (char *string, int *returnCode, int *reasonCode) {
return groupId;
}

/* Obtain group name by GID, groupNameBuffer must be at least 8 chars long */
int groupGetName(int gid, char *groupNameBuffer, int *returnCode, int *reasonCode) {
int status = 0;
GroupInfo groupInfo = {0};
status = getGroupInfo(gid, &groupInfo, returnCode, reasonCode);
if (status == 0) {
groupInfoGetGroupName(&groupInfo, groupNameBuffer);
}
return status;
}


/*
This program and the accompanying materials are made available under the
Expand Down
19 changes: 5 additions & 14 deletions c/zosfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,11 +1637,6 @@ int directoryChangeTagRecursive(const char *pathName, char *type,
goto ExitCodeError;
}

/* If directory and not recursive, just return */
if ((fileInfoIsDirectory(&info) && !recursive)) {
goto ExitCode;
}

/* Request is for a file. Handle it and exit */
if (fileInfoIsRegularFile(&info)) {
if( -1 == patternChangeTagCheck (pathName, &returnCode,
Expand Down Expand Up @@ -1680,21 +1675,17 @@ int directoryChangeTagRecursive(const char *pathName, char *type,
goto ExitCodeError;
}

if (fileInfoIsDirectory(&info)) {
if (fileInfoIsDirectory(&info) && recursive) {
/* Change tag of all sub-directories and files there-in */
if (-1 == directoryChangeTagRecursive(
pathBuffer, type, codepage, recursive, pattern,
&returnCode, &reasonCode) ){
goto ExitCodeError;
}
}
else {
/* change mode of this file, not a directory */
if (fileInfoIsRegularFile(&info)) {
if( -1 == patternChangeTagCheck (pathBuffer, &returnCode, &reasonCode,
codepage, type, pattern)) {
goto ExitCodeError;
}
} else if (fileInfoIsRegularFile(&info)) {
if( -1 == patternChangeTagCheck (pathBuffer, &returnCode, &reasonCode,
codepage, type, pattern)) {
goto ExitCodeError;
}
}
} /* End of for loop */
Expand Down
2 changes: 2 additions & 0 deletions h/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ bool stringIsDigit(const char * str);
const char* strrstr(const char * base, const char * find);
#endif

void trimRight(char *str, int length);

#if defined(__cplusplus)
} /* end of extern "C" */
#endif
Expand Down
9 changes: 8 additions & 1 deletion h/zosaccounts.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,24 @@ typedef struct BPXYGIDN_tag {
typedef BPXYGIDS GroupInfo;
typedef BPXYGIDN UserInfo;


#define USER_NAME_LEN 8
#define GROUP_NAME_LEN 8

/* Function Prototype */
int gidGetUserInfo(const char *userName, UserInfo * info,
int *returnCode, int *reasonCode);
int getUserInfo(int uid, UserInfo *info, int *returnCode, int *reasonCode);
int gidGetGroupInfo(const char *groupName, GroupInfo *info,
int *returnCode, int *reasonCode);
int getGroupInfo(int gid, GroupInfo *info, int *returnCode, int *reasonCode);
int userInfoGetUserId (UserInfo *info);
void userInfoGetUserName (UserInfo *info, char *userNameBuffer);
int groupInfoGetGroupId (GroupInfo *info);
void groupInfoGetGroupName (GroupInfo *info, char *groupNameBuffer);
int userIdGet (char *string, int *returnCode, int *reasonCode);
int userGetName(int uid, char *userNameBuffer, int *returnCode, int *reasonCode);
int groupIdGet (char *string, int *returnCode, int *reasonCode);
int groupGetName(int gid, char *groupNameBuffer, int *returnCode, int *reasonCode);
int resetZosUserPassword(const char *userName, const char *password, const char *newPassword,
int *returnCode, int *reasonCode);

Expand Down

0 comments on commit 84148da

Please sign in to comment.