| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include "mod_quotatab.h" |
| 28 |
|
| 29 |
|
| 30 |
#if PROFTPD_VERSION_NUMBER < 0x0001030001 |
| 31 |
# error "ProFTPD 1.3.0rc1 or later required" |
| 32 |
#endif |
| 33 |
|
| 34 |
module quotatab_radius_module; |
| 35 |
|
| 36 |
static int radiustab_close(quota_table_t *radiustab) { |
| 37 |
|
| 38 |
|
| 39 |
return 0; |
| 40 |
} |
| 41 |
|
| 42 |
static unsigned char radiustab_lookup(quota_table_t *radiustab, void *ptr, |
| 43 |
const char *name, quota_type_t quota_type) { |
| 44 |
char **values = NULL; |
| 45 |
array_header *data = NULL; |
| 46 |
pool *tmp_pool = NULL; |
| 47 |
cmdtable *cmdtab = NULL; |
| 48 |
cmd_rec *cmd = NULL; |
| 49 |
modret_t *res = NULL; |
| 50 |
quota_limit_t *limit = ptr; |
| 51 |
|
| 52 |
if (quota_type != USER_QUOTA) { |
| 53 |
quotatab_log("error: mod_quotatab_radius only supports user quotas"); |
| 54 |
return FALSE; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
cmdtab = pr_stash_get_symbol2(PR_SYM_HOOK, "radius_quota_lookup", NULL, |
| 59 |
NULL, NULL); |
| 60 |
if (cmdtab == NULL) { |
| 61 |
quotatab_log("error: unable to find RADIUS hook symbol " |
| 62 |
"'radius_quota_lookup'"); |
| 63 |
return FALSE; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
tmp_pool = make_sub_pool(radiustab->tab_pool); |
| 68 |
|
| 69 |
|
| 70 |
cmd = pr_cmd_alloc(tmp_pool, 1, name); |
| 71 |
res = pr_module_call(cmdtab->m, cmdtab->handler, cmd); |
| 72 |
|
| 73 |
destroy_pool(tmp_pool); |
| 74 |
|
| 75 |
|
| 76 |
if (!res || MODRET_ISERROR(res)) { |
| 77 |
quotatab_log("error retrieving RADIUS quota attributes"); |
| 78 |
return FALSE; |
| 79 |
} |
| 80 |
|
| 81 |
data = (array_header *) res->data; |
| 82 |
if (data->nelts != 9) { |
| 83 |
quotatab_log("RADIUS server returned wrong number of attributes"); |
| 84 |
return FALSE; |
| 85 |
} |
| 86 |
|
| 87 |
values = (char **) data->elts; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
sstrncpy(limit->name, values[0], sizeof(limit->name)-1); |
| 98 |
limit->quota_type = USER_QUOTA; |
| 99 |
|
| 100 |
if (strcasecmp(values[1], "false") == 0) { |
| 101 |
limit->quota_per_session = FALSE; |
| 102 |
|
| 103 |
} else if (strcasecmp(values[1], "true") == 0) { |
| 104 |
limit->quota_per_session = TRUE; |
| 105 |
} |
| 106 |
|
| 107 |
if (strcasecmp(values[2], "soft") == 0) { |
| 108 |
limit->quota_limit_type = SOFT_LIMIT; |
| 109 |
|
| 110 |
} else if (strcasecmp(values[2], "hard") == 0) { |
| 111 |
limit->quota_limit_type = HARD_LIMIT; |
| 112 |
} |
| 113 |
|
| 114 |
limit->bytes_in_avail = atof(values[3]); |
| 115 |
limit->bytes_out_avail = atof(values[4]); |
| 116 |
limit->bytes_xfer_avail = atof(values[5]); |
| 117 |
limit->files_in_avail = atoi(values[6]); |
| 118 |
limit->files_out_avail = atoi(values[7]); |
| 119 |
limit->files_xfer_avail = atoi(values[8]); |
| 120 |
|
| 121 |
return TRUE; |
| 122 |
} |
| 123 |
|
| 124 |
static unsigned char radiustab_verify(quota_table_t *radiustab) { |
| 125 |
|
| 126 |
|
| 127 |
return TRUE; |
| 128 |
} |
| 129 |
|
| 130 |
static quota_table_t *radiustab_open(pool *parent_pool, |
| 131 |
quota_tabtype_t tab_type, const char *srcinfo) { |
| 132 |
pool *tab_pool = make_sub_pool(parent_pool); |
| 133 |
quota_table_t *tab = NULL; |
| 134 |
|
| 135 |
tab = (quota_table_t *) pcalloc(tab_pool, sizeof(quota_table_t)); |
| 136 |
tab->tab_pool = tab_pool; |
| 137 |
tab->tab_type = tab_type; |
| 138 |
|
| 139 |
|
| 140 |
tab->tab_close = radiustab_close; |
| 141 |
tab->tab_lookup = radiustab_lookup; |
| 142 |
tab->tab_verify = radiustab_verify; |
| 143 |
|
| 144 |
return tab; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
#if defined(PR_SHARED_MODULE) |
| 151 |
static void radiustab_mod_unload_ev(const void *event_data, void *user_data) { |
| 152 |
if (strcmp("mod_quotatab_radius.c", (const char *) event_data) == 0) { |
| 153 |
pr_event_unregister("atab_radius_module, NULL, NULL); |
| 154 |
quotatab_unregister_backend("radius", QUOTATAB_LIMIT_SRC); |
| 155 |
} |
| 156 |
} |
| 157 |
#endif |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
static int radiustab_init(void) { |
| 163 |
quotatab_register_backend("radius", radiustab_open, QUOTATAB_LIMIT_SRC); |
| 164 |
|
| 165 |
#if defined(PR_SHARED_MODULE) |
| 166 |
pr_event_register("atab_radius_module, "core.module-unload", |
| 167 |
radiustab_mod_unload_ev, NULL); |
| 168 |
#endif |
| 169 |
|
| 170 |
return 0; |
| 171 |
} |
| 172 |
|
| 173 |
module quotatab_radius_module = { |
| 174 |
NULL, NULL, |
| 175 |
|
| 176 |
|
| 177 |
0x20, |
| 178 |
|
| 179 |
|
| 180 |
"quotatab_radius", |
| 181 |
|
| 182 |
|
| 183 |
NULL, |
| 184 |
|
| 185 |
|
| 186 |
NULL, |
| 187 |
|
| 188 |
|
| 189 |
NULL, |
| 190 |
|
| 191 |
|
| 192 |
radiustab_init, |
| 193 |
|
| 194 |
|
| 195 |
NULL |
| 196 |
}; |