本文整理汇总了C++中PR_GetError函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_GetError函数的具体用法?C++ PR_GetError怎么用?C++ PR_GetError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_GetError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cert_stuff
static CURLcode cert_stuff(struct connectdata *conn, int sockindex,
char *cert_file, char *key_file)
{
struct SessionHandle *data = conn->data;
CURLcode rv;
if(cert_file) {
rv = nss_load_cert(&conn->ssl[sockindex], cert_file, PR_FALSE);
if(CURLE_OK != rv) {
const PRErrorCode err = PR_GetError();
if(!display_error(conn, err, cert_file)) {
const char *err_name = nss_error_to_name(err);
failf(data, "unable to load client cert: %d (%s)", err, err_name);
}
return rv;
}
}
if(key_file || (is_file(cert_file))) {
if(key_file)
rv = nss_load_key(conn, sockindex, key_file);
else
/* In case the cert file also has the key */
rv = nss_load_key(conn, sockindex, cert_file);
if(CURLE_OK != rv) {
const PRErrorCode err = PR_GetError();
if(!display_error(conn, err, key_file)) {
const char *err_name = nss_error_to_name(err);
failf(data, "unable to load client key: %d (%s)", err, err_name);
}
return rv;
}
}
return CURLE_OK;
}
示例2: PrintPRError
void
PrintPRError(const char *aPrefix)
{
const char *err = PR_ErrorToName(PR_GetError());
if (err) {
if (gDebugLevel >= DEBUG_ERRORS) {
fprintf(stderr, "%s: %s\n", aPrefix, err);
}
} else {
if (gDebugLevel >= DEBUG_ERRORS) {
fprintf(stderr, "%s\n", aPrefix);
}
}
}
示例3: pkcs11_login
int pkcs11_login(pkcs11_handle_t *h, char *password)
{
SECStatus rv;
if (h->slot == NULL) {
DBG("Login failed: No Slot selected");
return -1;
}
rv = PK11_Authenticate(h->slot, PR_FALSE, password);
if (rv != SECSuccess) {
DBG1("Login failed: %s", SECU_Strerror(PR_GetError()));
}
return (rv == SECSuccess) ? 0 : -1;
}
示例4: main
int main(int argc, char **argv)
{
PR_STDIO_INIT();
t1 = PR_Open(NO_SUCH_FILE, PR_RDONLY, 0666);
if (t1 == NULL) {
if (PR_GetError() == PR_FILE_NOT_FOUND_ERROR) {
printf ("error code is PR_FILE_NOT_FOUND_ERROR, as expected\n");
printf ("PASS\n");
return 0;
} else {
printf ("error code is %d \n", PR_GetError());
printf ("FAIL\n");
return 1;
}
}
printf ("File %s exists on this machine!?\n", NO_SUCH_FILE);
if (PR_Close(t1) == PR_FAILURE) {
printf ("cannot close file\n");
printf ("error code is %d \n", PR_GetError());
}
printf ("FAIL\n");
return 1;
}
示例5: load_pkcs11_module
/*
* NSS allows you to load a specific module. If the user specified a module
* to load, load it, otherwize select on of the standard modules from the
* secmod.db list.
*/
int load_pkcs11_module(const char *pkcs11_module, pkcs11_handle_t **hp)
{
pkcs11_handle_t *h = (pkcs11_handle_t *)calloc(sizeof(pkcs11_handle_t),1);
SECMODModule *module = NULL;
#define SPEC_TEMPLATE "library=\"%s\" name=\"SmartCard\""
char *moduleSpec = NULL;
if (!pkcs11_module || (strcasecmp(pkcs11_module,"any module") == 0)) {
h->is_user_module = PR_FALSE;
h->module = NULL;
*hp = h;
return 0;
}
/* found it, use the existing module */
module = find_module_by_library(pkcs11_module);
if (module) {
h->is_user_module = PR_FALSE;
h->module = module;
*hp = h;
return 0;
}
/* specified module is not already loaded, load it now */
moduleSpec = malloc(sizeof(SPEC_TEMPLATE) + strlen(pkcs11_module));
if (!moduleSpec) {
DBG1("Malloc failed when allocating module spec", strerror(errno));
free (h);
return -1;
}
sprintf(moduleSpec,SPEC_TEMPLATE, pkcs11_module);
DBG2("loading Module explictly, moduleSpec=<%s> module=%s",
moduleSpec, pkcs11_module);
module = SECMOD_LoadUserModule(moduleSpec, NULL, 0);
free(moduleSpec);
if ((!module) || !module->loaded) {
DBG1("Failed to load SmartCard software %s", SECU_Strerror(PR_GetError()));
free (h);
if (module) {
SECMOD_DestroyModule(module);
}
return -1;
}
h->is_user_module = PR_TRUE;
h->module = module;
*hp = h;
DBG("load module complete");
return 0;
}
示例6: SpawnIOChild
static bool
SpawnIOChild(char* const* aArgs, PRProcess** aPID,
PRFileDesc** aFromChildFD, PRFileDesc** aToChildFD)
{
PRFileDesc* toChildPipeRead;
PRFileDesc* toChildPipeWrite;
if (PR_CreatePipe(&toChildPipeRead, &toChildPipeWrite) != PR_SUCCESS)
return false;
PR_SetFDInheritable(toChildPipeRead, true);
PR_SetFDInheritable(toChildPipeWrite, false);
PRFileDesc* fromChildPipeRead;
PRFileDesc* fromChildPipeWrite;
if (PR_CreatePipe(&fromChildPipeRead, &fromChildPipeWrite) != PR_SUCCESS) {
PR_Close(toChildPipeRead);
PR_Close(toChildPipeWrite);
return false;
}
PR_SetFDInheritable(fromChildPipeRead, false);
PR_SetFDInheritable(fromChildPipeWrite, true);
PRProcessAttr* attr = PR_NewProcessAttr();
if (!attr) {
PR_Close(fromChildPipeRead);
PR_Close(fromChildPipeWrite);
PR_Close(toChildPipeRead);
PR_Close(toChildPipeWrite);
return false;
}
PR_ProcessAttrSetStdioRedirect(attr, PR_StandardInput, toChildPipeRead);
PR_ProcessAttrSetStdioRedirect(attr, PR_StandardOutput, fromChildPipeWrite);
PRProcess* process = PR_CreateProcess(aArgs[0], aArgs, nullptr, attr);
PR_DestroyProcessAttr(attr);
PR_Close(fromChildPipeWrite);
PR_Close(toChildPipeRead);
if (!process) {
LOG(("ntlm_auth exec failure [%d]", PR_GetError()));
PR_Close(fromChildPipeRead);
PR_Close(toChildPipeWrite);
return false;
}
*aPID = process;
*aFromChildFD = fromChildPipeRead;
*aToChildFD = toChildPipeWrite;
return true;
}
示例7: FastFetchFile
PRStatus FastFetchFile(PRFileDesc *in, PRFileDesc *out, PRUint32 size)
{
PRInt32 nBytes;
PRFileMap *outfMap;
void *addr;
char *start;
PRUint32 rem;
PRUint32 bytesToRead;
PRStatus rv;
PRInt64 sz64;
LL_UI2L(sz64, size);
outfMap = PR_CreateFileMap(out, sz64, PR_PROT_READWRITE);
PR_ASSERT(outfMap);
addr = PR_MemMap(outfMap, LL_ZERO, size);
if (addr == (void *) -1) {
fprintf(stderr, "cannot memory-map file: (%d, %d)\n", PR_GetError(),
PR_GetOSError());
PR_CloseFileMap(outfMap);
return PR_FAILURE;
}
PR_ASSERT(addr != (void *) -1);
start = (char *) addr;
rem = size;
while ((nBytes = DrainInputBuffer(start, rem)) > 0) {
start += nBytes;
rem -= nBytes;
}
if (nBytes < 0) {
/* Input buffer is empty and end of stream */
return PR_SUCCESS;
}
bytesToRead = (rem < FCOPY_BUFFER_SIZE) ? rem : FCOPY_BUFFER_SIZE;
while (rem > 0 && (nBytes = PR_Read(in, start, bytesToRead)) > 0) {
start += nBytes;
rem -= nBytes;
bytesToRead = (rem < FCOPY_BUFFER_SIZE) ? rem : FCOPY_BUFFER_SIZE;
}
if (nBytes < 0) {
fprintf(stderr, "httpget: cannot read from socket\n");
return PR_FAILURE;
}
rv = PR_MemUnmap(addr, size);
PR_ASSERT(rv == PR_SUCCESS);
rv = PR_CloseFileMap(outfMap);
PR_ASSERT(rv == PR_SUCCESS);
return PR_SUCCESS;
}
示例8: _NSFC_PR_NT_CancelIo
static void
_NSFC_PR_NT_CancelIo(PRFileDesc *fd)
{
#ifdef XP_WIN32
PRErrorCode prerr = PR_GetError();
PRInt32 oserr = PR_GetOSError();
/* Attempt to load PR_NT_CancelIo() from the DLL that contains PR_Send() */
static PRStatus (*pfnPR_NT_CancelIo)(PRFileDesc *fd) = NULL;
if (pfnPR_NT_CancelIo == NULL) {
MEMORY_BASIC_INFORMATION mbi;
VirtualQuery(&PR_Send, &mbi, sizeof(mbi));
pfnPR_NT_CancelIo = (PRStatus (*)(PRFileDesc *fd))GetProcAddress((HINSTANCE)mbi.AllocationBase, "PR_NT_CancelIo");
}
/* If we couldn't find PR_NT_CancelIo(), just use the dummy */
if (pfnPR_NT_CancelIo == NULL)
pfnPR_NT_CancelIo = &_NSFC_Dummy_NT_CancelIo;
/* VB: _NSFC_PR_NT_CancelIo - calls PR_NT_CancelIo when an I/O timed out
* or was interrupted.
*/
if (prerr == PR_IO_TIMEOUT_ERROR || prerr == PR_PENDING_INTERRUPT_ERROR) {
// Need to cancel the i/o
if (pfnPR_NT_CancelIo(fd) != PR_SUCCESS) {
// VB: This should not happen. Assert when this happens
// Get the error codes to make debugging a bit easier
PRErrorCode cancelErr = PR_GetError();
PRInt32 cancelOSErr = PR_GetOSError();
PR_ASSERT(0);
}
}
PR_SetError(prerr, oserr);
#endif
}
示例9: PR_IMPLEMENT
PR_IMPLEMENT(void) PL_FPrintError(PRFileDesc *fd, const char *msg)
{
PRErrorCode error = PR_GetError();
PRInt32 oserror = PR_GetOSError();
const char *name = PR_ErrorToName(error);
if (NULL != msg) PR_fprintf(fd, "%s: ", msg);
if (NULL == name)
PR_fprintf(
fd, " (%d)OUT OF RANGE, oserror = %d\n", error, oserror);
else
PR_fprintf(
fd, "%s(%d), oserror = %d\n",
name, error, oserror);
} /* PL_FPrintError */
示例10: assert
/* Called when the socket is handhaking and has signaled that it
is ready to continue. */
void
SSLSocket::handshakeContinue()
{
assert (_state == State::Handshaking);
if (SSL_ForceHandshake(_fd.get()) != SECSuccess) {
PRErrorCode err = PR_GetError();
if(PR_GetError() == PR_WOULD_BLOCK_ERROR) {
/* Try again later */
} else {
/* Error while handshaking */
close(make_nss_error(err));
}
} else {
if (!is_negotiated_protocol_http2(_fd.get())) {
close(make_mist_error(MIST_ERR_NOT_HTTP2));
} else {
_state = State::Open;
if (_h.cb) {
_h.cb(boost::system::error_code());
_h.cb = nullptr;
}
}
}
}
示例11: Curl_nss_send
/* return number of sent (non-SSL) bytes */
int Curl_nss_send(struct connectdata *conn, /* connection data */
int sockindex, /* socketindex */
const void *mem, /* send this data */
size_t len) /* amount to write */
{
int rc;
rc = PR_Send(conn->ssl[sockindex].handle, mem, (int)len, 0, -1);
if(rc < 0) {
failf(conn->data, "SSL write: error %d", PR_GetError());
return -1;
}
return rc; /* number of bytes */
}
示例12: pluto_init_nss
static void
pluto_init_nss(char *confddir)
{
char buf[100];
snprintf(buf, sizeof(buf), "%s",confddir);
loglog(RC_LOG_SERIOUS,"nss directory plutomain: %s",buf);
SECStatus nss_init_status= NSS_InitReadWrite(buf);
if (nss_init_status != SECSuccess) {
loglog(RC_LOG_SERIOUS, "NSS initialization failed (err %d)\n", PR_GetError());
exit_pluto(10);
} else {
libreswan_log("NSS Initialized");
PK11_SetPasswordFunc(getNSSPassword);
}
}
示例13: sxi_crypto_check_ver
int sxi_crypto_check_ver(struct sxi_logger *l)
{
const char *compile_ver = NSS_VERSION;
if (NSS_NoDB_Init("/") != SECSuccess) {
sxi_log_msg(l, "sxi_crypto_check_ver", SX_LOG_CRIT,
"Failed to initialize NSS: %d", PR_GetError());
return -1;
}
if(!NSS_VersionCheck(compile_ver)) {
sxi_log_msg(l, "crypto_check_ver", SX_LOG_CRIT, "NSS library version mismatch: compiled: %s, runtime: %s", compile_ver, NSS_GetVersion());
return -1;
}
return 0;
}
示例14: CheckThread
void TransportLayerDtls::PacketReceived(TransportLayer* layer,
const unsigned char *data,
size_t len) {
CheckThread();
MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "PacketReceived(" << len << ")");
if (state_ != TS_CONNECTING && state_ != TS_OPEN) {
MOZ_MTLOG(ML_DEBUG,
LAYER_INFO << "Discarding packet in inappropriate state");
return;
}
nspr_io_adapter_->PacketReceived(data, len);
// If we're still connecting, try to handshake
if (state_ == TS_CONNECTING) {
Handshake();
}
// Now try a recv if we're open, since there might be data left
if (state_ == TS_OPEN) {
// nICEr uses a 9216 bytes buffer to allow support for jumbo frames
unsigned char buf[9216];
int32_t rv;
// One packet might contain several DTLS packets
do {
rv = PR_Recv(ssl_fd_, buf, sizeof(buf), 0, PR_INTERVAL_NO_WAIT);
if (rv > 0) {
// We have data
MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Read " << rv << " bytes from NSS");
SignalPacketReceived(this, buf, rv);
} else if (rv == 0) {
TL_SET_STATE(TS_CLOSED);
} else {
int32_t err = PR_GetError();
if (err == PR_WOULD_BLOCK_ERROR) {
// This gets ignored
MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Receive would have blocked");
} else {
MOZ_MTLOG(ML_NOTICE, LAYER_INFO << "NSS Error " << err);
TL_SET_STATE(TS_ERROR);
}
}
} while (rv > 0);
}
}
示例15: nss_Init_Tokens
static SECStatus nss_Init_Tokens(struct connectdata * conn)
{
PK11SlotList *slotList;
PK11SlotListElement *listEntry;
SECStatus ret, status = SECSuccess;
pphrase_arg_t *parg = NULL;
parg = (pphrase_arg_t *) malloc(sizeof(*parg));
parg->retryCount = 0;
parg->data = conn->data;
PK11_SetPasswordFunc(nss_get_password);
slotList =
PK11_GetAllTokens(CKM_INVALID_MECHANISM, PR_FALSE, PR_TRUE, NULL);
for(listEntry = PK11_GetFirstSafe(slotList);
listEntry; listEntry = listEntry->next) {
PK11SlotInfo *slot = listEntry->slot;
if(PK11_NeedLogin(slot) && PK11_NeedUserInit(slot)) {
if(slot == PK11_GetInternalKeySlot()) {
failf(conn->data, "The NSS database has not been initialized.\n");
}
else {
failf(conn->data, "The token %s has not been initialized.",
PK11_GetTokenName(slot));
}
PK11_FreeSlot(slot);
continue;
}
ret = PK11_Authenticate(slot, PR_TRUE, parg);
if(SECSuccess != ret) {
if (PR_GetError() == SEC_ERROR_BAD_PASSWORD)
infof(conn->data, "The password for token '%s' is incorrect\n",
PK11_GetTokenName(slot));
status = SECFailure;
break;
}
parg->retryCount = 0; /* reset counter to 0 for the next token */
PK11_FreeSlot(slot);
}
free(parg);
return status;
}