本文整理汇总了C++中radius_axlat函数的典型用法代码示例。如果您正苦于以下问题:C++ radius_axlat函数的具体用法?C++ radius_axlat怎么用?C++ radius_axlat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了radius_axlat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: XS
/*
* This is a wraper for radius_axlat
* Now users are able to get data that is accessible only via xlat
* e.g. %{client:...}
* Call syntax is radiusd::xlat(string), string will be handled the
* same way it is described in EXPANSIONS section of man unlang
*/
static XS(XS_radiusd_xlat)
{
dXSARGS;
char *in_str;
char *expanded;
ssize_t slen;
SV *rad_requestp_sv;
REQUEST *request;
if (items != 1) croak("Usage: radiusd::xlat(string)");
rad_requestp_sv = get_sv("RAD___REQUESTP", 0);
if (rad_requestp_sv == NULL) croak("Can not evalue xlat, RAD___REQUESTP is not set!");
request = INT2PTR(REQUEST *, SvIV(rad_requestp_sv));
in_str = (char *) SvPV(ST(0), PL_na);
expanded = NULL;
slen = radius_axlat(&expanded, request, in_str, NULL, NULL);
if (slen < 0) {
REDEBUG("Error parsing xlat '%s'", in_str);
XSRETURN_UNDEF;
}
XST_mPV(0, expanded);
talloc_free(expanded);
XSRETURN(1);
}
示例2: sql_set_user
/*
* Set the SQL user name.
*
* We don't call the escape function here. The resulting string
* will be escaped later in the queries xlat so we don't need to
* escape it twice. (it will make things wrong if we have an
* escape candidate character in the username)
*/
int sql_set_user(rlm_sql_t *inst, REQUEST *request, char const *username)
{
char *expanded = NULL;
VALUE_PAIR *vp = NULL;
char const *sqluser;
ssize_t len;
if (username != NULL) {
sqluser = username;
} else if (inst->config->query_user[0] != '\0') {
sqluser = inst->config->query_user;
} else {
return 0;
}
len = radius_axlat(&expanded, request, sqluser, NULL, NULL);
if (len < 0) {
return -1;
}
vp = pairalloc(request->packet, inst->sql_user);
if (!vp) {
talloc_free(expanded);
return -1;
}
pairstrsteal(vp, expanded);
RDEBUG2("SQL-User-Name set to '%s'", vp->vp_strvalue);
vp->op = T_OP_SET;
pairmove(request, &request->packet->vps, &vp); /* needs to be pair move else op is not respected */
return 0;
}
示例3: sqlippool_command
/** Perform a single sqlippool query
*
* Mostly wrapper around sql_query which does some special sqlippool sequence substitutions and expands
* the format string.
*
* @param fmt sql query to expand.
* @param handle sql connection handle.
* @param data Instance of rlm_sqlippool.
* @param request Current request.
* @param param ip address string.
* @param param_len ip address string len.
* @return 0 on success or < 0 on error.
*/
static int sqlippool_command(char const *fmt, rlm_sql_handle_t **handle,
rlm_sqlippool_t *data, REQUEST *request,
char *param, int param_len)
{
char query[MAX_QUERY_LEN];
char *expanded = NULL;
int ret;
/*
* If we don't have a command, do nothing.
*/
if (!fmt || !*fmt) return 0;
/*
* @todo this needs to die (should just be done in xlat expansion)
*/
sqlippool_expand(query, sizeof(query), fmt, data, param, param_len);
if (radius_axlat(&expanded, request, query, data->sql_inst->sql_escape_func, data->sql_inst) < 0) return -1;
ret = data->sql_inst->sql_query(data->sql_inst, request, handle, expanded);
if (ret < 0){
talloc_free(expanded);
return -1;
}
talloc_free(expanded);
if (*handle) (data->sql_inst->module->sql_finish_query)(*handle, data->sql_inst->config);
return 0;
}
示例4: CC_HINT
/*
* Query the database expecting a single result row
*/
static int CC_HINT(nonnull (1, 3, 4, 5)) sqlippool_query1(char *out, int outlen, char const *fmt,
rlm_sql_handle_t *handle, rlm_sqlippool_t *data,
REQUEST *request, char *param, int param_len)
{
char query[MAX_QUERY_LEN];
char *expanded = NULL;
int rlen, retval;
/*
* @todo this needs to die (should just be done in xlat expansion)
*/
sqlippool_expand(query, sizeof(query), fmt, data, param, param_len);
*out = '\0';
/*
* Do an xlat on the provided string
*/
if (radius_axlat(&expanded, request, query, data->sql_inst->sql_escape_func, data->sql_inst) < 0) {
return 0;
}
retval = data->sql_inst->sql_select_query(data->sql_inst, request, &handle, expanded);
talloc_free(expanded);
if (retval != 0){
REDEBUG("database query error on '%s'", query);
return 0;
}
if (data->sql_inst->sql_fetch_row(data->sql_inst, request, &handle) < 0) {
REDEBUG("Failed fetching query result");
goto finish;
}
if (!handle->row) {
REDEBUG("SQL query did not return any results");
goto finish;
}
if (!handle->row[0]) {
REDEBUG("The first column of the result was NULL");
goto finish;
}
rlen = strlen(handle->row[0]);
if (rlen >= outlen) {
RDEBUG("insufficient string space");
goto finish;
}
strcpy(out, handle->row[0]);
retval = rlen;
finish:
(data->sql_inst->module->sql_finish_select_query)(handle, data->sql_inst->config);
return retval;
}
示例5: rad_assert
static char *radius_expand_tmpl(REQUEST *request, value_pair_tmpl_t const *vpt)
{
char *buffer = NULL;
VALUE_PAIR *vp;
rad_assert(vpt->type != VPT_TYPE_LIST);
switch (vpt->type) {
case VPT_TYPE_LITERAL:
EVAL_DEBUG("TMPL LITERAL");
buffer = talloc_strdup(request, vpt->name);
break;
case VPT_TYPE_EXEC:
EVAL_DEBUG("TMPL EXEC");
buffer = talloc_array(request, char, 1024);
if (radius_exec_program(vpt->name, request, 1,
buffer, 1024, NULL, NULL, 0) != 0) {
talloc_free(buffer);
return NULL;
}
break;
case VPT_TYPE_REGEX:
EVAL_DEBUG("TMPL REGEX");
if (strchr(vpt->name, '%') == NULL) {
buffer = talloc_strdup(request, vpt->name);
break;
}
/* FALL-THROUGH */
case VPT_TYPE_XLAT:
EVAL_DEBUG("TMPL XLAT");
buffer = NULL;
if (radius_axlat(&buffer, request, vpt->name, NULL, NULL) == 0) {
return NULL;
}
break;
case VPT_TYPE_ATTR:
EVAL_DEBUG("TMPL ATTR");
vp = radius_vpt_get_vp(request, vpt);
if (!vp) return NULL;
buffer = vp_aprint(request, vp);
break;
case VPT_TYPE_DATA:
rad_assert(0 == 1);
/* FALL-THROUGH */
default:
buffer = NULL;
break;
}
EVAL_DEBUG("Expand tmpl --> %s", buffer);
return buffer;
}
示例6: sqlippool_query1
/*
* Query the database expecting a single result row
*/
static int sqlippool_query1(char *out, int outlen, char const *fmt,
rlm_sql_handle_t *handle, rlm_sqlippool_t *data,
REQUEST *request, char *param, int param_len)
{
char query[MAX_QUERY_LEN];
char *expanded = NULL;
int rlen, retval;
/*
* @todo this needs to die (should just be done in xlat expansion)
*/
sqlippool_expand(query, sizeof(query), fmt, data, param, param_len);
rad_assert(request != NULL);
*out = '\0';
/*
* Do an xlat on the provided string
*/
if (radius_axlat(&expanded, request, query, data->sql_inst->sql_escape_func, data->sql_inst) < 0) {
return 0;
}
retval = data->sql_inst->sql_select_query(&handle, data->sql_inst, expanded);
talloc_free(expanded);
if (retval != 0) {
REDEBUG("database query error on '%s'", query);
return 0;
}
if (!data->sql_inst->sql_fetch_row(&handle, data->sql_inst)) {
if (handle->row) {
if (handle->row[0]) {
if ((rlen = strlen(handle->row[0])) < outlen) {
strcpy(out, handle->row[0]);
retval = rlen;
} else {
RDEBUG("insufficient string space");
}
} else {
RDEBUG("row[0] returned NULL");
}
} else {
RDEBUG("SQL query did not return any results");
}
} else {
RDEBUG("SQL query did not succeed");
}
(data->sql_inst->module->sql_finish_select_query)(handle, data->sql_inst->config);
return retval;
}
示例7: sqlcounter_cmp
/*
* See if the counter matches.
*/
static int sqlcounter_cmp(void *instance, REQUEST *request, UNUSED VALUE_PAIR *req , VALUE_PAIR *check,
UNUSED VALUE_PAIR *check_pairs, UNUSED VALUE_PAIR **reply_pairs)
{
rlm_sqlcounter_t *inst = instance;
uint64_t counter;
char *p;
char query[MAX_QUERY_LEN];
char *expanded = NULL;
size_t len;
len = snprintf(query, sizeof(query), "%%{%s:%s}", inst->sqlmod_inst, query);
if (len >= sizeof(query) - 1) {
REDEBUG("Insufficient query buffer space");
return RLM_MODULE_FAIL;
}
p = query + len;
/* first, expand %k, %b and %e in query */
len = sqlcounter_expand(p, p - query, inst->query, inst);
if (len <= 0) {
REDEBUG("Insufficient query buffer space");
return RLM_MODULE_FAIL;
}
p += len;
if ((p - query) < 2) {
REDEBUG("Insufficient query buffer space");
return RLM_MODULE_FAIL;
}
p[0] = '}';
p[1] = '\0';
/* Finally, xlat resulting SQL query */
if (radius_axlat(&expanded, request, query, NULL, NULL) < 0) {
return RLM_MODULE_FAIL;
}
counter = strtoull(expanded, NULL, 10);
talloc_free(expanded);
if (counter < check->vp_integer64) {
return -1;
}
if (counter > check->vp_integer64) {
return 1;
}
return 0;
}
示例8: sql_get_grouplist
static int sql_get_grouplist(rlm_sql_t *inst, rlm_sql_handle_t **handle, REQUEST *request,
rlm_sql_grouplist_t **phead)
{
char *expanded = NULL;
int num_groups = 0;
rlm_sql_row_t row;
rlm_sql_grouplist_t *entry;
int ret;
/* NOTE: sql_set_user should have been run before calling this function */
entry = *phead = NULL;
if (!inst->config->groupmemb_query || (inst->config->groupmemb_query[0] == 0)) {
return 0;
}
if (radius_axlat(&expanded, request, inst->config->groupmemb_query, sql_escape_func, inst) < 0) {
return -1;
}
ret = rlm_sql_select_query(handle, inst, expanded);
talloc_free(expanded);
if (ret != RLM_SQL_OK) {
return -1;
}
while (rlm_sql_fetch_row(handle, inst) == 0) {
row = (*handle)->row;
if (!row)
break;
if (!row[0]){
RDEBUG("row[0] returned NULL");
(inst->module->sql_finish_select_query)(*handle, inst->config);
talloc_free(entry);
return -1;
}
if (!*phead) {
*phead = talloc_zero(*handle, rlm_sql_grouplist_t);
entry = *phead;
} else {
entry->next = talloc_zero(*phead, rlm_sql_grouplist_t);
entry = entry->next;
}
entry->next = NULL;
entry->name = talloc_typed_strdup(entry, row[0]);
num_groups++;
}
(inst->module->sql_finish_select_query)(*handle, inst->config);
return num_groups;
}
示例9: do_logging
/*
* If we have something to log, then we log it.
* Otherwise we return the retcode as soon as possible
*/
static int do_logging(REQUEST *request, char const *str, int rcode)
{
char *expanded = NULL;
if (!str || !*str) return rcode;
if (radius_axlat(&expanded, request, str, NULL, NULL) < 0) {
return rcode;
}
pair_make_config("Module-Success-Message", expanded, T_OP_SET);
talloc_free(expanded);
return rcode;
}
示例10: rlm_sql_query_log
/*
* Log the query to a file.
*/
void rlm_sql_query_log(rlm_sql_t *inst, REQUEST *request,
sql_acct_section_t *section, char const *query)
{
int fd;
char const *filename = NULL;
char *expanded = NULL;
size_t len;
bool failed = false; /* Write the log message outside of the critical region */
if (section) {
filename = section->logfile;
} else {
filename = inst->config->logfile;
}
if (!filename) {
return;
}
if (radius_axlat(&expanded, request, filename, NULL, NULL) < 0) {
return;
}
fd = exfile_open(inst->ef, filename, 0640, true);
if (fd < 0) {
ERROR("rlm_sql (%s): Couldn't open logfile '%s': %s", inst->config->xlat_name,
expanded, fr_syserror(errno));
talloc_free(expanded);
return;
}
len = strlen(query);
if ((write(fd, query, len) < 0) || (write(fd, ";\n", 2) < 0)) {
failed = true;
}
if (failed) {
ERROR("rlm_sql (%s): Failed writing to logfile '%s': %s", inst->config->xlat_name, expanded,
fr_syserror(errno));
}
talloc_free(expanded);
exfile_close(inst->ef, fd);
}
示例11: sqlcounter_cmp
/*
* See if the counter matches.
*/
static int sqlcounter_cmp(void *instance, REQUEST *request, UNUSED VALUE_PAIR *req , VALUE_PAIR *check,
UNUSED VALUE_PAIR *check_pairs, UNUSED VALUE_PAIR **reply_pairs)
{
rlm_sqlcounter_t *inst = instance;
uint64_t counter;
char query[MAX_QUERY_LEN], subst[MAX_QUERY_LEN];
char *expanded = NULL;
size_t len;
/* First, expand %k, %b and %e in query */
if (sqlcounter_expand(subst, sizeof(subst), inst->query, inst) <= 0) {
REDEBUG("Insufficient query buffer space");
return RLM_MODULE_FAIL;
}
/* Then combine that with the name of the module were using to do the query */
len = snprintf(query, sizeof(query), "%%{%s:%s}", inst->sqlmod_inst, subst);
if (len >= sizeof(query) - 1) {
REDEBUG("Insufficient query buffer space");
return RLM_MODULE_FAIL;
}
/* Finally, xlat resulting SQL query */
if (radius_axlat(&expanded, request, query, NULL, NULL) < 0) {
return RLM_MODULE_FAIL;
}
if (sscanf(expanded, "%" PRIu64, &counter) != 1) {
RDEBUG2("No integer found in string \"%s\"", expanded);
}
talloc_free(expanded);
if (counter < check->vp_integer64) {
return -1;
}
if (counter > check->vp_integer64) {
return 1;
}
return 0;
}
示例12: rlm_sql_query_log
/*
* Log the query to a file.
*/
void rlm_sql_query_log(rlm_sql_t *inst, REQUEST *request,
sql_acct_section_t *section, char const *query)
{
int fd;
char const *filename = NULL;
char *expanded = NULL;
if (section) {
filename = section->logfile;
} else {
filename = inst->config->logfile;
}
if (!filename) {
return;
}
if (radius_axlat(&expanded, request, filename, NULL, NULL) < 0) {
return;
}
fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0666);
if (fd < 0) {
ERROR("rlm_sql (%s): Couldn't open logfile '%s': %s", inst->config->xlat_name,
expanded, fr_syserror(errno));
talloc_free(expanded);
return;
}
if ((rad_lockfd(fd, MAX_QUERY_LEN) < 0) || (write(fd, query, strlen(query)) < 0) || (write(fd, ";\n", 2) < 0)) {
ERROR("rlm_sql (%s): Failed writing to logfile '%s': %s", inst->config->xlat_name, expanded,
fr_syserror(errno));
}
talloc_free(expanded);
close(fd); /* and release the lock */
}
示例13: radius_expand_tmpl
/** Expand the RHS of a template
*
* @note Length of expanded string can be found with talloc_array_length(*out) - 1
*
* @param out where to write a pointer to the newly allocated buffer.
* @param request Current request.
* @param vpt to evaluate.
* @return -1 on error, else 0.
*/
static int radius_expand_tmpl(char **out, REQUEST *request, value_pair_tmpl_t const *vpt)
{
VALUE_PAIR *vp;
*out = NULL;
rad_assert(vpt->type != VPT_TYPE_LIST);
switch (vpt->type) {
case VPT_TYPE_LITERAL:
EVAL_DEBUG("TMPL LITERAL");
*out = talloc_strdup(request, vpt->name);
break;
case VPT_TYPE_EXEC:
EVAL_DEBUG("TMPL EXEC");
*out = talloc_array(request, char, 1024);
if (radius_exec_program(request, vpt->name, true, false, *out, 1024, EXEC_TIMEOUT, NULL, NULL) != 0) {
TALLOC_FREE(*out);
return -1;
}
break;
case VPT_TYPE_REGEX:
EVAL_DEBUG("TMPL REGEX");
if (strchr(vpt->name, '%') == NULL) {
*out = talloc_strdup(request, vpt->name);
break;
}
/* FALL-THROUGH */
case VPT_TYPE_XLAT:
EVAL_DEBUG("TMPL XLAT");
/* Error in expansion, this is distinct from zero length expansion */
if (radius_axlat(out, request, vpt->name, NULL, NULL) < 0) {
rad_assert(!*out);
return -1;
}
break;
case VPT_TYPE_ATTR:
EVAL_DEBUG("TMPL ATTR");
if (radius_vpt_get_vp(&vp, request, vpt) < 0) {
return -2;
}
*out = vp_aprint(request, vp);
if (!*out) {
return -1;
}
break;
case VPT_TYPE_DATA:
rad_assert(0 == 1);
/* FALL-THROUGH */
default:
break;
}
EVAL_DEBUG("Expand tmpl --> %s", *out);
return 0;
}
示例14: mod_checksimul
/*
* See if a user is already logged in. Sets request->simul_count to the
* current session count for this user and sets request->simul_mpp to 2
* if it looks like a multilink attempt based on the requested IP
* address, otherwise leaves request->simul_mpp alone.
*
* Check twice. If on the first pass the user exceeds his
* max. number of logins, do a second pass and validate all
* logins by querying the terminal server (using eg. SNMP).
*/
static rlm_rcode_t mod_checksimul(void *instance, REQUEST *request)
{
rlm_rcode_t rcode = RLM_MODULE_OK;
struct radutmp u;
int fd = -1;
VALUE_PAIR *vp;
uint32_t ipno = 0;
char const *call_num = NULL;
rlm_radutmp_t *inst = instance;
char *expanded = NULL;
ssize_t len;
/*
* Get the filename, via xlat.
*/
if (radius_axlat(&expanded, request, inst->filename, NULL, NULL) < 0) {
return RLM_MODULE_FAIL;
}
fd = open(expanded, O_RDWR);
if (fd < 0) {
/*
* If the file doesn't exist, then no users
* are logged in.
*/
if (errno == ENOENT) {
request->simul_count=0;
return RLM_MODULE_OK;
}
/*
* Error accessing the file.
*/
ERROR("rlm_radumtp: Error accessing file %s: %s", expanded, strerror(errno));
rcode = RLM_MODULE_FAIL;
goto finish;
}
TALLOC_FREE(expanded);
len = radius_axlat(&expanded, request, inst->username, NULL, NULL);
if (len < 0) {
rcode = RLM_MODULE_FAIL;
goto finish;
}
if (!len) {
rcode = RLM_MODULE_NOOP;
goto finish;
}
/*
* WTF? This is probably wrong... we probably want to
* be able to check users across multiple session accounting
* methods.
*/
request->simul_count = 0;
/*
* Loop over utmp, counting how many people MAY be logged in.
*/
while (read(fd, &u, sizeof(u)) == sizeof(u)) {
if (((strncmp(expanded, u.login, RUT_NAMESIZE) == 0) ||
(!inst->case_sensitive && (strncasecmp(expanded, u.login, RUT_NAMESIZE) == 0))) &&
(u.type == P_LOGIN)) {
++request->simul_count;
}
}
/*
* The number of users logged in is OK,
* OR, we've been told to not check the NAS.
*/
if ((request->simul_count < request->simul_max) || !inst->check_nas) {
rcode = RLM_MODULE_OK;
goto finish;
}
lseek(fd, (off_t)0, SEEK_SET);
/*
* Setup some stuff, like for MPP detection.
*/
if ((vp = pairfind(request->packet->vps, PW_FRAMED_IP_ADDRESS, 0, TAG_ANY)) != NULL) {
ipno = vp->vp_ipaddr;
//.........这里部分代码省略.........
示例15: mod_accounting
//.........这里部分代码省略.........
if (ut.nas_address == htonl(INADDR_NONE)) {
ut.nas_address = request->packet->src_ipaddr.ipaddr.ip4addr.s_addr;
nas = request->client->shortname;
} else if (request->packet->src_ipaddr.ipaddr.ip4addr.s_addr == ut.nas_address) { /* might be a client, might not be. */
nas = request->client->shortname;
} else {
/*
* The NAS isn't a client, it's behind
* a proxy server. In that case, just
* get the IP address.
*/
nas = ip_ntoa(ip_name, ut.nas_address);
}
/*
* Set the protocol field.
*/
if (protocol == PW_PPP) {
ut.proto = 'P';
} else if (protocol == PW_SLIP) {
ut.proto = 'S';
} else {
ut.proto = 'T';
}
ut.time = t - ut.delay;
/*
* Get the utmp filename, via xlat.
*/
filename = NULL;
if (radius_axlat(&filename, request, inst->filename, NULL, NULL) < 0) {
return RLM_MODULE_FAIL;
}
/*
* See if this was a reboot.
*
* Hmm... we may not want to zap all of the users when the NAS comes up, because of issues with receiving
* UDP packets out of order.
*/
if (status == PW_STATUS_ACCOUNTING_ON && (ut.nas_address != htonl(INADDR_NONE))) {
RIDEBUG("NAS %s restarted (Accounting-On packet seen)", nas);
rcode = radutmp_zap(request, filename, ut.nas_address, ut.time);
goto finish;
}
if (status == PW_STATUS_ACCOUNTING_OFF && (ut.nas_address != htonl(INADDR_NONE))) {
RIDEBUG("NAS %s rebooted (Accounting-Off packet seen)", nas);
rcode = radutmp_zap(request, filename, ut.nas_address, ut.time);
goto finish;
}
/*
* If we don't know this type of entry pretend we succeeded.
*/
if (status != PW_STATUS_START && status != PW_STATUS_STOP && status != PW_STATUS_ALIVE) {
REDEBUG("NAS %s port %u unknown packet type %d)", nas, ut.nas_port, status);
rcode = RLM_MODULE_NOOP;
goto finish;
}