OW_NetwareIdentity.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Novell, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Novell, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
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 }  // End of anonymous namespace
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 }  // End of namespace OpenWBEM
00231 
00232 #endif   // OW_NETWARE
00233 

Generated on Thu Feb 9 08:48:07 2006 for openwbem by  doxygen 1.4.6