void SigHandler (int sig) { int ThreadGroupId; switch (sig) { case SIGTERM: // tell the NLM its exiting, and save the console threadid, recovering the main threadid NlmExiting = TRUE; ThreadGroupId = SetThreadGroupID (MainThreadGroupId); // if the NLM is waiting on the user, stuff an enter keypress into the keyboard buffer if (AwaitingInput) ungetch (KEY_ENTER); // allow the NLM to finish cleanly while (ThreadCount != 0) ThreadSwitchWithDelay (); // restore the console threadid SetThreadGroupID (ThreadGroupId); break; } return; }
void NLM_SignalHandler(int sig) #pragma on(unreferenced); { int handlerThreadGroupID; switch(sig) { case SIGTERM: NLM_exiting = TRUE; handlerThreadGroupID = GetThreadGroupID(); SetThreadGroupID(NLM_mainThreadGroupID); /* NLM SDK functions may be called here */ while (NLM_threadCnt != 0) ThreadSwitchWithDelay(); SetThreadGroupID(handlerThreadGroupID); break; case SIGINT: signal(SIGINT, NLM_SignalHandler); break; } return; }
/* ----------------------------------------------------------------------- * nmasldap_get_password() * ============================== * * Description: * This API attempts to get the universal password * * ------------------------------------------------------------------------ */ int nmasldap_get_password( LDAP *ld, char *objectDN, size_t *pwdSize, // in bytes char *pwd ) { int err = 0; struct berval *requestBV = NULL; char *replyOID = NULL; struct berval *replyBV = NULL; int serverVersion; char *pwdBuf; size_t pwdBufLen, bufferLen; #ifdef NOT_N_PLAT_NLM int currentThreadGroupID; #endif /* Validate char parameters. */ if(objectDN == NULL || (strlen(objectDN) == 0) || pwdSize == NULL || ld == NULL) { return NMAS_E_INVALID_PARAMETER; } bufferLen = pwdBufLen = *pwdSize; pwdBuf = (char *)malloc(pwdBufLen+2); if(pwdBuf == NULL) { return NMAS_E_INSUFFICIENT_MEMORY; } #ifdef NOT_N_PLAT_NLM currentThreadGroupID = SetThreadGroupID(nmasLDAPThreadGroupID); #endif err = berEncodePasswordData(&requestBV, objectDN, NULL, NULL); if(err) { goto Cleanup; } /* Call the ldap_extended_operation (synchronously) */ if((err = ldap_extended_operation_s(ld, NMASLDAP_GET_PASSWORD_REQUEST, requestBV, NULL, NULL, &replyOID, &replyBV))) { goto Cleanup; } /* Make sure there is a return OID */ if(!replyOID) { err = NMAS_E_NOT_SUPPORTED; goto Cleanup; } /* Is this what we were expecting to get back. */ if(strcmp(replyOID, NMASLDAP_GET_PASSWORD_RESPONSE)) { err = NMAS_E_NOT_SUPPORTED; goto Cleanup; } /* Do we have a good returned berval? */ if(!replyBV) { /* * No; returned berval means we experienced a rather drastic error. * Return operations error. */ err = NMAS_E_SYSTEM_RESOURCES; goto Cleanup; } err = berDecodeLoginData(replyBV, &serverVersion, &pwdBufLen, pwdBuf); if(serverVersion != NMAS_LDAP_EXT_VERSION) { err = NMAS_E_INVALID_VERSION; goto Cleanup; } if (!err && pwdBufLen != 0) { if (*pwdSize >= pwdBufLen+1 && pwd != NULL) { memcpy(pwd, pwdBuf, pwdBufLen); pwd[pwdBufLen] = 0; /* add null termination */ } *pwdSize = pwdBufLen; /* does not include null termination */ } Cleanup: if(replyBV) { ber_bvfree(replyBV); } /* Free the return OID string if one was returned. */ if(replyOID) { ldap_memfree(replyOID); } /* Free memory allocated while building the request ber and berval. */ if(requestBV) { ber_bvfree(requestBV); } if (pwdBuf != NULL) { memset(pwdBuf, 0, bufferLen); free(pwdBuf); } #ifdef NOT_N_PLAT_NLM SetThreadGroupID(currentThreadGroupID); #endif /* Return the appropriate error/success code. */ return err; } /* end of nmasldap_get_password */