END_TEST START_TEST (expr_eval_group_and_test) { char *names1[3] = { "foo", "bar", NULL }, *names2[2] = { "test", NULL }, *names3[2] = { "!baz", NULL }; int res; res = pr_expr_eval_group_and(NULL); fail_unless(res == -1, "Failed to handle null argument"); fail_unless(errno == EINVAL, "Failed to set errno to EINVAL"); session.group = NULL; session.groups = NULL; res = pr_expr_eval_group_and(names1); fail_unless(res == FALSE, "Expected FALSE, got TRUE"); session.group = "test"; res = pr_expr_eval_group_and(names1); fail_unless(res == FALSE, "Expected FALSE, got TRUE"); res = pr_expr_eval_group_and(names2); fail_unless(res == TRUE, "Expected TRUE, got FALSE"); res = pr_expr_eval_group_and(names3); fail_unless(res == TRUE, "Expected TRUE, got FALSE"); session.group = NULL; session.groups = make_array(p, 2, sizeof(char *)); *((char **) push_array(session.groups)) = "test"; *((char **) push_array(session.groups)) = NULL; *((char **) push_array(session.groups)) = "spank"; res = pr_expr_eval_group_and(names1); fail_unless(res == FALSE, "Expected FALSE, got TRUE"); res = pr_expr_eval_group_and(names2); fail_unless(res == TRUE, "Expected TRUE, got FALSE"); res = pr_expr_eval_group_and(names3); fail_unless(res == TRUE, "Expected TRUE, got FALSE"); }
void pr_throttle_init(cmd_rec *cmd) { config_rec *c = NULL; char *xfer_cmd = NULL; unsigned char have_user_rate = FALSE, have_group_rate = FALSE, have_class_rate = FALSE; unsigned int precedence = 0; /* Make sure the variables are (re)initialized */ xfer_rate_kbps = xfer_rate_bps = 0.0; xfer_rate_freebytes = 0; xfer_rate_scoreboard_updates = 0; have_xfer_rate = FALSE; c = find_config(CURRENT_CONF, CONF_PARAM, "TransferRate", FALSE); /* Note: need to cycle through all the matching config_recs, and using * the information from the current config_rec only if it matches * the target *and* has a higher precedence than any of the previously * found config_recs. */ while (c) { char **cmdlist = (char **) c->argv[0]; int matched_cmd = FALSE; pr_signals_handle(); /* Does this TransferRate apply to the current command? Note: this * could be made more efficient by using bitmasks rather than string * comparisons. */ for (xfer_cmd = *cmdlist; xfer_cmd; xfer_cmd = *(cmdlist++)) { if (strcasecmp(xfer_cmd, cmd->argv[0]) == 0) { matched_cmd = TRUE; break; } } /* No -- continue on to the next TransferRate. */ if (!matched_cmd) { c = find_config_next(c, c->next, CONF_PARAM, "TransferRate", FALSE); continue; } if (c->argc > 4) { if (strncmp(c->argv[4], "user", 5) == 0) { if (pr_expr_eval_user_or((char **) &c->argv[5]) == TRUE && *((unsigned int *) c->argv[3]) > precedence) { /* Set the precedence. */ precedence = *((unsigned int *) c->argv[3]); xfer_rate_kbps = *((long double *) c->argv[1]); xfer_rate_freebytes = *((off_t *) c->argv[2]); have_xfer_rate = TRUE; have_user_rate = TRUE; have_group_rate = have_class_rate = FALSE; } } else if (strncmp(c->argv[4], "group", 6) == 0) { if (pr_expr_eval_group_and((char **) &c->argv[5]) == TRUE && *((unsigned int *) c->argv[3]) > precedence) { /* Set the precedence. */ precedence = *((unsigned int *) c->argv[3]); xfer_rate_kbps = *((long double *) c->argv[1]); xfer_rate_freebytes = *((off_t *) c->argv[2]); have_xfer_rate = TRUE; have_group_rate = TRUE; have_user_rate = have_class_rate = FALSE; } } else if (strncmp(c->argv[4], "class", 6) == 0) { if (pr_expr_eval_class_or((char **) &c->argv[5]) == TRUE && *((unsigned int *) c->argv[3]) > precedence) { /* Set the precedence. */ precedence = *((unsigned int *) c->argv[3]); xfer_rate_kbps = *((long double *) c->argv[1]); xfer_rate_freebytes = *((off_t *) c->argv[2]); have_xfer_rate = TRUE; have_class_rate = TRUE; have_user_rate = have_group_rate = FALSE; } } } else { if (*((unsigned int *) c->argv[3]) > precedence) { /* Set the precedence. */ precedence = *((unsigned int *) c->argv[3]); xfer_rate_kbps = *((long double *) c->argv[1]); xfer_rate_freebytes = *((off_t *) c->argv[2]); have_xfer_rate = TRUE; have_user_rate = have_group_rate = have_class_rate = FALSE; } } c = find_config_next(c, c->next, CONF_PARAM, "TransferRate", FALSE); } /* Print out a helpful debugging message. */ if (have_xfer_rate) { pr_log_debug(DEBUG3, "TransferRate (%.3Lf KB/s, %" PR_LU " bytes free) in effect%s", xfer_rate_kbps, (pr_off_t) xfer_rate_freebytes, have_user_rate ? " for current user" : have_group_rate ? " for current group" : have_class_rate ? " for current class" : ""); /* Convert the configured Kbps to bytes per usec, for use later. * The 1024.0 factor converts for Kbytes to bytes, and the * 1000000.0 factor converts from secs to usecs. */ xfer_rate_bps = xfer_rate_kbps * 1024.0; } }