static QUERY(sniff_status_show) { char *uid = *(va_arg(ap, char **)); session_t *s = session_find(uid); struct pcap_stat stats; if (!s) return -1; if (!s->connected) return 0; if (!s->priv) { debug_error("sniff_status_show() s->priv NULL\n"); return -1; } /* Device: DEVICE (PROMISC?) */ /* some stats */ memset(&stats, 0, sizeof(struct pcap_stat)); if (pcap_stats(GET_DEV(s), &stats) == -1) { debug_error("sniff_status_show() pcap_stats() failed\n"); return -1; } debug("pcap_stats() recv: %d drop: %d ifdrop: %d\n", stats.ps_recv, stats.ps_drop, stats.ps_ifdrop); print("sniff_pkt_rcv", session_name(s), ekg_itoa(stats.ps_recv)); print("sniff_pkt_drop", session_name(s), ekg_itoa(stats.ps_drop)); print("sniff_conn_db", session_name(s), ekg_itoa(list_count(tcp_connections))); return 0; }
PyObject *ekg_config_set(ekg_configObj * self, PyObject * key, PyObject * value) { char *name = PyString_AsString(key); variable_t *v; debug("[python] Setting '%s' config option to '%s'\n", name, PyString_AsString(value)); v = variable_find(name); if (!v) { PyErr_SetString(PyExc_LookupError, "unknown variable"); return NULL; } if (v->type == VAR_INT || v->type == VAR_BOOL || v->type == VAR_MAP) { if (!PyInt_Check(value)) { PyErr_SetString(PyExc_TypeError, "invalid type"); return NULL; } variable_set(name, ekg_itoa(PyInt_AsLong(value))); } else { if (!PyString_Check(value)) { PyErr_SetString(PyExc_TypeError, "invalid type"); return NULL; } variable_set(name, PyString_AsString(value)); } Py_INCREF(Py_None); return Py_None; }
static COMMAND(sniff_command_connections) { list_t l; for (l = tcp_connections; l; l = l->next) { connection_t *c = l->data; char src_ip[INET_ADDRSTRLEN]; char dst_ip[INET_ADDRSTRLEN]; print_window("__status", session, EKG_WINACT_MSG, 1, "sniff_tcp_connection", inet_ntop(AF_INET, &c->srcip, src_ip, sizeof(src_ip)), ekg_itoa(c->srcport), inet_ntop(AF_INET, &c->dstip, dst_ip, sizeof(dst_ip)), ekg_itoa(c->dstport)); } return 0; }
/** * current_prompt() * * Get the current prompt, locale-recoded. * * @return Static buffer pointer, non-NULL, locale-encoded. */ const /*locale*/ char *current_prompt(void) { static gchar *buf = NULL; session_t *s; char *tmp, *act, *sid; char *format, *format_act; if (no_prompt) return ""; s = session_current; sid = s ? (s->alias?s->alias:s->uid) : ""; if (window_current->id > 1) { format = "rl_prompt_query"; format_act = "rl_prompt_query_act"; } else if (s && (s && s->status == EKG_STATUS_INVISIBLE)) { format = "rl_prompt_invisible"; format_act = "rl_prompt_invisible_act"; } else if (s && (s->status < EKG_STATUS_AVAIL)) { format = "rl_prompt_away"; format_act = "rl_prompt_away_act"; } else { format = "rl_prompt"; format_act = "rl_prompt_act"; } act = window_activity(); if (act) tmp = format_string(format_find(format_act), sid, ekg_itoa(window_current->id), act, window_current->target); else tmp = format_string(format_find(format), sid, ekg_itoa(window_current->id), window_current->target); g_free(buf); buf = ekg_recode_to_locale(tmp); g_free(tmp); g_free(act); return buf; }
/* w sumie starczylby 1 statyczny bufor ... */ static const char *prepare_timestamp_format(const char *format, time_t t) { static char buf[2][100]; struct tm *tm = localtime(&t); static int i = 0; if (!format) return ekg_itoa(t); if (!format[0]) return ""; i = i % 2; if (!strftime(buf[i], sizeof(buf[0]), format, tm)) return "TOOLONG"; return buf[i++]; }
/** * jogger_checkoutfile() * * Tries to open given file (check), and reads it, if expected (checkout). * It is designed to be proof to special file problems (especially named pipe ones). * * @param file - filename to open. * @param data - pointer to store file contents or NULL, if don't want to read it. * @param len - pointer to store filelength or NULL, if not needed. * @param hash - pointer to store filehash or NULL, if not needed. * @param maxlen - maximum filesize to accept (not counting additional NUL) or 0, if n/a. * @param quiet - if set, don't output anything to __status. * * @return 0 on success, errno on failure. */ static int jogger_checkoutfile(const char *file, char **data, int *len, char **hash, const int maxlen, const int quiet) { static char jogger_hash[sizeof(int)*2+3]; int mylen, fs, fd; const char *fn = prepare_path_user(file); if (!fn) return EINVAL; if ((fd = open(fn, O_RDONLY|O_NONBLOCK)) == -1) { /* we use O_NONBLOCK to get rid of FIFO problems */ const int err = errno; if (err == ENXIO) printq("io_nonfile", file); else printq("io_cantopen", file, strerror(err)); return err; } { struct stat st; if ((fstat(fd, &st) == -1) || !S_ISREG(st.st_mode)) { close(fd); printq("io_nonfile", file); return EISDIR; /* nearest, I think */ } fs = st.st_size; } int bufsize = (fs ? (maxlen && fs > maxlen ? maxlen+1 : fs+1) : 0x4000); /* we leave 1 byte for additional NUL */ char *out = xmalloc(bufsize); void *p = out; int _read = 0, res; { int cf = fcntl(fd, F_GETFL); if (cf == -1) /* evil thing */ cf = 0; else cf &= ~O_NONBLOCK; fcntl(fd, F_SETFL, cf); } while ((res = read(fd, p, bufsize-_read))) { if (res == -1) { const int err = errno; if (err != EINTR && err != EAGAIN) { close(fd); printq("io_cantread", file, strerror(errno)); return err; } } else { _read += res; if (maxlen && _read > maxlen) { xfree(out); printq("io_toobig", file, ekg_itoa(_read > fs ? _read : fs), ekg_itoa(maxlen)); return EFBIG; } else if (_read == bufsize) { /* fs sucks? */ bufsize += 0x4000; out = xrealloc(out, bufsize); p = out+_read; } else p += res; } } close(fd); if (_read == 0) { xfree(out); printq("io_emptyfile", file); return EINVAL; /* like mmap() */ } else if (_read+1 != bufsize) { out = xrealloc(out, _read+1); out[_read] = 0; /* add NUL */ } mylen = xstrlen(out); if (fs && _read > fs) printq("io_expanded", file, ekg_itoa(_read), ekg_itoa(fs)); else if (_read < fs) printq("io_truncated", file, ekg_itoa(_read), ekg_itoa(fs)); if (_read > mylen) printq("io_binaryfile", file, ekg_itoa(mylen), ekg_itoa(_read)); if (len) *len = _read; /* I don't want to write my own hashing function, so using EKG2 one * it will fail to hash data after any \0 in file, if there're any * but we also aren't prepared to handle them */ if (hash) { char sizecont[8]; snprintf(sizecont, 8, "0x%%0%lux", sizeof(int)*2); snprintf(jogger_hash, sizeof(int)*2+3, sizecont, ekg_hash(out)); *hash = jogger_hash; } if (data) *data = out; else xfree(out); return 0; }
/* * gg_session_handler_search50() * * zajmuje siê obs³ug± wyniku przeszukiwania katalogu publicznego. * * - s - sesja * - e - opis zdarzenia */ void gg_session_handler_search50(session_t *s, struct gg_event *e) { gg_private_t *g = session_private_get(s); gg_pubdir50_t res = e->event.pubdir50; int i, count, all = 0; list_t l; uin_t last_uin = 0; if (!g) return; if ((count = gg_pubdir50_count(res)) < 1) { print("search_not_found"); return; } debug_function("gg_session_handler_search50() handle_search50, count = %d\n", gg_pubdir50_count(res)); for (l = g->searches; l; l = l->next) { gg_pubdir50_t req = l->data; if (gg_pubdir50_seq(req) == gg_pubdir50_seq(res)) { all = 1; break; } } for (i = 0; i < count; i++) { const char *uin = gg_pubdir50_get(res, i, "fmnumber"); const char *__firstname = gg_pubdir50_get(res, i, "firstname"); const char *__lastname = gg_pubdir50_get(res, i, "lastname"); const char *__nickname = gg_pubdir50_get(res, i, "nickname"); const char *__fmstatus = gg_pubdir50_get(res, i, "fmstatus"); const char *__birthyear = gg_pubdir50_get(res, i, "birthyear"); const char *__city = gg_pubdir50_get(res, i, "city"); char *firstname = gg_to_core_dup(s, __firstname); char *lastname = gg_to_core_dup(s, __lastname); char *nickname = gg_to_core_dup(s, __nickname); char *city = gg_to_core_dup(s, __city); int status = (__fmstatus) ? atoi(__fmstatus) : GG_STATUS_NOT_AVAIL; const char *birthyear = (__birthyear && xstrcmp(__birthyear, "0")) ? __birthyear : NULL; char *name, *active, *gender; const char *target = NULL; if (count == 1 && !all) { xfree(last_search_first_name); xfree(last_search_last_name); xfree(last_search_nickname); xfree(last_search_uid); last_search_first_name = xstrdup(firstname); last_search_last_name = xstrdup(lastname); last_search_nickname = xstrdup(nickname); last_search_uid = saprintf("gg:%s", uin); } name = saprintf( ("%s %s"), firstname ? firstname : (""), lastname ? lastname : ("")); #define __format(x) ((count == 1 && !all) ? "search_results_single" x : "search_results_multi" x) { const char *fvalue; switch (status) { case GG_STATUS_AVAIL: case GG_STATUS_AVAIL_DESCR: fvalue = format_find(__format("_avail")); break; case GG_STATUS_BUSY: case GG_STATUS_BUSY_DESCR: fvalue = format_find(__format("_away")); break; default: fvalue = format_find(__format("_notavail")); } active = format_string(fvalue, (__firstname) ? __firstname : nickname); } gender = format_string(format_find(__format("_unknown")), ""); /* XXX: why do we _exactly_ use it here? can't we just always * define target and thus display result in right conversation window? */ for (l = autofinds; l; l = l->next) { char *d = (char *) l->data; if (!xstrcasecmp(d + 3, uin)) { target = d; break; } } print_info(target, s, __format(""), uin ? uin : ("?"), name, nickname ? nickname : (""), city ? city : (""), birthyear ? birthyear : ("-"), gender, active); #undef __format xfree(name); xfree(active); xfree(gender); xfree(firstname); xfree(lastname); xfree(nickname); xfree(city); last_uin = atoi(uin); } /* je¶li mieli¶my ,,/find --all'', szukamy dalej */ for (l = g->searches; l; l = l->next) { gg_pubdir50_t req = l->data; uin_t next; if (gg_pubdir50_seq(req) != gg_pubdir50_seq(res)) continue; /* nie ma dalszych? to dziêkujemy */ if (!(next = gg_pubdir50_next(res)) || !g->sess || next <= last_uin) { list_remove(&g->searches, req, 0); gg_pubdir50_free(req); break; } gg_pubdir50_add(req, GG_PUBDIR50_START, ekg_itoa(next)); gg_pubdir50(g->sess, req); break; } }
/* * variable_set() * * ustawia warto¶æ podanej zmiennej. je¶li to zmienna liczbowa lub boolowska, * zmienia ci±g na liczbê. w przypadku boolowskich, rozumie zwroty typu `on', * `off', `yes', `no' itp. je¶li dana zmienna jest bitmap±, akceptuje warto¶æ * w postaci listy flag oraz konstrukcje `+flaga' i `-flaga'. * * - name - nazwa zmiennej, * - value - nowa warto¶æ, */ int variable_set(const char *name, const char *value) { variable_t *v = variable_find(name); char *tmpname; int changed = 0; if (!v) return -1; switch (v->type) { case VAR_INT: case VAR_MAP: { const char *p = value; int hex, tmp; if (!value) return -2; if (v->map && v->type == VAR_INT && !xisdigit(*p)) { int i; for (i = 0; v->map[i].label; i++) if (!xstrcasecmp(v->map[i].label, value)) value = ekg_itoa(v->map[i].value); } if (v->map && v->type == VAR_MAP && !xisdigit(*p)) { int i, k = *(int*)(v->ptr); int mode = 0; /* 0 set, 1 add, 2 remove */ char **args; if (*p == '+') { mode = 1; p++; } else if (*p == '-') { mode = 2; p++; } if (!mode) k = 0; args = array_make(p, ",", 0, 1, 0); for (i = 0; args[i]; i++) { int j, found = 0; for (j = 0; v->map[j].label; j++) { if (!xstrcasecmp(args[i], v->map[j].label)) { found = 1; if (mode == 2) k &= ~(v->map[j].value); if (mode == 1) k &= ~(v->map[j].conflicts); if (mode == 1 || !mode) k |= v->map[j].value; } } if (!found) { g_strfreev(args); return -2; } } g_strfreev(args); value = ekg_itoa(k); } p = value; if ((hex = !xstrncasecmp(p, "0x", 2))) p += 2; while (*p && *p != ' ') { if (hex && !xisxdigit(*p)) return -2; if (!hex && !xisdigit(*p)) return -2; p++; } tmp = strtol(value, NULL, 0); if (v->map) { int i; for (i = 0; v->map[i].label; i++) { if ((tmp & v->map[i].value) && (tmp & v->map[i].conflicts)) return -2; } } changed = (*(int*)(v->ptr) != tmp); *(int*)(v->ptr) = tmp; break; } case VAR_BOOL: { int tmp; if (!value) return -2; if ((tmp = on_off(value)) == -1) return -2; changed = (*(int*)(v->ptr) != tmp); *(int*)(v->ptr) = tmp; break; } case VAR_THEME: case VAR_FILE: case VAR_DIR: case VAR_STR: { char **tmp = (char**)(v->ptr); char *oldval = *tmp; if (value) { if (*value == 1) *tmp = base64_decode(value + 1); else *tmp = xstrdup(value); } else *tmp = NULL; changed = xstrcmp(oldval, *tmp); xfree(oldval); break; } default: return -1; } if (v->notify) (v->notify)(v->name); if (!changed) return 1; tmpname = xstrdup(v->name); query_emit(NULL, "variable-changed", &tmpname); xfree(tmpname); return 0; }