Il existe maintenant des API de sécurité pour Client Access 95/NT, indépendantes du protocole. Elles permettent de se signer automatiquement et de gérer le mot de passe. en voici la liste : .......................................................................... : cwbSY_CreateSecurityObj : >> API d'initilisation = OBLIGATOIRE: : cwbSY_SetSys : définit le système à utiliser : : cwbSY_GetDateTimeCurrentSignon : retrouve date/heure de debut session: : cwbSY_GetDateTimeLastSignon : retrouve date/heure dernier signon : : cwbSY_GetDateTimePwdExpires : retrouve date/heure expiration pwd : : cwbSY_GetFailedAttempts : retrouve nbr de tentatives invalides: : cwbSY_GetUserID : retrouve user en cours : : cwbSY_Logon : affiche le fenêtre de logon : : cwbSY_LogonUser : établit une session (sans fenêtre) : : cwbSY_VerifyUserIDPwd : vérifier le mot de passe d'un user : : cwbSY_ChangePwd : Modifier le mot de passe d'un user : : cwbSY_DeleteSecurityObj : >> API destruction = Ménage de fin : :..................................:.....................................: |
Pour toutes ces API vous devez passer par une phase d'initialisation de l'objet sécurité, par l'API cwbSY_CreateSecurityObj. Celle-ci vous retourne un identifiant (handle) de type "long", cet identifiant est à utiliser avec toutes les APIs qui suiverons. Vous devez détruire l'objet avec l'API cwbSY_DeleteSecurityObj. toutes ces fonctions retournent un code erreur de type "int" (integer) que vous devez tester afin de savoir ce qui s'est passé. les codes sont fournis dans cwb.h et CWBSY.H voici un extrait d'un source en C, livré avec l'option de Client Access : Application Development Toolkit chemin : "Program files\ibm\client access\toolkit\sample\c\security" |
/******************************************************************* /* This sample program can be used to verify that a user's ID and password are valid for a system and if so to change the password for that user. */ /******************************************************************* /* Include API header files */ #include "cwb.h" /* Client Access API header file. */ #include "cwbsy.h" /* Security API header file. */ #include "cwbsv.h" /* Service/Error header file. */ void main() { /* First we must setup the required data items. */ |
unsigned int rc; /* Used to hold the return code. */ cwbSY_SecurityHandle aHandle; /* Used to hold a handle to a security object. */ cwbSV_ErrHandle errHandle; /* Used to hold a handle to an error object. */ /* To access any error messages that are generated, you need to create an error object: */ rc = cwbSV_CreateErrHandle(&errHandle); /* To use the security APIs you'll first need to create a security object to work with. */ rc = cwbSY_CreateSecurityObj(&aHandle); /* Now you have a security object. So, next you need to set the name of the system. */ rc = cwbSY_SetSys(aHandle, "SYS1"); /* |
The object is now ready to verify the userid and password. */ rc = cwbSY_VerifyUserIDPwd(aHandle, "USER", "PASSWORD", errHandle); /* Check the return codes. If you receive a non-successful return code you can retreive the error messages from the error object. See the cwbsv.h header file for more information. */ if (rc == CWB_OK) { /* The user ID and password were verified to exist and be correct so lets change the password. */ rc = cwbSY_ChangePwd(aHandle, "USER", "PASSWORD", "NEWPASSWRD", errHandle); |
if (rc == CWB_OK) { /* The password was changed for the user ID. You could put some code here to perform other functions based on this success. */ } else { /* The password was not changed for the user ID. You could put some code here to display an error message or to prompt the user for new input. */ } } /* Now we must perform some clean up work so we will delete the security object when you are finished. */ rc = cwbSY_DeleteSecurityObj(aHandle); } |
En ce qui concerne l'API cwbSY_Logon, elle affiche la fenêtre d'ouverture de session, SI vous n'êtes pas connecté. + paramètres - handle retourné par cwbSY_CreateSecurityObj L'API cwbSY_LogonUser, elle, établit une session avec user et mot de passe fournis en paramètre. + paramètres - handle retourné par cwbSY_CreateSecurityObj - profil (10 c. plus la terminaison de fin de chaîne en c) - password (idem profil) - handle retourné par cwbSV_CreateErrHandle |