📄 smsbox.c
字号:
info(0, "MO message converted from UCS2 to UTF-8"); octstr_destroy(msg->sms.msgdata); msg->sms.msgdata = octstr_duplicate(text); msg->sms.charset = octstr_create("UTF-8"); msg->sms.coding = DC_7BIT; /* redundant, but this code could be used if another convertion is required converted=1; } else { octstr_destroy(text); text = octstr_duplicate(msg->sms.msgdata); */ } } octstr_destroy(text); } if (octstr_len(msg->sms.sender) == 0 || octstr_len(msg->sms.receiver) == 0) { error(0, "smsbox_req_thread: no sender/receiver, dump follows:"); msg_dump(msg, 0); /* * Send NACK to bearerbox, otherwise message remains in store file. */ mack = msg_create(ack); mack->ack.nack = ack_failed; mack->ack.time = msg->sms.time; uuid_copy(mack->ack.id, msg->sms.id); write_to_bearerbox(mack); msg_destroy(msg); continue; } /* create ack message to be sent afterwards */ mack = msg_create(ack); mack->ack.nack = ack_success; mack->ack.time = msg->sms.time; uuid_copy(mack->ack.id, msg->sms.id); /* * no smsbox services when we are doing ppg dlr - so trans would be * NULL in this case. */ if (dreport) { if (msg->sms.service == NULL || (msg->sms.service != NULL && ppg_service_name != NULL && octstr_compare(msg->sms.service, ppg_service_name) != 0)) { trans = NULL; } else { trans = urltrans_find_service(translations, msg); } info(0, "Starting delivery report <%s> from <%s>", octstr_get_cstr(msg->sms.service), octstr_get_cstr(msg->sms.sender)); } else { trans = urltrans_find(translations, msg->sms.msgdata, msg->sms.smsc_id, msg->sms.sender, msg->sms.receiver); if (trans == NULL) { warning(0, "No translation found for <%s> from <%s> to <%s>", octstr_get_cstr(msg->sms.msgdata), octstr_get_cstr(msg->sms.sender), octstr_get_cstr(msg->sms.receiver)); sms_swap(msg); goto error; } info(0, "Starting to service <%s> from <%s> to <%s>", octstr_get_cstr(msg->sms.msgdata), octstr_get_cstr(msg->sms.sender), octstr_get_cstr(msg->sms.receiver)); /* * now, we change the sender (receiver now 'cause we swap them later) * if faked-sender or similar set. Note that we ignore if the * replacement fails. */ tmp = octstr_duplicate(msg->sms.sender); p = urltrans_faked_sender(trans); if (p != NULL) { octstr_destroy(msg->sms.sender); msg->sms.sender = octstr_duplicate(p); } else if (global_sender != NULL) { octstr_destroy(msg->sms.sender); msg->sms.sender = octstr_duplicate(global_sender); } else { octstr_destroy(msg->sms.sender); msg->sms.sender = octstr_duplicate(msg->sms.receiver); } octstr_destroy(msg->sms.receiver); msg->sms.receiver = tmp; msg->sms.sms_type = mt_reply; } /* TODO: check if the sender is approved to use this service */ if(msg->sms.service == NULL && trans != NULL) msg->sms.service = octstr_duplicate(urltrans_name(trans)); ret = obey_request(&reply, trans, msg); if (ret != 0) { if (ret == -1) { error: error(0, "request failed"); /* XXX this can be something different, according to urltranslation */ reply = octstr_duplicate(reply_requestfailed); trans = NULL; /* do not use any special translation */ } if (!dreport) { /* create reply message */ reply_msg = msg_create(sms); reply_msg->sms.sms_type = mt_reply; reply_msg->sms.sender = msg->sms.sender; msg->sms.sender = NULL; reply_msg->sms.receiver = msg->sms.receiver; msg->sms.receiver = NULL; reply_msg->sms.msgdata = reply; reply_msg->sms.time = time(NULL); /* set current time */ /* send message */ if (send_message(trans, reply_msg) < 0) error(0, "request_thread: failed"); /* cleanup */ msg_destroy(reply_msg); } } write_to_bearerbox(mack); /* implicit msg_destroy */ msg_destroy(msg); }}/*********************************************************************** * HTTP sendsms interface. */#ifdef HAVE_SECURITY_PAM_APPL_H /*Module for pam authentication *//* * Use PAM (Pluggable Authentication Module) to check sendsms authentication. */typedef const struct pam_message pam_message_type;static const char *PAM_username;static const char *PAM_password;static int PAM_conv (int num_msg, pam_message_type **msg, struct pam_response **resp, void *appdata_ptr){ int count = 0, replies = 0; struct pam_response *repl = NULL; int size = sizeof(struct pam_response);#define GET_MEM \ repl = gw_realloc(repl, size); \ size += sizeof(struct pam_response)#define COPY_STRING(s) (s) ? gw_strdup(s) : NULL for (count = 0; count < num_msg; count++) { switch (msg[count]->msg_style) { case PAM_PROMPT_ECHO_ON: GET_MEM; repl[replies].resp_retcode = PAM_SUCCESS; repl[replies++].resp = COPY_STRING(PAM_username); /* PAM frees resp */ break; case PAM_PROMPT_ECHO_OFF: GET_MEM; repl[replies].resp_retcode = PAM_SUCCESS; repl[replies++].resp = COPY_STRING(PAM_password); /* PAM frees resp */ break; case PAM_TEXT_INFO: warning(0, "unexpected message from PAM: %s", msg[count]->msg); break; case PAM_ERROR_MSG: default: /* Must be an error of some sort... */ error(0, "unexpected error from PAM: %s", msg[count]->msg); gw_free(repl); return PAM_CONV_ERR; } } if (repl) *resp = repl; return PAM_SUCCESS;}static struct pam_conv PAM_conversation = { &PAM_conv, NULL};static int authenticate(const char *login, const char *passwd){ pam_handle_t *pamh; int pam_error; PAM_username = login; PAM_password = passwd; pam_error = pam_start("kannel", login, &PAM_conversation, &pamh); if (pam_error != PAM_SUCCESS || (pam_error = pam_authenticate(pamh, 0)) != PAM_SUCCESS) { pam_end(pamh, pam_error); return 0; } pam_end(pamh, PAM_SUCCESS); info(0, "sendsms used by <%s>", login); return 1;}/* * Check for matching username and password for requests. * Return an URLTranslation if successful NULL otherwise. */static int pam_authorise_user(List *list) { Octstr *val, *user = NULL; char *pwd, *login; int result; if ((user = http_cgi_variable(list, "user")) == NULL && (user = http_cgi_variable(list, "username"))==NULL) return 0; login = octstr_get_cstr(user); if ((val = http_cgi_variable(list, "password")) == NULL && (val = http_cgi_variable(list, "pass")) == NULL) return 0; pwd = octstr_get_cstr(val); result = authenticate(login, pwd); return result;}#endif /* HAVE_SECURITY_PAM_APPL_H */static Octstr *smsbox_req_handle(URLTranslation *t, Octstr *client_ip, Octstr *from, Octstr *to, Octstr *text, Octstr *charset, Octstr *udh, Octstr *smsc, int mclass, int mwi, int coding, int compress, int validity, int deferred, int *status, int dlr_mask, Octstr *dlr_url, Octstr *account, int pid, int alt_dcs, int rpi, List *receiver, Octstr *binfo, int priority){ Msg *msg = NULL; Octstr *newfrom, *returnerror, *receiv; List *failed_id, *allowed, *denied; int no_recv, ret = 0, i; long del; /* * Multi-cast messages with several receivers in 'to' are handled * in a loop. We only change sms.time and sms.receiver within the * loop below, because everything else is identical for all receivers. * If receiver is not null, to list is already present on it */ if(receiver == NULL) { receiver = octstr_split_words(to); } no_recv = list_len(receiver); /* * check if UDH length is legal, or otherwise discard the * message, to prevent intentional buffer overflow schemes */ if (udh != NULL && (octstr_len(udh) != octstr_get_char(udh, 0) + 1)) { returnerror = octstr_create("UDH field misformed, rejected"); goto fielderror2; } if (udh != NULL && octstr_len(udh) > MAX_SMS_OCTETS) { returnerror = octstr_create("UDH field is too long, rejected"); goto fielderror2; } /* * Check for white and black lists, first for the URLTranlation * lists and then for the global lists. * * Set the 'allowed' and 'denied' lists accordingly to process at * least all allowed receiver messages. This is a constrain * walk through all disallowing rules within the lists. */ allowed = list_create(); denied = list_create(); for (i = 0; i < no_recv; i++) { receiv = list_get(receiver, i); /* * Check if there are any illegal characters in the 'to' scheme */ if (strspn(octstr_get_cstr(receiv), sendsms_number_chars) < octstr_len(receiv)) { info(0,"Illegal characters in 'to' string ('%s') vs '%s'", octstr_get_cstr(receiv), sendsms_number_chars); list_append_unique(denied, receiv, octstr_item_match); } /* * First of all fill the two lists systematicaly by the rules, * then we will revice the lists. */ if (urltrans_white_list(t) && numhash_find_number(urltrans_white_list(t), receiv) < 1) { info(0, "Number <%s> is not in white-list, message discarded", octstr_get_cstr(receiv)); list_append_unique(denied, receiv, octstr_item_match); } else { list_append_unique(allowed, receiv, octstr_item_match); } if (urltrans_white_list_regex(t) && gw_regex_matches(urltrans_white_list_regex(t), receiv) == NO_MATCH) { info(0, "Number <%s> is not in white-list-regex, message discarded", octstr_get_cstr(receiv)); list_append_unique(denied, receiv, octstr_item_match); } else { list_append_unique(allowed, receiv, octstr_item_match); } if (urltrans_black_list(t) && numhash_find_number(urltrans_black_list(t), receiv) == 1) { info(0, "Number <%s> is in black-list, message discarded", octstr_get_cstr(receiv)); list_append_unique(denied, receiv, octstr_item_match); } else { list_append_unique(allowed, receiv, octstr_item_match); } if (urltrans_black_list_regex(t) && gw_regex_matches(urltrans_black_list_regex(t), receiv) == MATCH) { info(0, "Number <%s> is in black-list-regex, message discarded", octstr_get_cstr(receiv)); list_append_unique(denied, receiv, octstr_item_match); } else { list_append_unique(allowed, receiv, octstr_item_match); } if (white_list && numhash_find_number(white_list, receiv) < 1) { info(0, "Number <%s> is not in global white-list, message discarded", octstr_get_cstr(receiv)); list_append_unique(denied, receiv, octstr_item_match); } else { list_append_unique(allowed, receiv, octstr_item_match); } if (white_list_regex && gw_regex_matches(white_list_regex, receiv) == NO_MATCH) { info(0, "Number <%s> is not in global white-list-regex, message discarded", octstr_get_cstr(receiv)); list_append_unique(denied, receiv, octstr_item_match); } else { list_append_unique(allowed, receiv, octstr_item_match); } if (black_list && numhash_find_number(black_list, receiv) == 1) { info(0, "Number <%s> is in global black-list, message discarded", octstr_get_cstr(receiv)); list_append_unique(denied, receiv, octstr_item_match); } else { list_append_unique(allowed, receiv, octstr_item_match); } if (black_list_regex && gw_regex_matches(black_list_regex, receiv) == MATCH) { info(0, "Number <%s> is in global black-list-regex, message discarded", octstr_get_cstr(receiv)); list_append_unique(denied, receiv, octstr_item_match); } else { list_append_unique(allowed, receiv, octstr_item_match); } } /* * Now we have to revise the 'allowed' and 'denied' lists by walking * the 'denied' li
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -