Loading src/secureid.c +27 −8 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include "stdio.h" #include "sys/mman.h" #include "secureid.h" Loading Loading @@ -103,7 +105,8 @@ void initSID(struct SID **sid){ *sid=map32(sizeof(struct SID)); (*sid)->Revesion=1; (*sid)->SubAuthorityCount=1; setAuthority(*sid,NullAccount,0,0); setAuthority(*sid,NullAccount); setSubAuthority(*sid,0,0); }; void destroySID(struct SID *sid){ Loading @@ -126,7 +129,15 @@ int SIDcpy(struct SID *dest,struct SID *src){ return written+sizeof(struct SID); }; void setAuthority(struct SID *sid,Authority authority,uint32_t* uid,uint8_t count){ void setAuthority(struct SID *sid,Authority authority){ int i; for(i=0; i<6; ++i){ sid->IdentifierAuthority.Value[i]=authority[i]; } } void setSubAuthority(struct SID *sid,uint32_t* uid,uint8_t count){ if(sid->SubAuthorityCount!=0){ munmap(sid->SubAuthority[1],(sizeof(uint32_t)*sid->SubAuthorityCount)); } Loading @@ -135,12 +146,6 @@ void setAuthority(struct SID *sid,Authority authority,uint32_t* uid,uint8_t coun memcpy32(sid->SubAuthority[1],uid, (count * sizeof(uint32_t))); int i; for(i=0; i<6; ++i){ sid->IdentifierAuthority.Value[i]=authority[i]; } sid->SubAuthorityCount=count; } Loading Loading @@ -223,6 +228,20 @@ int printSID(struct SID *sid,char *output,int size){ void generateDomainIdentfier(uint32_t* output, int count){ //the last place will be used for the real user id --count; FILE *devrandom; devrandom = fopen("/dev/random","ro"); for(int i=0; i<count; ++i){ for(char ii=0; ii<sizeof(uint32_t); ++ii){ output[i]= output[i] | getc(devrandom); } } fclose(devrandom); } void setRid(struct SID* sid, uint32_t rid){ Loading src/secureid.h +9 −2 Original line number Diff line number Diff line Loading @@ -110,14 +110,21 @@ extern "C" { int SIDcpy(struct SID *dest,struct SID *src); /*! \fn setAuthority(struct SID *sid,Authority authority,uint32_t* uid,uint8_t count) \fn setAuthority(struct SID *sid,Authority authority) \brief This function will set your Authority for example NT look for Authority type. \param sid SID struct set will be the value set \param authority type of authority that genarated the Identifier */ void setAuthority(struct SID *sid,Authority authority); /*! \fn setSubAuthority(struct SID *sid,uint32_t* uid,uint8_t count) \brief This function will set your SubAuthority. \param sid SID struct set will be the value set \param uid the indentifier array that will you set \param count the indentifier array size */ void setAuthority(struct SID *sid,Authority authority,uint32_t* uid,uint8_t count); void setSubAuthority(struct SID *sid,uint32_t* uid,uint8_t count); /*! \fn int parseSID(struct SID *sid,const char *input,int size) Loading test/CMakeLists.txt +5 −0 Original line number Diff line number Diff line Loading @@ -12,3 +12,8 @@ add_executable(rid rid.c) target_link_libraries(rid secureid) add_test(NAME rid COMMAND $<TARGET_FILE:rid> "${CMAKE_SOURCE_DIR}/test/sid.txt") add_executable(gendomain gendomain.c) target_link_libraries(gendomain secureid) add_test(NAME gendomain COMMAND $<TARGET_FILE:gendomain>) test/gendomain.c 0 → 100644 +54 −0 Original line number Diff line number Diff line /******************************************************************************* * Copyright (c) 2023, Jan Koester jan.koester@gmx.net * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include "stdio.h" #include "string.h" #include "secureid.h" int main(int argc, char *argv[]){ char sidc[512]; struct SID *sid; initSID(&sid); uint32_t ident[4]; setAuthority(sid,NT); generateDomainIdentfier(ident,4); setRid(sid,1001); setSubAuthority(sid,ident,4); printSID(sid,sidc,512); destroySID(sid); printf("%s",sidc); return 0; } Loading
src/secureid.c +27 −8 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include "stdio.h" #include "sys/mman.h" #include "secureid.h" Loading Loading @@ -103,7 +105,8 @@ void initSID(struct SID **sid){ *sid=map32(sizeof(struct SID)); (*sid)->Revesion=1; (*sid)->SubAuthorityCount=1; setAuthority(*sid,NullAccount,0,0); setAuthority(*sid,NullAccount); setSubAuthority(*sid,0,0); }; void destroySID(struct SID *sid){ Loading @@ -126,7 +129,15 @@ int SIDcpy(struct SID *dest,struct SID *src){ return written+sizeof(struct SID); }; void setAuthority(struct SID *sid,Authority authority,uint32_t* uid,uint8_t count){ void setAuthority(struct SID *sid,Authority authority){ int i; for(i=0; i<6; ++i){ sid->IdentifierAuthority.Value[i]=authority[i]; } } void setSubAuthority(struct SID *sid,uint32_t* uid,uint8_t count){ if(sid->SubAuthorityCount!=0){ munmap(sid->SubAuthority[1],(sizeof(uint32_t)*sid->SubAuthorityCount)); } Loading @@ -135,12 +146,6 @@ void setAuthority(struct SID *sid,Authority authority,uint32_t* uid,uint8_t coun memcpy32(sid->SubAuthority[1],uid, (count * sizeof(uint32_t))); int i; for(i=0; i<6; ++i){ sid->IdentifierAuthority.Value[i]=authority[i]; } sid->SubAuthorityCount=count; } Loading Loading @@ -223,6 +228,20 @@ int printSID(struct SID *sid,char *output,int size){ void generateDomainIdentfier(uint32_t* output, int count){ //the last place will be used for the real user id --count; FILE *devrandom; devrandom = fopen("/dev/random","ro"); for(int i=0; i<count; ++i){ for(char ii=0; ii<sizeof(uint32_t); ++ii){ output[i]= output[i] | getc(devrandom); } } fclose(devrandom); } void setRid(struct SID* sid, uint32_t rid){ Loading
src/secureid.h +9 −2 Original line number Diff line number Diff line Loading @@ -110,14 +110,21 @@ extern "C" { int SIDcpy(struct SID *dest,struct SID *src); /*! \fn setAuthority(struct SID *sid,Authority authority,uint32_t* uid,uint8_t count) \fn setAuthority(struct SID *sid,Authority authority) \brief This function will set your Authority for example NT look for Authority type. \param sid SID struct set will be the value set \param authority type of authority that genarated the Identifier */ void setAuthority(struct SID *sid,Authority authority); /*! \fn setSubAuthority(struct SID *sid,uint32_t* uid,uint8_t count) \brief This function will set your SubAuthority. \param sid SID struct set will be the value set \param uid the indentifier array that will you set \param count the indentifier array size */ void setAuthority(struct SID *sid,Authority authority,uint32_t* uid,uint8_t count); void setSubAuthority(struct SID *sid,uint32_t* uid,uint8_t count); /*! \fn int parseSID(struct SID *sid,const char *input,int size) Loading
test/CMakeLists.txt +5 −0 Original line number Diff line number Diff line Loading @@ -12,3 +12,8 @@ add_executable(rid rid.c) target_link_libraries(rid secureid) add_test(NAME rid COMMAND $<TARGET_FILE:rid> "${CMAKE_SOURCE_DIR}/test/sid.txt") add_executable(gendomain gendomain.c) target_link_libraries(gendomain secureid) add_test(NAME gendomain COMMAND $<TARGET_FILE:gendomain>)
test/gendomain.c 0 → 100644 +54 −0 Original line number Diff line number Diff line /******************************************************************************* * Copyright (c) 2023, Jan Koester jan.koester@gmx.net * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include "stdio.h" #include "string.h" #include "secureid.h" int main(int argc, char *argv[]){ char sidc[512]; struct SID *sid; initSID(&sid); uint32_t ident[4]; setAuthority(sid,NT); generateDomainIdentfier(ident,4); setRid(sid,1001); setSubAuthority(sid,ident,4); printSID(sid,sidc,512); destroySID(sid); printf("%s",sidc); return 0; }