IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Utiliser Sddl.h windows


Sujet :

C++

  1. #1
    Invité
    Invité(e)
    Par défaut Utiliser Sddl.h windows
    Bonjour,
    J'essaie d'utiliser depuis 2h une fonctions qui est normalement dans Sddl.h (ConvertStringSecurityDescriptorToSecurityDescriptor) mais plusieurs erreurs :

    C:\Users\Yohann\Desktop\injector\main.cpp|63|error: 'szSD' was not declared in this scope|
    C:\Users\Yohann\Desktop\injector\main.cpp|63|error: 'SDDL_REVISION_1' was not declared in this scope|
    Je ne comprend pas pourquoi pourtant bien mis Sddl.h...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    #include <iostream>
    #include <windows.h>
    #include <wchar.h>
    #include <math.h>
    #include <time.h>
    #include <Sddl.h>
     
    using namespace std;
     
    BOOL CreateMyDACL(SECURITY_ATTRIBUTES * pSA)
    {
         // Define the SDDL for the DACL. This example sets
         // the following access:
         //     Built-in guests are denied all access.
         //     Anonymous logon is denied all access.
         //     Authenticated users are allowed
         //     read/write/execute access.
         //     Administrators are allowed full control.
         // Modify these values as needed to generate the proper
         // DACL for your application.
         TCHAR * szSD = TEXT("D:")       // Discretionary ACL
            TEXT("(D;OICI;GA;;;BG)")     // Deny access to
                                         // built-in guests
            TEXT("(D;OICI;GA;;;AN)")     // Deny access to
                                         // anonymous logon
            TEXT("(A;OICI;GRGWGX;;;AU)") // Allow
                                         // read/write/execute
                                         // to authenticated
                                         // users
            TEXT("(A;OICI;GA;;;BA)");    // Allow full control
                                         // to administrators
     
        if (NULL == pSA)
            return FALSE;
     
         return ConvertStringSecurityDescriptorToSecurityDescriptor(
                    szSD,
                    SDDL_REVISION_1,
                    &(pSA->lpSecurityDescriptor),
                    NULL);
    }
     
    int main(void)
    {
        /*if(OpenClipboard(GetForegroundWindow()))
        {
            HANDLE pText = GetClipboardData(CF_UNICODETEXT);
     
                if(pText)
                {
                    char *pchData = (char*)GlobalLock(pText);
                    char *strData = pchData;
                    GlobalUnlock(pText);
                    CloseClipboard();
                    cout <<strData;
                }
        }*/
        HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,GetCurrentProcessId());
        SECURITY_ATTRIBUTES sa;
        sa.nLength = sizeof(SECURITY_ATTRIBUTES);
        sa.lpSecurityDescriptor =
        sa.bInheritHandle = FALSE;
        if (!ConvertStringSecurityDescriptorToSecurityDescriptor(szSD, SDDL_REVISION_1, &(sa.lpSecurityDescriptor), NULL))
            wcout<<"erreur convertstring..."<<endl;
        if (!SetKernelObjectSecurity(hProcess, DACL_SECURITY_INFORMATION, sa.lpSecurityDescriptor))
            wcout<<"false"<<endl;
        Sleep(20000);
    }
    Merci

  2. #2
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    94
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 94
    Points : 122
    Points
    122
    Par défaut
    Citation Envoyé par yohann2008 Voir le message
    Bonjour,
    J'essaie d'utiliser depuis 2h une fonctions qui est normalement dans Sddl.h (ConvertStringSecurityDescriptorToSecurityDescriptor) mais plusieurs erreurs :

    C:\Users\Yohann\Desktop\injector\main.cpp|63|error: 'szSD' was not declared in this scope|
    C:\Users\Yohann\Desktop\injector\main.cpp|63|error: 'SDDL_REVISION_1' was not declared in this scope|
    Je ne comprend pas pourquoi pourtant bien mis Sddl.h...


    Salut!!

    Le code d'erreur est ici assez explicite:

    dans ton main, à la ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if (!ConvertStringSecurityDescriptorToSecurityDescriptor(szSD, SDDL_REVISION_1, &(sa.lpSecurityDescriptor), NULL));
    Le compilateur te dit qu'il ne connait pas les variables "szSD" et "SDDL_REVISION_1".

    Concernant la variable "szSD", on dirait que c'est à toi de le spécifier. Quant à "SDDL_REVISION_1", on dirait que c'est une constante présent dans le header "sddl.h".

    Tu es sûr que tu as bien include ce header là :
    http://doxygen.reactos.org/d2/d0e/sddl_8h_source.html
    ?

    EDIT: au pire ajoute un:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    #define SDDL_REVISION_1     1
    , comme c'est fait dans le header que je t'ai indiqué.

  3. #3
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    L'erreur en ligne 63, c'est que szSD est définie dans l'autre fonction uniquement. Elle n'est pas globale, et n'est pas définie dans main().
    D'ailleurs, son type devrait être const TCHAR * (alias LPCTSTR) et non pas TCHAR *.

    Pour SDDL_REVISION_1 et ConvertStringSecurityDescriptorToSecurityDescriptor non-déclarés, c'est que tu sembles utiliser MinGW, dont le <sddl.h> est ridiculement court:
    Code C/C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    #ifndef _SDDL_H
    #define _SDDL_H
    #if __GNUC__ >= 3
    #pragma GCC system_header
    #endif
     
    #ifndef WINADVAPI
    #define WINADVAPI
    #endif
     
    #ifdef __cplusplus
    extern "C" {
    #endif
     
    #if (WINVER >= 0x0500)
    WINADVAPI BOOL WINAPI ConvertSidToStringSidA(PSID Sid, LPSTR* StringSid);
    WINADVAPI BOOL WINAPI ConvertSidToStringSidW(PSID Sid, LPWSTR* StringSid);
    WINADVAPI BOOL WINAPI ConvertStringSidToSidA(LPSTR StringSid, PSID *Sid);
    WINADVAPI BOOL WINAPI ConvertStringSidToSidW(LPWSTR StringSid, PSID *Sid);
    #endif
     
    #ifdef UNICODE
    #define ConvertSidToStringSid ConvertSidToStringSidW
    #define ConvertStringSidToSid ConvertStringSidToSidW
    #else
    #define ConvertSidToStringSid ConvertSidToStringSidA
    #define ConvertStringSidToSid ConvertStringSidToSidA
    #endif
     
    #ifdef __cplusplus
    }
    #endif
     
    #endif /* _SDDL_H */
    Ces 34 lignes sont la totalité du fichier sous Code::Blocks 12.11.

    Et si tu déclares la fonction toi-même, évidemment l'import n'est pas présent dans libadvapi32.a...

    Voici ton code qui à présent compile, mais ne linke pas:
    Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    /*
    http://www.developpez.net/forums/d1409298/c-cpp/cpp/utiliser-sddl-h-windows/#post7657306
     
    */
    #define _WIN32_WINNT 0x502
    #define _WINVER 0x500
    #include <iostream>
    #include <windows.h>
    #include <wchar.h>
    #include <math.h>
    #include <time.h>
    #include <Sddl.h>
     
    extern "C"
    WINADVAPI BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptor(
    	/*_In_*/   LPCTSTR StringSecurityDescriptor,
    	/*_In_*/   DWORD StringSDRevision,
    	/*_Out_*/  PSECURITY_DESCRIPTOR *SecurityDescriptor,
    	/*_Out_*/  PULONG SecurityDescriptorSize
    );
     
    #define SDDL_REVISION_1 1
     
    using namespace std;
     
    BOOL CreateMyDACL(SECURITY_ATTRIBUTES * pSA)
    {
    	// Define the SDDL for the DACL. This example sets
    	// the following access:
    	//     Built-in guests are denied all access.
    	//     Anonymous logon is denied all access.
    	//     Authenticated users are allowed
    	//     read/write/execute access.
    	//     Administrators are allowed full control.
    	// Modify these values as needed to generate the proper
    	// DACL for your application.
    	LPCTSTR szSD = TEXT("D:")       // Discretionary ACL
    		TEXT("(D;OICI;GA;;;BG)")     // Deny access to
    		                             // built-in guests
    		TEXT("(D;OICI;GA;;;AN)")     // Deny access to
    		                             // anonymous logon
    		TEXT("(A;OICI;GRGWGX;;;AU)") // Allow
    		                             // read/write/execute
    		                             // to authenticated
    		                             // users
    		TEXT("(A;OICI;GA;;;BA)");    // Allow full control
    		                             // to administrators
     
    	if (NULL == pSA)
    		return FALSE;
     
    	return ConvertStringSecurityDescriptorToSecurityDescriptor(
    		szSD,
    		SDDL_REVISION_1,
    		reinterpret_cast< PSECURITY_DESCRIPTOR * >(&(pSA->lpSecurityDescriptor)),
    		NULL);
    }
     
    int main(void)
    {
    	HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,GetCurrentProcessId());
    	SECURITY_ATTRIBUTES sa;
    	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    	sa.lpSecurityDescriptor = NULL;
    	sa.bInheritHandle = FALSE;
     
    	LPCTSTR szSD = TEXT("D:(D;OICI;GA;;;BG)(D;OICI;GA;;;AN)(A;OICI;GRGWGX;;;AU)(A;OICI;GA;;;BA)");    // Allow full control
     
    	PSECURITY_DESCRIPTOR psd = NULL;
    	if (!ConvertStringSecurityDescriptorToSecurityDescriptor(szSD, SDDL_REVISION_1, &psd, NULL))
    		wcout << L"erreur convertstring..." << endl;
    	sa.lpSecurityDescriptor = psd;
    	if (!SetKernelObjectSecurity(hProcess, DACL_SECURITY_INFORMATION, psd))
    		wcout << L"false" << endl;
    	Sleep(20000);
    }
    La morale de l'histoire, c'est que MinGW est encore très en retard, et que pour ce genre de choses il vaut mieux utiliser Visual.

    Je suppose que tu ne peux pas, aussi tu vas devoir jouer avec LoadLibrary() et GetProcAddress() à la place.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  4. #4
    Invité
    Invité(e)
    Par défaut
    Ok , merci a vous deux j'essayerais de passer sous visual studio j'aurais du m'en douter pour utiliser l'api windows
    sinon ton code ne compile pas :
    obj\Release\main.o:main.cpp|| undefined reference to `ConvertStringSecurityDescriptorToSecurityDescriptor@16'|
    obj\Release\main.o:main.cpp.text.startup+0x5f)||undefined reference to `ConvertStringSecurityDescriptorToSecurityDescriptor@16'|

  5. #5
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Ce n'est pas une erreur de compilation, mais une erreur de linkage: comme je l'ai dit, ça compile, mais ça ne linke pas.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  6. #6
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Pour mieux comprendre de quoi parle Médinoc, vous pouvez lire ce tutoriel : http://alexandre-laurent.developpez....-bibliotheque/
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

Discussions similaires

  1. [Cygwin]Comment utiliser gprof avec Windows ?
    Par Invité dans le forum Autres éditeurs
    Réponses: 1
    Dernier message: 04/02/2006, 12h36
  2. Utiliser FD_SET sous Windows sur l'entré STDIN ?
    Par MonsieurAk dans le forum Windows
    Réponses: 6
    Dernier message: 09/12/2005, 20h45
  3. [VB]Comment utiliser les variables Windows?
    Par Furius dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 13/10/2005, 21h20
  4. Identification utilisant le username windows
    Par j_bolduc dans le forum ASP
    Réponses: 3
    Dernier message: 13/09/2005, 17h19
  5. [Utilisation Postgresql sur windows]
    Par xhercule dans le forum PostgreSQL
    Réponses: 6
    Dernier message: 26/01/2004, 18h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo