00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "OW_config.h"
00032
00033 #ifdef OW_NETWARE
00034
00035 #include "OW_NetwareIdentity.hpp"
00036
00037 #include <iostream>
00038 using std::cerr;
00039 using std::endl;
00040
00041 extern "C"
00042 {
00043 #include <client.h>
00044 #include <fsio.h>
00045 }
00046
00047 namespace OW_NAMESPACE
00048 {
00049
00050 namespace
00051 {
00052
00053 int
00054 doSetcwd(NXPathCtx_t pathCtx)
00055 {
00056 int cc = setcwd2(pathCtx);
00057 if (cc != 0)
00058 {
00059 cerr << "** NetwareIdentity; setcwd2 failed: ";
00060 switch (cc)
00061 {
00062 case 4:
00063 cerr << "Invalid file descriptor" << endl;
00064 break;
00065 case 5:
00066 cerr << "Insufficient memory" << endl;
00067 break;
00068 case 9:
00069 cerr << "Invalid parameter" << endl;
00070 break;
00071 case 28:
00072 cerr << "Volume not mounted or file system error" << endl;
00073 break;
00074 case 65:
00075 cerr << "File system name for a path component is too long"
00076 << endl;
00077 break;
00078 case 67:
00079 cerr << "Object is not a directory" << endl;
00080 break;
00081 case 79:
00082 cerr << "Operation is not supported in the manner requested"
00083 << endl;
00084 break;
00085 case 105:
00086 cerr << "thread context is invalid or not available"
00087 << endl;
00088 break;
00089 case 106:
00090 cerr << "Name space is invalid" << endl;
00091 break;
00092 case 107:
00093 cerr << "NCP connection is not valid" << endl;
00094 break;
00095 case 114:
00096 cerr << "Security badge is invalid" << endl;
00097 break;
00098 default:
00099 cerr << "Error = " << cc << endl;
00100 break;
00101 }
00102 }
00103
00104 return cc;
00105 }
00106
00107 }
00108
00110 NetwareIdentity::NetwareIdentity()
00111 : OperationContext::Data()
00112 , m_identity(0)
00113 , m_pathContext(0)
00114 , m_userName()
00115 , m_userDN()
00116 , m_valid(false)
00117 , m_isAdmin(false)
00118 {
00119 }
00120
00122 NetwareIdentity::NetwareIdentity(int identity, NXPathCtx_t pathContext,
00123 const String& userName, const String& userDN, bool m_isAdmin)
00124 : OperationContext::Data()
00125 , m_identity(identity)
00126 , m_pathContext(pathContext)
00127 , m_userName(userName)
00128 , m_userDN(userDN)
00129 , m_valid(true)
00130 , m_isAdmin(false)
00131 {
00132 int error;
00133 if (!is_valid_identity(m_identity, &error))
00134 {
00135 m_valid = false;
00136 cerr << "** Invalid identity passed to NetwareIdentity CTOR: ";
00137 switch (error)
00138 {
00139 case 22:
00140 cerr << "Bad identity. Could not be found" << endl;
00141 break;
00142 case 105:
00143 cerr << "Thread has no context" << endl;
00144 default:
00145 cerr << "Error = " << error << endl;
00146 }
00147 }
00148 }
00149
00151 NetwareIdentity::~NetwareIdentity()
00152 {
00153 if (m_valid && !m_isAdmin)
00154 {
00155 int cc = NXFreePathContext(m_pathContext);
00156 if(cc != 0)
00157 {
00158 cerr << "** NXFreePathContext Failed: ";
00159 switch (cc)
00160 {
00161 case 4:
00162 cerr << "Invalid path context" << endl;
00163 break;
00164 case 105:
00165 cerr << "Thread has no NKS context" << endl;
00166 default:
00167 cerr << "Error = " << cc << endl;
00168 }
00169 }
00170
00171 delete_identity(m_identity);
00172 }
00173 }
00174
00176 bool
00177 NetwareIdentity::setContextToUser() const
00178 {
00179 bool cc = (m_isAdmin) ? m_isAdmin : m_valid;
00180
00181 if (cc)
00182 {
00183 if(doSetcwd(m_pathContext) != 0)
00184 {
00185 cc = false;
00186 }
00187 }
00188
00189 return cc;
00190 }
00191
00193 bool
00194 NetwareIdentity::setContextToAdmin() const
00195 {
00196 bool cc = (m_isAdmin) ? m_isAdmin : m_valid;
00197
00198 if (cc)
00199 {
00200 if (doSetcwd(0) != 0)
00201 {
00202 cc = false;
00203 }
00204 }
00205
00206 return cc;
00207 }
00208
00210 String
00211 NetwareIdentity::getUserDN() const
00212 {
00213 return m_userDN;
00214 }
00215
00217 String
00218 NetwareIdentity::getUserName() const
00219 {
00220 return m_userName;
00221 }
00222
00224 void
00225 NetwareIdentity::setAdminFlag(bool isAdmin)
00226 {
00227 m_isAdmin = isAdmin;
00228 }
00229
00230 }
00231
00232 #endif // OW_NETWARE
00233