| 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 |
|
| 28 |
#include "mod_quotatab.h" |
| 29 |
|
| 30 |
module quotatab_ldap_module; |
| 31 |
|
| 32 |
static int ldaptab_close(quota_table_t *ldaptab) { |
| 33 |
|
| 34 |
|
| 35 |
return 0; |
| 36 |
} |
| 37 |
|
| 38 |
static unsigned char ldaptab_lookup(quota_table_t *ldaptab, void *ptr, |
| 39 |
const char *name, quota_type_t quota_type) { |
| 40 |
char **values = NULL; |
| 41 |
array_header *ldap_data = NULL; |
| 42 |
pool *tmp_pool = NULL; |
| 43 |
cmdtable *ldap_cmdtab = NULL; |
| 44 |
cmd_rec *ldap_cmd = NULL; |
| 45 |
modret_t *ldap_res = NULL; |
| 46 |
quota_limit_t *limit = ptr; |
| 47 |
|
| 48 |
if (quota_type != USER_QUOTA) { |
| 49 |
quotatab_log("error: mod_quotatab_ldap only supports user quotas"); |
| 50 |
return FALSE; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
ldap_cmdtab = pr_stash_get_symbol2(PR_SYM_HOOK, "ldap_quota_lookup", NULL, |
| 55 |
NULL, NULL); |
| 56 |
if (ldap_cmdtab == NULL) { |
| 57 |
quotatab_log("error: unable to find LDAP hook symbol 'ldap_quota_lookup'"); |
| 58 |
return FALSE; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
tmp_pool = make_sub_pool(ldaptab->tab_pool); |
| 63 |
|
| 64 |
|
| 65 |
ldap_cmd = pr_cmd_alloc(tmp_pool, 1, name); |
| 66 |
ldap_res = pr_module_call(ldap_cmdtab->m, ldap_cmdtab->handler, ldap_cmd); |
| 67 |
|
| 68 |
|
| 69 |
if (!ldap_res || MODRET_ISERROR(ldap_res)) { |
| 70 |
quotatab_log("error performing LDAP search"); |
| 71 |
|
| 72 |
destroy_pool(tmp_pool); |
| 73 |
return FALSE; |
| 74 |
} |
| 75 |
|
| 76 |
ldap_data = (array_header *) ldap_res->data; |
| 77 |
if (ldap_data->nelts != 9) { |
| 78 |
quotatab_log("LDAP search returned wrong number of elements"); |
| 79 |
|
| 80 |
destroy_pool(tmp_pool); |
| 81 |
return FALSE; |
| 82 |
} |
| 83 |
|
| 84 |
values = (char **) ldap_data->elts; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
sstrncpy(limit->name, values[0], sizeof(limit->name)-1); |
| 95 |
limit->quota_type = USER_QUOTA; |
| 96 |
|
| 97 |
if (!strcasecmp(values[1], "false")) |
| 98 |
limit->quota_per_session = FALSE; |
| 99 |
else if (!strcasecmp(values[1], "true")) |
| 100 |
limit->quota_per_session = TRUE; |
| 101 |
|
| 102 |
if (!strcasecmp(values[2], "soft")) |
| 103 |
limit->quota_limit_type = SOFT_LIMIT; |
| 104 |
else if (!strcasecmp(values[2], "hard")) |
| 105 |
limit->quota_limit_type = HARD_LIMIT; |
| 106 |
|
| 107 |
limit->bytes_in_avail = atof(values[3]); |
| 108 |
limit->bytes_out_avail = atof(values[4]); |
| 109 |
limit->bytes_xfer_avail = atof(values[5]); |
| 110 |
limit->files_in_avail = atoi(values[6]); |
| 111 |
limit->files_out_avail = atoi(values[7]); |
| 112 |
limit->files_xfer_avail = atoi(values[8]); |
| 113 |
|
| 114 |
destroy_pool(tmp_pool); |
| 115 |
return TRUE; |
| 116 |
} |
| 117 |
|
| 118 |
static unsigned char ldaptab_verify(quota_table_t *ldaptab) { |
| 119 |
|
| 120 |
|
| 121 |
return TRUE; |
| 122 |
} |
| 123 |
|
| 124 |
static quota_table_t *ldaptab_open(pool *parent_pool, quota_tabtype_t tab_type, |
| 125 |
const char *srcinfo) { |
| 126 |
|
| 127 |
pool *tab_pool = make_sub_pool(parent_pool); |
| 128 |
quota_table_t *tab = NULL; |
| 129 |
|
| 130 |
tab = (quota_table_t *) pcalloc(tab_pool, sizeof(quota_table_t)); |
| 131 |
tab->tab_pool = tab_pool; |
| 132 |
tab->tab_type = tab_type; |
| 133 |
|
| 134 |
|
| 135 |
tab->tab_close = ldaptab_close; |
| 136 |
tab->tab_lookup = ldaptab_lookup; |
| 137 |
tab->tab_verify = ldaptab_verify; |
| 138 |
|
| 139 |
return tab; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
#if defined(PR_SHARED_MODULE) |
| 146 |
static void ldaptab_mod_unload_ev(const void *event_data, void *user_data) { |
| 147 |
if (strcmp("mod_quotatab_ldap.c", (const char *) event_data) == 0) { |
| 148 |
pr_event_unregister("atab_ldap_module, NULL, NULL); |
| 149 |
quotatab_unregister_backend("ldap", QUOTATAB_LIMIT_SRC); |
| 150 |
} |
| 151 |
} |
| 152 |
#endif |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
static int ldaptab_init(void) { |
| 158 |
quotatab_register_backend("ldap", ldaptab_open, QUOTATAB_LIMIT_SRC); |
| 159 |
|
| 160 |
#if defined(PR_SHARED_MODULE) |
| 161 |
pr_event_register("atab_ldap_module, "core.module-unload", |
| 162 |
ldaptab_mod_unload_ev, NULL); |
| 163 |
#endif |
| 164 |
|
| 165 |
return 0; |
| 166 |
} |
| 167 |
|
| 168 |
module quotatab_ldap_module = { |
| 169 |
NULL, NULL, |
| 170 |
|
| 171 |
|
| 172 |
0x20, |
| 173 |
|
| 174 |
|
| 175 |
"quotatab_ldap", |
| 176 |
|
| 177 |
|
| 178 |
NULL, |
| 179 |
|
| 180 |
|
| 181 |
NULL, |
| 182 |
|
| 183 |
|
| 184 |
NULL, |
| 185 |
|
| 186 |
|
| 187 |
ldaptab_init, |
| 188 |
|
| 189 |
|
| 190 |
NULL |
| 191 |
}; |