irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rsChkNVPathPerm.cpp
Go to the documentation of this file.
1 
3 /* This is script-generated code (for the most part). */
4 /* See chkNVPathPerm.h for a description of this API call.*/
5 
6 #include "chkNVPathPerm.h"
7 #include "fileStat.h"
8 #include "miscServerFunct.hpp"
9 #include "dataObjOpr.hpp"
10 #include "rsChkNVPathPerm.hpp"
11 
12 // =-=-=-=-=-=-=-
13 #include "irods_log.hpp"
14 #include "irods_file_object.hpp"
15 #include "irods_stacktrace.hpp"
17 
18 int
19 rsChkNVPathPerm( rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp ) {
21  int remoteFlag;
22  int status;
23 
24  //remoteFlag = resolveHost (&chkNVPathPermInp->addr, &rodsServerHost);
25  irods::error ret = irods::get_host_for_hier_string( chkNVPathPermInp->resc_hier_, remoteFlag, rodsServerHost );
26  if ( !ret.ok() ) {
27  irods::log( PASSMSG( "rsChkNVPathPerm - failed in call to irods::get_host_for_hier_string", ret ) );
28  return -1;
29  }
30 
31  if ( remoteFlag < 0 ) {
32  return remoteFlag;
33  }
34  else {
35  status = rsChkNVPathPermByHost( rsComm, chkNVPathPermInp,
37  return status;
38  }
39 }
40 
41 int
42 rsChkNVPathPermByHost( rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp,
44  int remoteFlag;
45  int status;
46 
47  if ( rodsServerHost == NULL ) {
49  "rsChkNVPathPermByHost: Input NULL rodsServerHost" );
51  }
52 
53  remoteFlag = rodsServerHost->localFlag;
54 
55  if ( remoteFlag == LOCAL_HOST ) {
56  status = _rsChkNVPathPerm( rsComm, chkNVPathPermInp );
57  }
58  else if ( remoteFlag == REMOTE_HOST ) {
59  status = remoteChkNVPathPerm( rsComm, chkNVPathPermInp, rodsServerHost );
60  }
61  else {
62  if ( remoteFlag < 0 ) {
63  return remoteFlag;
64  }
65  else {
67  "rsChkNVPathPerm: resolveHost returned unrecognized value %d",
68  remoteFlag );
70  }
71  }
72 
73  return status;
74 }
75 
76 int
77 remoteChkNVPathPerm( rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp,
79  int status;
80 
81  if ( rodsServerHost == NULL ) {
83  "remoteChkNVPathPerm: Invalid rodsServerHost" );
85  }
86 
87  if ( ( status = svrToSvrConnect( rsComm, rodsServerHost ) ) < 0 ) {
88  return status;
89  }
90 
91 
92  status = rcChkNVPathPerm( rodsServerHost->conn, chkNVPathPermInp );
93 
94  if ( status < 0 ) {
96  "remoteChkNVPathPerm: rcChkNVPathPerm failed for %s",
97  chkNVPathPermInp->fileName );
98  }
99 
100  return status;
101 }
102 
103 int
104 _rsChkNVPathPerm( rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp ) {
105  struct stat myFileStat;
106  int sysUid;
107  char tmpPath[MAX_NAME_LEN];
108  int len;
109  char *tmpPtr;
110 
111  if ( chkNVPathPermInp->objPath[0] == '\0' ) {
112  std::stringstream msg;
113  msg << __FUNCTION__;
114  msg << " - Empty logical path.";
115  irods::log( LOG_ERROR, msg.str() );
116  return -1;
117  }
118 
119  /* Need to match path's owner uid with sysUid */
120  sysUid = rsComm->clientUser.sysUid;
121  if ( sysUid < 0 ) {
122  /* have tried before */
123  return SYS_NO_PATH_PERMISSION;
124  }
125  else if ( sysUid == 0 ) {
126  sysUid = rsComm->clientUser.sysUid =
127  getUnixUid( rsComm->clientUser.userName );
128 
129  if ( sysUid < 0 ) {
130  rsComm->clientUser.sysUid = sysUid;
131  return SYS_NO_PATH_PERMISSION;
132  }
133  }
134 
135 
136  rstrcpy( tmpPath, chkNVPathPermInp->fileName, MAX_NAME_LEN );
137 
138  len = strlen( tmpPath );
139  irods::error stat_err;
140  while ( 1 ) {
141 
142  irods::file_object_ptr file_obj(
143  new irods::file_object(
144  rsComm,
145  chkNVPathPermInp->objPath,
146  tmpPath,
147  chkNVPathPermInp->resc_hier_,
148  0, 0, 0 ) );
149  stat_err = fileStat( rsComm, file_obj, &myFileStat );
150  if ( stat_err.code() >= 0 ) {
151  break;
152  }
153  else if ( errno == EEXIST || getErrno( stat_err.code() ) == EEXIST ) {
154 
155  /* go back */
156  tmpPtr = tmpPath + len;
157 
158  while ( len > 0 ) {
159  len --;
160  if ( *tmpPtr == '/' ) {
161  *tmpPtr = '\0';
162  break;
163  }
164  tmpPtr--;
165  }
166 
167  if ( len > 0 ) {
168  /* give it more tries */
169  continue;
170  }
171  else {
172  break;
173  }
174  }
175  else {
176  break;
177  }
178  }
179 
180  if ( stat_err.code() < 0 ) {
181  return SYS_NO_PATH_PERMISSION;
182  }
183 
184  if ( sysUid != ( int ) myFileStat.st_uid &&
185  ( myFileStat.st_mode & S_IWOTH ) == 0 ) {
186  return SYS_NO_PATH_PERMISSION;
187  }
188  else {
189  return 0;
190  }
191 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
userInfo_t::userName
char userName[64]
Definition: rodsUser.h:66
SYS_UNRECOGNIZED_REMOTE_FLAG
@ SYS_UNRECOGNIZED_REMOTE_FLAG
Definition: rodsErrorTable.h:88
irods_file_object.hpp
irods_stacktrace.hpp
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
irods_resource_backport.hpp
fileOpenInp_t::resc_hier_
char resc_hier_[(1024+64)]
Definition: fileOpen.h:16
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
fileStat.h
rsChkNVPathPermByHost
int rsChkNVPathPermByHost(rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp, rodsServerHost_t *rodsServerHost)
Definition: rsChkNVPathPerm.cpp:42
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
SYS_NO_PATH_PERMISSION
@ SYS_NO_PATH_PERMISSION
Definition: rodsErrorTable.h:103
fileOpenInp_t::fileName
char fileName[(1024+64)]
Definition: fileOpen.h:20
chkNVPathPerm.h
_rsChkNVPathPerm
int _rsChkNVPathPerm(rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp)
Definition: rsChkNVPathPerm.cpp:104
irods::error::code
long long code() const
Definition: irods_error.cpp:194
fileOpenInp_t::objPath
char objPath[(1024+64)]
Definition: fileOpen.h:17
irods::get_host_for_hier_string
error get_host_for_hier_string(const std::string &, int &, rodsServerHost_t *&)
Definition: irods_resource_backport.cpp:581
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
getErrno
int getErrno(int errCode)
Definition: rcMisc.cpp:3261
SYS_INVALID_SERVER_HOST
@ SYS_INVALID_SERVER_HOST
Definition: rodsErrorTable.h:89
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
irods::log
void log(const error &)
Definition: irods_log.cpp:13
userInfo_t::sysUid
int sysUid
Definition: rodsUser.h:69
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
rsComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:153
rcChkNVPathPerm
int rcChkNVPathPerm(rcComm_t *conn, fileOpenInp_t *chkNVPathPermInp)
Definition: rcChkNVPathPerm.cpp:11
getUnixUid
int getUnixUid(char *userName)
Definition: rcMisc.cpp:1270
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
rsChkNVPathPerm
int rsChkNVPathPerm(rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp)
Definition: rsChkNVPathPerm.cpp:19
fileStat
irods::error fileStat(rsComm_t *, irods::first_class_object_ptr, struct stat *)
Definition: fileDriver.cpp:207
fileOpenInp_t
Definition: fileOpen.h:14
irods::file_object
Definition: irods_file_object.hpp:19
rodsServerHost
Definition: rodsConnect.h:62
irods::file_object_ptr
boost::shared_ptr< file_object > file_object_ptr
Definition: irods_file_object.hpp:145
rsChkNVPathPerm.hpp
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
dataObjOpr.hpp
remoteChkNVPathPerm
int remoteChkNVPathPerm(rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp, rodsServerHost_t *rodsServerHost)
Definition: rsChkNVPathPerm.cpp:77
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods_log.hpp