Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wap_push_ppg_pushuser.h File Reference
#include "gwlib/gwlib.h"

Go to the source code of this file.

Functions

int wap_push_ppg_pushuser_list_add (List *l, long number_of_pushes, long number_of_users)
 
void wap_push_ppg_pushuser_list_destroy (void)
 
int wap_push_ppg_pushuser_authenticate (HTTPClient *client, List *cgivars, Octstr *ip, List *headers, Octstr **username)
 
int wap_push_ppg_pushuser_client_phone_number_acceptable (Octstr *username, Octstr *number)
 
int wap_push_ppg_pushuser_search_ip_from_wildcarded_list (Octstr *haystack, Octstr *needle, Octstr *gwlist_sep, Octstr *ip_sep)
 
Octstrwap_push_ppg_pushuser_smsc_id_get (Octstr *username)
 
Octstrwap_push_ppg_pushuser_dlr_url_get (Octstr *username)
 
Octstrwap_push_ppg_pushuser_smsbox_id_get (Octstr *username)
 

Function Documentation

int wap_push_ppg_pushuser_authenticate ( HTTPClient client,
List cgivars,
Octstr ip,
List headers,
Octstr **  username 
)

Definition at line 223 of file wap_push_ppg_pushuser.c.

References ADDITION, challenge(), dict_get(), dict_put(), dict_remove(), error(), ip_allowed_by_user(), NO_USERNAME, octstr_destroy(), octstr_duplicate, octstr_format(), octstr_get_cstr, octstr_parse_long(), parse_cgivars_for_password(), parse_cgivars_for_username(), password, password_matches(), reply(), response(), and user_find_by_username().

Referenced by pap_request_thread().

224  {
225  time_t now;
226  static long next = 0L; /* used only in this thread (and this
227  function) */
228  long next_time;
229  Octstr *next_time_os;
230  static long multiplier = 1L; /* ditto */
231  WAPPushUser *u;
232  Octstr *copy,
233  *password;
234  int ret;
235 
236  copy = octstr_duplicate(ip);
237  time(&now);
238  next_time_os = NULL;
239 
240  if ((ret = response(push_headers, username, &password)) == NO_USERNAME) {
241  if (!parse_cgivars_for_username(cgivars, username)) {
242  error(0, "no user specified, challenging regardless");
243  goto listed;
244  }
245  }
246 
247  if (password == NULL)
248  parse_cgivars_for_password(cgivars, &password);
249 
250  u = user_find_by_username(*username);
251  if (!ip_allowed_by_user(u, ip)) {
252  goto not_listed;
253  }
254 
255  next = 0;
256 
257  if ((next_time_os = dict_get(next_try, ip)) != NULL) {
258  octstr_parse_long(&next_time, next_time_os, 0, 10);
259  if (difftime(now, (time_t) next_time) < 0) {
260  error(0, "another try from %s, not much time used",
261  octstr_get_cstr(copy));
262  goto listed;
263  }
264  }
265 
266  if (u == NULL) {
267  error(0, "user %s is not allowed by users list, challenging",
268  octstr_get_cstr(*username));
269  goto listed;
270  }
271 
272  if (!password_matches(u, password)) {
273  error(0, "wrong or missing password in request from %s, challenging" ,
274  octstr_get_cstr(copy));
275  goto listed;
276  }
277 
278  dict_remove(next_try, ip); /* no restrictions after authentica-
279  tion */
280  octstr_destroy(password);
281  octstr_destroy(copy);
282  octstr_destroy(next_time_os);
283  return 1;
284 
285 not_listed:
286  octstr_destroy(password);
287  octstr_destroy(copy);
288  reply(c, push_headers);
289  octstr_destroy(next_time_os);
290  return 0;
291 
292 listed:
293  challenge(c, push_headers);
294 
295  multiplier <<= 1;
296  next = next + multiplier * ADDITION;
297  next += now;
298  next_time_os = octstr_format("%ld", next);
299  dict_put(next_try, ip, next_time_os);
300 
301  octstr_destroy(copy);
302  octstr_destroy(password);
303 
304  return 0;
305 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static Dict * next_try
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
static int password_matches(WAPPushUser *u, Octstr *password)
static int parse_cgivars_for_password(List *cgivars, Octstr **password)
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
unsigned char * password
Definition: test_cimd2.c:100
void * dict_remove(Dict *dict, Octstr *key)
Definition: dict.c:307
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static int ip_allowed_by_user(WAPPushUser *u, Octstr *ip)
#define ADDITION
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
Definition: octstr.c:118
long octstr_parse_long(long *nump, Octstr *ostr, long pos, int base)
Definition: octstr.c:747
static int parse_cgivars_for_username(List *cgivars, Octstr **username)
static int response(List *push_headers, Octstr **username, Octstr **password)
static void challenge(HTTPClient *c, List *push_headers)
static void reply(HTTPClient *c, List *push_headers)
static WAPPushUser * user_find_by_username(Octstr *username)
int wap_push_ppg_pushuser_client_phone_number_acceptable ( Octstr username,
Octstr number 
)

Definition at line 312 of file wap_push_ppg_pushuser.c.

References blacklisted(), error(), octstr_get_cstr, prefix_allowed(), user_find_by_username(), and whitelisted().

Referenced by pap_request_thread().

314 {
315  WAPPushUser *u;
316 
317  u = user_find_by_username(username);
318  if (!prefix_allowed(u, number)) {
319  error(0, "Number %s not allowed by user %s (wrong prefix)",
320  octstr_get_cstr(number), octstr_get_cstr(username));
321  return 0;
322  }
323 
324  if (blacklisted(u, number)) {
325  error(0, "Number %s not allowed by user %s (blacklisted)",
326  octstr_get_cstr(number), octstr_get_cstr(username) );
327  return 0;
328  }
329 
330  if (!whitelisted(u, number)) {
331  error(0, "Number %s not allowed by user %s (not whitelisted)",
332  octstr_get_cstr(number), octstr_get_cstr(username) );
333  return 0;
334  }
335 
336  return 1;
337 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static int whitelisted(WAPPushUser *u, Octstr *number)
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static int blacklisted(WAPPushUser *u, Octstr *number)
static int prefix_allowed(WAPPushUser *u, Octstr *number)
static WAPPushUser * user_find_by_username(Octstr *username)
Octstr* wap_push_ppg_pushuser_dlr_url_get ( Octstr username)

Definition at line 400 of file wap_push_ppg_pushuser.c.

References WAPPushUser::dlr_url, dlr_url, octstr_duplicate, and user_find_by_username().

Referenced by set_dlr_url().

401 {
402  WAPPushUser *u;
403  Octstr *dlr_url;
404 
405  u = user_find_by_username(username);
406  dlr_url = u->dlr_url;
407 
408  return octstr_duplicate(dlr_url);
409 }
static Octstr * dlr_url
Definition: test_ppg.c:107
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Definition: octstr.c:118
static WAPPushUser * user_find_by_username(Octstr *username)
int wap_push_ppg_pushuser_list_add ( List l,
long  number_of_pushes,
long  number_of_users 
)

Definition at line 156 of file wap_push_ppg_pushuser.c.

References dict_create(), gw_assert(), gwlist_destroy(), gwlist_extract_first(), octstr_destroy_item(), oneuser_add(), and pushusers_create().

Referenced by read_ppg_config().

158 {
159  CfgGroup *grp;
160 
163  gw_assert(list);
164  while (list && (grp = gwlist_extract_first(list))) {
165  if (oneuser_add(grp) == -1) {
166  gwlist_destroy(list, NULL);
167  return 0;
168  }
169  }
170  gwlist_destroy(list, NULL);
171 
172  return 1;
173 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
static Dict * next_try
static int oneuser_add(CfgGroup *cfg)
static long number_of_users
Definition: wap_push_ppg.c:193
void * gwlist_extract_first(List *list)
Definition: list.c:305
static WAPPushUserList * pushusers_create(long number_of_users)
static WAPPushUserList * users
void octstr_destroy_item(void *os)
Definition: octstr.c:334
gw_assert(wtls_machine->packet_to_send!=NULL)
static long number_of_pushes
Definition: wap_push_ppg.c:191
Definition: cfg.c:73
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
void wap_push_ppg_pushuser_list_destroy ( void  )

Definition at line 175 of file wap_push_ppg_pushuser.c.

References destroy_oneuser(), dict_destroy(), gwlist_destroy(), WAPPushUserList::list, and WAPPushUserList::names.

Referenced by wap_push_ppg_shutdown().

176 {
178  if (users == NULL)
179  return;
180 
183  gw_free(users);
184 }
static Dict * next_try
static void destroy_oneuser(void *p)
static WAPPushUserList * users
void dict_destroy(Dict *dict)
Definition: dict.c:215
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
int wap_push_ppg_pushuser_search_ip_from_wildcarded_list ( Octstr haystack,
Octstr needle,
Octstr gwlist_sep,
Octstr ip_sep 
)

Definition at line 339 of file wap_push_ppg_pushuser.c.

References found, gw_assert(), gwlist_destroy(), gwlist_get(), gwlist_len(), octstr_destroy_item(), octstr_search(), octstr_search_char(), octstr_split(), and wildcarded_ip_found().

Referenced by ip_allowed_by_ppg(), and ip_allowed_by_user().

341 {
342  List *ips;
343  long i;
344  Octstr *configured_ip;
345 
346  gw_assert(haystack);
347  gw_assert(gwlist_sep);
348  gw_assert(ip_sep);
349 
350  /*There are no wildcards in the list*/
351  if (octstr_search_char(haystack, '*', 0) < 0) {
352  if (octstr_search(haystack, needle, 0) >= 0) {
353  return 1;
354  } else {
355  return 0;
356  }
357  }
358 
359  /*There are wildcards in the list*/
360  configured_ip = NULL;
361  ips = octstr_split(haystack, gwlist_sep);
362  for (i = 0; i < gwlist_len(ips); ++i) {
363  configured_ip = gwlist_get(ips, i);
364  if (wildcarded_ip_found(configured_ip, needle, ip_sep))
365  goto found;
366  }
367 
369  return 0;
370 
371 found:
373  return 1;
374 }
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1068
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1010
static struct pid_list * found
static int wildcarded_ip_found(Octstr *ip, Octstr *needle, Octstr *ip_sep)
void octstr_destroy_item(void *os)
Definition: octstr.c:334
gw_assert(wtls_machine->packet_to_send!=NULL)
Definition: octstr.c:118
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1638
Definition: list.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
Octstr* wap_push_ppg_pushuser_smsbox_id_get ( Octstr username)

Definition at line 414 of file wap_push_ppg_pushuser.c.

References octstr_duplicate, WAPPushUser::smsbox_id, smsbox_id, and user_find_by_username().

Referenced by set_smsbox_id().

415 {
416  WAPPushUser *u;
417  Octstr *smsbox_id;
418 
419  u = user_find_by_username(username);
420  smsbox_id = u->smsbox_id;
421 
422  return octstr_duplicate(smsbox_id);
423 }
static Octstr * smsbox_id
Definition: smsbox.c:120
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Definition: octstr.c:118
static WAPPushUser * user_find_by_username(Octstr *username)
Octstr* wap_push_ppg_pushuser_smsc_id_get ( Octstr username)

Definition at line 380 of file wap_push_ppg_pushuser.c.

References default_smsc(), forced_smsc(), octstr_duplicate, smsc_id, and user_find_by_username().

Referenced by set_smsc_id().

381 {
382  WAPPushUser *u;
383  Octstr *smsc_id;
384 
385  if ((u = user_find_by_username(username)) == NULL) {
386  /* no user found with this username */
387  return NULL;
388  }
389 
390  if ((smsc_id = forced_smsc(u)) != NULL)
391  return octstr_duplicate(smsc_id);
392 
393  smsc_id = default_smsc(u);
394  return octstr_duplicate(smsc_id);
395 }
static Octstr * default_smsc(WAPPushUser *u)
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static Octstr * smsc_id
Definition: mtbatch.c:98
Definition: octstr.c:118
static Octstr * forced_smsc(WAPPushUser *u)
static WAPPushUser * user_find_by_username(Octstr *username)
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.