TorCtlCircuitBuild *torControlCircuitBuild_new(ShadowLogFunc logFunc, gint sockd, gchar **args, TorControl_EventHandlers *handlers) { g_assert(handlers && args); handlers->initialize = _torControlCircuitBuild_initialize; handlers->free = (TorControlFree) _torControlCircuitBuild_free; handlers->circEvent = _torControlCircuitBuild_circEvent; handlers->streamEvent = _torControlCircuitBuild_streamEvent; handlers->statusEvent = _torControlCircuitBuild_statusEvent; handlers->responseEvent = _torControlCircuitBuild_responseEvent; if(!args[0]) { logFunc(G_LOG_LEVEL_WARNING, __FUNCTION__, "Error! Did not specify circuit to build!"); return NULL; } /* create structure with module data to return */ TorCtlCircuitBuild *circuitBuild = g_new0(TorCtlCircuitBuild, 1); circuitBuild->log = logFunc; circuitBuild->sockd = sockd; circuitBuild->circuit = NULL; gchar **nodes = g_strsplit(args[0], ",", 0); for(gint idx = 0; nodes[idx]; idx++) { circuitBuild->circuit = g_list_append(circuitBuild->circuit, strdup(nodes[idx])); } g_strfreev(nodes); circuitBuild->state = TORCTL_CIRCBUILD_STATE_AUTHENTICATE; logFunc(G_LOG_LEVEL_INFO, __FUNCTION__, "Successfully initialized the circuit build Tor control module."); return circuitBuild; }
double EntropyBasedSplitCrit::oldEnt(Distribution * bags) { double returnValue = 0; int j; for (j=0;j<bags->numClasses();j++) returnValue = returnValue+logFunc(bags->perClass(j)); return logFunc(bags->Total())-returnValue; }
/** * Computes entropy after splitting without considering the * class values. */ double EntropyBasedSplitCrit::splitEnt(Distribution * bags) { double returnValue = 0; int i; for (i=0;i<bags->numBags();i++) returnValue = returnValue+logFunc(bags->perBag(i)); return logFunc(bags->Total())-returnValue; }
void baldr::logger::log(const char* str, ...) { va_list ap; va_start(ap, str); logFunc(str, ap); va_end (ap); }
double EntropyBasedSplitCrit::newEnt(Distribution * bags) { double returnValue = 0; int i,j; for (i=0;i<bags->numBags();i++) { for (j=0;j<bags->numClasses();j++) { returnValue = returnValue+logFunc(bags->perClassPerBag(i,j)); } returnValue = returnValue-logFunc(bags->perBag(i)); } return -returnValue; }
char * GLProgram::logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) { GLint logLength = 0, charsWritten = 0; infoFunc(object, GL_INFO_LOG_LENGTH, &logLength); if (logLength < 1) return NULL; char *logBytes = (char *)malloc(logLength); logFunc(object, logLength, &charsWritten, logBytes); return (logBytes); }
static char* cxShaderLogFunc(GLuint object, cxOpenGLInfoFunc infoFunc, cxOpenGLLogFunc logFunc) { GLint logLength = 0, writeBytes = 0; infoFunc(object, GL_INFO_LOG_LENGTH, &logLength); if (logLength < 1){ return NULL; } char *logBytes = (char*)allocator->malloc(logLength + 1); logFunc(object, logLength, &writeBytes, logBytes); logBytes[logLength] = '\0'; return logBytes; }
TorControlLogger* torcontrollogger_new(ShadowLogFunc logFunc, gchar* hostname, in_addr_t ip, in_port_t port, gint sockd, gchar **moduleArgs, TorControl_EventHandlers *handlers) { g_assert(handlers); handlers->initialize = (TorControlInitialize) _torcontrollogger_manageState; handlers->free = (TorControlFree) _torcontrollogger_free; handlers->responseEvent = (TorControlResponseFunc) _torcontrollogger_handleResponseEvent; /* all events get processed by the same function that simply logs tor output directly */ handlers->genericEvent = (TorControlGenericEventFunc) _torcontrollogger_handleEvents; /* make sure they specified events */ if(!moduleArgs[0]) { logFunc(SHADOW_LOG_LEVEL_WARNING, __FUNCTION__, "Error! Did not specify torctl events to log!"); return NULL; } TorControlLogger* tcl = g_new0(TorControlLogger, 1); tcl->log = logFunc; tcl->targetHostname = g_string_new(hostname); tcl->targetIP = ip; tcl->targetPort = port; tcl->targetSockd = sockd; /* store the events a string so we can register it later * g_ascii_strup duplicates and converts the str to uppercase * g_strdelimit replaces ',' with ' ' in place */ tcl->torctlEvents = g_strdelimit(g_ascii_strup(moduleArgs[0], -1), ",", ' '); g_assert(tcl->torctlEvents); tcl->currentState = TCLS_SEND_AUTHENTICATE; return tcl; }
/* LookupGroups() * Return the list of groups to which a user belongs. * * For this plugin this involves finding the provided authorization * ID in the User definition file and returning all fields after * the second. */ SQL_API_RC SQL_API_FN LookupGroups(const char *authID, db2int32 authIDLength, const char *userid, /* ignored */ db2int32 useridLength, /* ignored */ const char *domain, /* ignored */ db2int32 domainLength, /* ignored */ db2int32 domainType, /* ignored */ const char *databaseName, /* ignored */ db2int32 databaseNameLength, /* ignored */ void *token, /* ignored */ db2int32 tokenType, /* ignored */ db2int32 location, /* ignored */ const char *authPluginName, /* ignored */ db2int32 authPluginNameLength, /* ignored */ void **groupList, db2int32 *groupCount, char **errorMessage, db2int32 *errorMessageLength) { int rc = DB2SEC_PLUGIN_OK; int length; int ngroups; char localAuthID[SQL_AUTHID_SZ + 1]; char readBuffer[MAX_LINE_LENGTH]; char *cptr; *errorMessage = NULL; *errorMessageLength = 0; /* NULL terminate the authID */ if (authIDLength > SQL_AUTHID_SZ) { char msg[512]; memcpy(localAuthID, authID, SQL_AUTHID_SZ); localAuthID[SQL_AUTHID_SZ] = '\0'; snprintf(msg, 512, "LookupGroups: authID too long ("FMT_S32" bytes): %s... (truncated)", authIDLength, localAuthID); msg[511]='\0'; /* ensure NULL terminated */ logFunc(DB2SEC_LOG_ERROR, msg, strlen(msg)); *errorMessage = "LookupGroups: authID too long"; rc = DB2SEC_PLUGIN_BADUSER; goto exit; } memcpy(localAuthID, authID, authIDLength); localAuthID[authIDLength] = '\0'; /* The maximum amount of group information that we could * return is less than MAX_LINE_LENGTH bytes. */ *groupList = malloc(MAX_LINE_LENGTH); if (*groupList == NULL) { *errorMessage = "malloc failed for group memory"; rc = DB2SEC_PLUGIN_NOMEM; goto exit; } rc = FindUser(getUserFileName(), localAuthID, /* User we're looking for */ readBuffer, sizeof(readBuffer), NULL, /* Don't care about password */ *groupList, &ngroups, errorMessage); if (rc == -2) { /* Unexpected error. */ rc = DB2SEC_PLUGIN_UNKNOWNERROR; goto exit; } else if (rc == -1) { /* User not found */ rc = DB2SEC_PLUGIN_BADUSER; goto exit; } *groupCount = ngroups; exit: if (*errorMessage != NULL) { *errorMessageLength = strlen(*errorMessage); } return(rc); }
/* DoesAuthIDExist() * Determine if the supplied DB2 Authorization ID is associated with * a valid user. * * Since this plugin derives the authorization ID directly from the * username (possibly with the domain name appended), this function * simply needs to determine if the given Auth ID exists in the User * definition file. */ SQL_API_RC SQL_API_FN DoesAuthIDExist(const char *authID, db2int32 authIDLength, char **errorMessage, db2int32 *errorMessageLength) { int rc; char lineBuf[MAX_LINE_LENGTH]; char localAuthID[SQL_AUTHID_SZ + 1]; *errorMessage = NULL; *errorMessageLength = 0; /* NULL terminate the authID */ if (authIDLength > SQL_AUTHID_SZ) { char msg[512]; memcpy(localAuthID, authID, SQL_AUTHID_SZ); localAuthID[SQL_AUTHID_SZ] = '\0'; snprintf(msg, 512, "DoesAuthIDExist: authID too long ("FMT_S32" bytes): %s... (truncated)", authIDLength, localAuthID); msg[511]='\0'; /* ensure NULL terminated */ logFunc(DB2SEC_LOG_ERROR, msg, strlen(msg)); *errorMessage = "DoesAuthIDExist: authID too long"; rc = DB2SEC_PLUGIN_BADUSER; goto exit; } memcpy(localAuthID, authID, authIDLength); localAuthID[authIDLength] = '\0'; rc = FindUser(getUserFileName(), localAuthID, /* User we're looking for */ lineBuf, sizeof(lineBuf), NULL, /* Don't want the password */ NULL, /* Don't want group info */ NULL, errorMessage); if (rc == -2) { /* Unexpected error. */ rc = DB2SEC_PLUGIN_UNKNOWNERROR; goto exit; } else if (rc == -1) { /* User not found */ rc = DB2SEC_PLUGIN_INVALIDUSERORGROUP; goto exit; } else { /* Found the user */ rc = DB2SEC_PLUGIN_OK; } exit: if (*errorMessage != NULL) { *errorMessageLength = strlen(*errorMessage); } return(rc); }
/* FindUser() * Open the indicated file and find the first line where the first * field matches the provided username. Optionally return the * second field (password) and/or parse the remaining fields * (groups) into a non-NULL terminated, length-prefixed sequence * of strings (see below). * * The caller must supply a read buffer for use when processing * the file. * * Leading and trailing whitesapce is stripped from the password * and all group names. * * Returns: 0 for success, * -1 if the user was not found * -2 on error, *errorMessage will be set to a static C * string describing the error. * * If groups are requested, the supplied group buffer must be at * least as large as the supplied read buffer. The groups are * written into that buffer in the following format: * <one byte length><group string><one byte length><group string>... * and *numGroups is set to indicate how many groups were written * to the group buffer. Note that the group name strings are not * NULL terminated. */ int FindUser(const char *fileName, /* File to read */ const char *userName, /* Who we're looking for */ char *readBuffer, /* Caller-supplied read buffer */ int readBufferLength, char **passwordPtr, /* Output: password */ char *groupBuffer, /* Output: group list */ int *numGroups, /* Output: number of groups */ char **errorMessage) /* Static C string for errors */ { int rc = -1; int foundUser = 0; /* Found the user yet? */ int groupCount = 0; int length; char *linePtr; char *field; char *nextPtr; char *cptr; char *errMsg = NULL; /* Temp local error message */ FILE *fp = NULL; if (userName == NULL) { errMsg = "NULL user name supplied"; rc = -2; goto exit; } if (readBuffer == NULL) { errMsg = "NULL read buffer supplied"; rc = -2; goto exit; } if (passwordPtr != NULL) { *passwordPtr = NULL; } if (numGroups != NULL) { *numGroups = 0; } fp = fopen(fileName,"r"); if (fp == NULL) { errMsg = "Cannot open specified file\n"; rc = -2; goto exit; } while (foundUser == 0) { linePtr = GetNextLine(fp, readBuffer, readBufferLength); if (linePtr == (char*)-1) { /* Line length error */ errMsg = "Encountered an invalid input line in file"; rc = -2; goto exit; } if (linePtr == NULL) { /* We've probably reached the end of file, but make sure. */ if (feof(fp)) { /* End of file: User not found. */ rc = -1; } else { /* Not end of file, must have encountered an error. */ rc = -2; errMsg = "Unknown file error encountered"; } goto exit; } field = NextField(linePtr, &nextPtr); if (field != NULL && strcasecmp(field, userName) == 0) { /* Found the correct user name. Parse the line. */ foundUser = 1; /* Second field is the password */ field = NextField(nextPtr, &nextPtr); /* A blank password field is an error. */ if (field == NULL) { errMsg = "No password for user"; rc = -2; goto exit; } if (passwordPtr != NULL) { *passwordPtr = field; } /* If we were requested to return group information, * parse the rest of the line. */ if (groupBuffer != NULL) { cptr = groupBuffer; field = NextField(nextPtr, &nextPtr); while (field != NULL) { length = strlen(field); if (length > 255) { /* Since the group list is formatted using * one byte lengths, a length of more than 255 * bytes is an error. */ errMsg = "group name too long"; rc = -2; goto exit; } *((unsigned char*)cptr) = (unsigned char)length; cptr++; memcpy(cptr, field, length); cptr += length; groupCount++; field = NextField(nextPtr, &nextPtr); } /* Write a NULL byte after the last group; a * "zero length group" indicates the end of the * group list in case the caller did not supply * "numGroups". */ *cptr = '\0'; if (numGroups != NULL) { *numGroups = groupCount; } } rc = 0; /* Found the user */ } } exit: if (fp != NULL) { fclose(fp); } if (errMsg != NULL) { char msg[256]; snprintf(msg, 256, "security plugin 'combined' encountered an error\n" "User: %s\nFile: %s\nError: %s\n", userName, fileName, errMsg); msg[255]='\0'; /* ensure NULL terminated */ logFunc(DB2SEC_LOG_ERROR, msg, strlen(msg)); if (errorMessage != NULL) { *errorMessage = errMsg; } } return(rc); }
/* DoesGroupExist * Searches the user definition file for the named group. If * any user is a member of the group, DB2SEC_PLUGIN_OK is * returned, otherwise DB2SEC_PLUGIN_INVALIDUSERORGROUP is * returned. */ SQL_API_RC SQL_API_FN DoesGroupExist(const char *groupName, db2int32 groupNameLength, char **errorMessage, db2int32 *errorMessageLength) { int rc = DB2SEC_PLUGIN_OK; char localGroupName[DB2SEC_MAX_AUTHID_LENGTH + 1]; char readBuffer[MAX_LINE_LENGTH]; int foundGroup = 0; char *linePtr; char *field; char *nextPtr; FILE *fp = NULL; *errorMessage = NULL; *errorMessageLength = 0; if (groupName == NULL) { *errorMessage = "NULL group name supplied"; rc = DB2SEC_PLUGIN_UNKNOWNERROR; goto exit; } /* NULL terminate the group name */ if (groupNameLength > DB2SEC_MAX_AUTHID_LENGTH) { char msg[512]; memcpy(localGroupName, groupName, DB2SEC_MAX_AUTHID_LENGTH); localGroupName[DB2SEC_MAX_AUTHID_LENGTH] = '\0'; snprintf(msg, 512, "DoesGroupExist: group name too long ("FMT_S32" bytes): %s... (truncated)", groupNameLength, localGroupName); msg[511]='\0'; /* ensure NULL terminated */ logFunc(DB2SEC_LOG_ERROR, msg, strlen(msg)); *errorMessage = "DoesGroupExist: group name too long"; rc = DB2SEC_PLUGIN_BADUSER; goto exit; } memcpy(localGroupName, groupName, groupNameLength); localGroupName[groupNameLength] = '\0'; fp = fopen(getUserFileName(),"r"); if (fp == NULL) { char msg[256]; snprintf(msg, 256, "DoesGroupExist: can't open file: %s", getUserFileName()); msg[255]='\0'; /* ensure NULL terminated */ logFunc(DB2SEC_LOG_ERROR, msg, strlen(msg)); *errorMessage = "Cannot open specified file\n"; rc = DB2SEC_PLUGIN_UNKNOWNERROR; goto exit; } while (foundGroup == 0) { /* Read the next line from the user definition file */ linePtr = GetNextLine(fp, readBuffer, sizeof(readBuffer)); if (linePtr == (char*)-1) { /* Line length error */ *errorMessage = "Encountered an invalid input line in file"; rc = DB2SEC_PLUGIN_UNKNOWNERROR; goto exit; } if (linePtr == NULL) { /* We've probably reached the end of file, but make sure. */ if (feof(fp)) { /* End of file: Group not found. */ rc = DB2SEC_PLUGIN_INVALIDUSERORGROUP; } else { /* Not end of file, must have encountered an error. */ rc = DB2SEC_PLUGIN_UNKNOWNERROR; *errorMessage = "Unknown file error encountered"; } goto exit; } field = NextField(linePtr, &nextPtr); /* Skip user name */ field = NextField(nextPtr, &nextPtr); /* and password */ /* Examine all of the remaining fields */ field = NextField(nextPtr, &nextPtr); while (field != NULL) { if (strcasecmp(field, localGroupName) == 0) { /* Found it! */ foundGroup = 1; break; } field = NextField(nextPtr, &nextPtr); } } if (foundGroup == 1) { rc = DB2SEC_PLUGIN_OK; } exit: if (fp != NULL) { fclose(fp); } if (*errorMessage != NULL) { *errorMessageLength = strlen(*errorMessage); } return(rc); }
TorCtlCircuitBuild *torControlCircuitBuild_new(ShadowLogFunc logFunc, gint sockd, gchar **moduleArgs, TorControl_EventHandlers *handlers) { g_assert(handlers && moduleArgs); handlers->initialize = _torControlCircuitBuild_initialize; handlers->free = (TorControlFree) _torControlCircuitBuild_free; handlers->circEvent = _torControlCircuitBuild_circEvent; handlers->streamEvent = _torControlCircuitBuild_streamEvent; handlers->statusEvent = _torControlCircuitBuild_statusEvent; handlers->responseEvent = _torControlCircuitBuild_responseEvent; if(!moduleArgs[0]) { logFunc(G_LOG_LEVEL_WARNING, __FUNCTION__, "Error! Did not specify circuit to build!"); return NULL; } /* create structure with module data to return */ TorCtlCircuitBuild *circuitBuild = g_new0(TorCtlCircuitBuild, 1); circuitBuild->log = logFunc; circuitBuild->sockd = sockd; circuitBuild->circuits = NULL; circuitBuild->circuitsToBuild = g_queue_new(); for(gint idx = 0; moduleArgs[idx]; idx++) { logFunc(G_LOG_LEVEL_MESSAGE, __FUNCTION__, "%s", moduleArgs[idx]); TorCtlCircuitBuild_Circuit *circuit = g_new0(TorCtlCircuitBuild_Circuit, 1); circuit->startTime = 0; circuit->endTime = -1; circuit->relays = NULL; circuit->circID = -1; /* time:hop1,hop2,hop3 OR hop1,hop2,hop3 */ gchar **parts = g_strsplit(moduleArgs[idx], ":", 2); if(!parts[1]) { circuit->relays = g_strdup(parts[0]); } else { circuit->startTime = g_ascii_strtoll(parts[0], NULL, 10); circuit->relays = g_strdup(parts[1]); } g_strfreev(parts); circuitBuild->circuits = g_list_append(circuitBuild->circuits, circuit); g_queue_push_tail(circuitBuild->circuitsToBuild, circuit); } for(GList *iter = g_list_first(circuitBuild->circuits); iter && iter->next; iter = g_list_next(iter)) { TorCtlCircuitBuild_Circuit *circ1 = iter->data; TorCtlCircuitBuild_Circuit *circ2 = iter->next->data; circ1->endTime = circ2->startTime; } // gchar **nodes = g_strsplit(moduleArgs[0], ",", 0); // for(gint idx = 0; nodes[idx]; idx++) { // circuitBuild->circuit = g_list_append(circuitBuild->circuit, strdup(nodes[idx])); // } // g_strfreev(nodes); circuitBuild->state = TORCTL_CIRCBUILD_STATE_AUTHENTICATE; logFunc(G_LOG_LEVEL_INFO, __FUNCTION__, "Successfully initialized the circuit build Tor control module."); return circuitBuild; }