Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

security_identifier.cpp

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2005 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00029 #include "precomp.h"
00030 #include "security_identifier.h"
00031 #include "exception.h"
00032 #ifdef WIN32
00033 #include <AclAPI.h>
00034 #endif
00035 
00037 // CL_SecurityIdentifier Construction:
00038 
00039 CL_SecurityIdentifier::CL_SecurityIdentifier(const CL_String &name)
00040 : type(type_invalid)
00041 {
00042         throw CL_Exception(TEXT("CL_SecurityIdentifier(const CL_String &name) not implemented"));
00043 }
00044         
00045 CL_SecurityIdentifier::CL_SecurityIdentifier(const CL_String &name, Type type)
00046 : type(type)
00047 {
00048         throw CL_Exception(TEXT("CL_SecurityIdentifier(const CL_String &name) not implemented"));
00049 }
00050 
00051 #ifdef WIN32
00052 CL_SecurityIdentifier::CL_SecurityIdentifier(const PSID new_sid)
00053 : type(type_unknown)
00054 {
00055         sid.set_size(GetLengthSid(new_sid));
00056         memcpy(sid.get_data(), new_sid, sid.get_size());
00057 }
00058 #else
00059 CL_SecurityIdentifier::CL_SecurityIdentifier(unsigned int sid, Type type)
00060 : sid(sid), type(type)
00061 {
00062 }
00063 #endif
00064 
00065 CL_SecurityIdentifier::CL_SecurityIdentifier(const CL_SecurityIdentifier &copy)
00066 : sid(copy.sid), type(copy.type)
00067 {
00068 }
00069 
00070 CL_SecurityIdentifier::~CL_SecurityIdentifier()
00071 {
00072 }
00073 
00074 CL_SecurityIdentifier CL_SecurityIdentifier::get_thread_user()
00075 {
00076 #ifdef WIN32
00077         PSID pSid = 0;
00078         PSECURITY_DESCRIPTOR securityDescriptor = 0;
00079         DWORD result = GetSecurityInfo(
00080                 GetCurrentThread(),
00081                 SE_KERNEL_OBJECT,
00082                 OWNER_SECURITY_INFORMATION,
00083                 &pSid,
00084                 0,
00085                 0,
00086                 0,
00087                 &securityDescriptor);
00088         if (result != ERROR_SUCCESS)
00089                 throw CL_Exception(TEXT("Unable to get thread user SID"));
00090 
00091         CL_SecurityIdentifier identifier(pSid);
00092         LocalFree(securityDescriptor);
00093         return identifier;
00094 #else
00095         return CL_SecurityIdentifier(getuid(), type_user);
00096 #endif
00097 }
00098         
00099 CL_SecurityIdentifier CL_SecurityIdentifier::get_thread_group()
00100 {
00101 #ifdef WIN32
00102         PSID pSid = 0;
00103         PSECURITY_DESCRIPTOR securityDescriptor = 0;
00104         DWORD result = GetSecurityInfo(
00105                 GetCurrentThread(),
00106                 SE_KERNEL_OBJECT,
00107                 GROUP_SECURITY_INFORMATION,
00108                 0,
00109                 &pSid,
00110                 0,
00111                 0,
00112                 &securityDescriptor);
00113         if (result != ERROR_SUCCESS)
00114                 throw CL_Exception(TEXT("Unable to get thread user SID"));
00115 
00116         CL_SecurityIdentifier identifier(pSid);
00117         LocalFree(securityDescriptor);
00118         return identifier;
00119 #else
00120         return CL_SecurityIdentifier(getgid(), type_group);
00121 #endif
00122 }
00123 
00125 // CL_SecurityIdentifier Attributes:
00126 
00127 CL_String CL_SecurityIdentifier::get_name() const
00128 {
00129         return CL_String();
00130 }
00131 
00132 CL_String CL_SecurityIdentifier::get_domain_name() const
00133 {
00134         return CL_String();
00135 }
00136 
00137 CL_SecurityIdentifier::Type CL_SecurityIdentifier::get_type() const
00138 {
00139         return type;
00140 }
00141 
00143 // CL_SecurityIdentifier Operations:
00144 
00145 CL_SecurityIdentifier &CL_SecurityIdentifier::operator =(const CL_SecurityIdentifier &copy)
00146 {
00147         sid = copy.sid;
00148         type = copy.type;
00149         return *this;
00150 }
00151 
00153 // CL_SecurityIdentifier Implementation:

Generated on Sat Feb 19 22:51:16 2005 for npcore by  doxygen 1.4.1