00001
00002
00003
00004
00005
00006 #include "chkNVPathPerm.h"
00007 #include "fileStat.h"
00008 #include "miscServerFunct.h"
00009 #include "dataObjOpr.h"
00010
00011 int
00012 rsChkNVPathPerm (rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp)
00013 {
00014 rodsServerHost_t *rodsServerHost;
00015 int remoteFlag;
00016 int status;
00017
00018 remoteFlag = resolveHost (&chkNVPathPermInp->addr, &rodsServerHost);
00019
00020 if (remoteFlag < 0) {
00021 return (remoteFlag);
00022 } else {
00023 status = rsChkNVPathPermByHost (rsComm, chkNVPathPermInp,
00024 rodsServerHost);
00025 return (status);
00026 }
00027 }
00028
00029 int
00030 rsChkNVPathPermByHost (rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp,
00031 rodsServerHost_t *rodsServerHost)
00032 {
00033 int remoteFlag;
00034 int status;
00035
00036 if (rodsServerHost == NULL) {
00037 rodsLog (LOG_NOTICE,
00038 "rsChkNVPathPermByHost: Input NULL rodsServerHost");
00039 return (SYS_INTERNAL_NULL_INPUT_ERR);
00040 }
00041
00042 remoteFlag = rodsServerHost->localFlag;
00043
00044 if (remoteFlag == LOCAL_HOST) {
00045 status = _rsChkNVPathPerm (rsComm, chkNVPathPermInp);
00046 } else if (remoteFlag == REMOTE_HOST) {
00047 status = remoteChkNVPathPerm (rsComm, chkNVPathPermInp, rodsServerHost);
00048 } else {
00049 if (remoteFlag < 0) {
00050 return (remoteFlag);
00051 } else {
00052 rodsLog (LOG_NOTICE,
00053 "rsChkNVPathPerm: resolveHost returned unrecognized value %d",
00054 remoteFlag);
00055 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00056 }
00057 }
00058
00059 return (status);
00060 }
00061
00062 int
00063 remoteChkNVPathPerm (rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp,
00064 rodsServerHost_t *rodsServerHost)
00065 {
00066 int status;
00067
00068 if (rodsServerHost == NULL) {
00069 rodsLog (LOG_NOTICE,
00070 "remoteChkNVPathPerm: Invalid rodsServerHost");
00071 return SYS_INVALID_SERVER_HOST;
00072 }
00073
00074 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00075 return status;
00076 }
00077
00078
00079 status = rcChkNVPathPerm (rodsServerHost->conn, chkNVPathPermInp);
00080
00081 if (status < 0) {
00082 rodsLog (LOG_NOTICE,
00083 "remoteChkNVPathPerm: rcChkNVPathPerm failed for %s",
00084 chkNVPathPermInp->fileName);
00085 }
00086
00087 return status;
00088 }
00089
00090 int
00091 _rsChkNVPathPerm (rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp)
00092 {
00093 int status;
00094 struct stat myFileStat;
00095 int sysUid;
00096 char userName[NAME_LEN], tmpPath[MAX_NAME_LEN];
00097 int len;
00098 char *tmpPtr;
00099
00100
00101
00102 sysUid = rsComm->clientUser.sysUid;
00103 if (sysUid < 0) {
00104 rodsLog( LOG_NOTICE, "ZZZZ - sysUid < 0" );
00105
00106 return (SYS_NO_PATH_PERMISSION);
00107 } else if (sysUid == 0) {
00108 rodsLog( LOG_NOTICE, "ZZZZ - sysUid == 0" );
00109 if (strstr (rsComm->clientUser.userName, "@") != NULL) {
00110 rodsLog( LOG_NOTICE, "ZZZZ - splitPathByKey" );
00111 splitPathByKey (rsComm->clientUser.userName, userName, tmpPath, '@');
00112 } else {
00113 rodsLog( LOG_NOTICE, "ZZZZ - rstrcpy (userName, rsComm->clientUser.userName, NAME_LEN)" );
00114 rstrcpy (userName, rsComm->clientUser.userName, NAME_LEN);
00115 }
00116
00117 sysUid = rsComm->clientUser.sysUid = getUnixUid (userName);
00118 if (sysUid < 0) {
00119 rodsLog( LOG_NOTICE, "ZZZZ - sysUid < 0 - 2" );
00120 rsComm->clientUser.sysUid = sysUid;
00121 return (SYS_NO_PATH_PERMISSION);
00122 }
00123 }
00124
00125
00126 rstrcpy (tmpPath, chkNVPathPermInp->fileName, MAX_NAME_LEN);
00127
00128 len = strlen (tmpPath);
00129
00130 status = -1;
00131 while (1) {
00132 status = fileStat (chkNVPathPermInp->fileType, rsComm, tmpPath, &myFileStat);
00133
00134 if (status >= 0) {
00135 break;
00136 } else if (errno == EEXIST || getErrno (status) == EEXIST) {
00137
00138
00139 tmpPtr = tmpPath + len;
00140
00141 while (len > 0) {
00142 len --;
00143 if (*tmpPtr == '/') {
00144 *tmpPtr = '\0';
00145 break;
00146 }
00147 tmpPtr--;
00148 }
00149
00150 if (len > 0) {
00151
00152 continue;
00153 } else {
00154 break;
00155 }
00156 } else {
00157 break;
00158 }
00159 }
00160
00161 if (status < 0) {
00162 rodsLog( LOG_NOTICE, "ZZZZ - status < 0" );
00163 return (SYS_NO_PATH_PERMISSION);
00164 }
00165
00166 if( sysUid != (int) myFileStat.st_uid &&
00167 (myFileStat.st_mode & S_IWOTH) == 0) {
00168 rodsLog( LOG_NOTICE, "ZZZZ - foobar" );
00169 return (SYS_NO_PATH_PERMISSION);
00170 } else {
00171 return (0);
00172 }
00173 }