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 #include "precomp.h"
00030 #include "security_identifier.h"
00031 #include "exception.h"
00032 #ifdef WIN32
00033 #include <AclAPI.h>
00034 #endif
00035
00037
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 ©)
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
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
00144
00145 CL_SecurityIdentifier &CL_SecurityIdentifier::operator =(const CL_SecurityIdentifier ©)
00146 {
00147 sid = copy.sid;
00148 type = copy.type;
00149 return *this;
00150 }
00151
00153