void conf_init(void) { init_default_values(); gboolean keyoption = FALSE; Display *dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default()); XrmInitialize(); char basename[12] = "/.Xdefaults"; char *filename = strcat(getpwuid(getuid())->pw_dir, basename); XrmSetDatabase(dpy, XrmGetFileDatabase(filename)); char *op; int i; Option o; for (i = 0; i < OPTION_COUNT; i++) { o = options[i]; if ((op = XGetDefault(dpy, "stjerm", o.long_name))) read_value(o.long_name, op); } char color[8]; for (i = 0; i < 16; i++) { sprintf(color, "color%d", i); if ((op = XGetDefault(dpy, "stjerm", color))) read_value(color, op); } for (i = 1; i < sargc; i++) { if (sargv != NULL) { if (!strcmp(sargv[i], "--help")) { print_help(); exit(1); } else if (!strcmp(sargv[i], "--info")) { print_info(); exit(1); } else if (!strcmp("--toggle", sargv[i])) { kill(get_stjerm_pid(), SIGUSR1); exit(1); } else if (!strcmp("--version", sargv[i]) || !strcmp("-v", sargv[i])){ print_version(); exit(1); } } if (i + 1>= sargc) break; read_value(sargv[i], sargv[i + 1]); } if (keyoption == FALSE && _key == 0) { printf("Hint: You started stjerm without specifying a shortcut key\n" " To show/hide stjerm run stjerm with the toggle option\n" " like this: stjerm --toggle"); } struct stat st; if (stat(_shell, &st) != 0) { fprintf(stderr, "ERROR: The shell '%s' can't be opened\n", _shell); exit(1); } if (_lines < 0) { fprintf(stderr, "ERROR: A scrollback line count < 0 is not allowed\n"); exit(1); } if (keyoption == TRUE && _key == 0) { fprintf(stderr, "ERROR: Wrong shortcut key is defined\n"); exit(1); } if (read_colors > 0 && read_colors < 16) { fprintf(stderr, "ERROR: Read only %d colors, not 16\n" "Specify a complete color palette\n", read_colors); exit(1); } signal(SIGUSR1, (__sighandler_t) mainwindow_toggle); int scrw = gdk_screen_get_width(gdk_screen_get_default()); int scrh = gdk_screen_get_height(gdk_screen_get_default()); if (_pos == POS_TOP) { _posx = (scrw - _width) / 2; _posy = 0; } else if (_pos == POS_BOTTOM) { _posx = (scrw - _width) / 2; _posy = scrh - _height; } else if (_pos == POS_LEFT) { _posx = 0; _posy = (scrh - _height) / 2; } else if (_pos == POS_RIGHT) { _posx = scrw - _width; _posy = (scrh - _height) / 2; } else if (_pos == POS_TOPLEFT) { _posx = 0; _posy = 0; } else if (_pos == POS_TOPRIGHT) { _posx = scrw - _width; _posy = 0; } else if (_pos == POS_BOTTOMLEFT) { _posx = 0; _posy = scrh - _height; } else if (_pos == POS_BOTTOMRIGHT) { _posx = scrw - _width; _posy = scrh - _height; } }
static DiaObject * ellipse_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Ellipse *ellipse; Element *elem; DiaObject *obj; Point p; int i; DiaFont *font = NULL; real font_height; init_default_values(); ellipse = g_malloc0(sizeof(Ellipse)); elem = &ellipse->element; obj = &elem->object; obj->type = &fc_ellipse_type; obj->ops = &ellipse_ops; elem->corner = *startpoint; elem->width = DEFAULT_WIDTH; elem->height = DEFAULT_HEIGHT; ellipse->border_width = attributes_get_default_linewidth(); ellipse->border_color = attributes_get_foreground(); ellipse->inner_color = attributes_get_background(); ellipse->show_background = default_properties.show_background; attributes_get_default_line_style(&ellipse->line_style,&ellipse->dashlength); ellipse->padding = default_properties.padding; attributes_get_default_font(&font, &font_height); p = *startpoint; p.x += elem->width / 2.0; p.y += elem->height / 2.0 + font_height / 2; ellipse->text = new_text("", font, font_height, &p, &ellipse->border_color, ALIGN_CENTER); dia_font_unref(font); /* new default: let the user decide the size? */ ellipse->text_fitting = TEXTFIT_ALWAYS; element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &ellipse->connections[i]; ellipse->connections[i].object = obj; ellipse->connections[i].connected = NULL; ellipse->connections[i].flags = 0; } ellipse->connections[16].flags = CP_FLAGS_MAIN; ellipse_update_data(ellipse, ANCHOR_MIDDLE, ANCHOR_MIDDLE); *handle1 = NULL; *handle2 = obj->handles[7]; return &ellipse->element.object; }
/* * main */ int main(int argc, char **argv) { int ret, dns_index = -1, host_port = 22; int udp_client_sock = -1, tcp_dns_sock = -1; ssize_t recv_size; char buf[1024], host_ip[15], username[NAME_MAX]; struct sockaddr_in saddr; pthread_t log_thread; void *status; progname = argv[0]; ret = set_signal_handler(); if (ret < 0) { goto error; } init_default_values(); ret = parse_args(argc, (const char **)argv); if (ret < 0) { goto error; } if (ssh_host != NULL) { ret = parse_ssh_host(host_ip, &host_port, username); if (ret < 0) { usage(stderr); goto error; } /* Setup SSH forward tunneling */ ssh_info = setup_forward_ssh(host_ip, host_port, username, dns_ip); if (ssh_info == NULL) { goto error; } } else { /* Connect to forward TCP server */ tcp_dns_sock = setup_forward_tcp(forward_port, forward_ip); if (tcp_dns_sock < 0) { goto error; } DBG("Connected TCP tunnel on %s:%d", forward_ip, forward_port); } /* Logging is used with libnetfilter queue */ if (opt_logname != NULL && opt_netfilter == -1) { opt_netfilter = DEFAULT_NETFILTER_QUEUE_NUM; } if (opt_netfilter != -1) { ret = snprintf(buf, sizeof(buf), IPTABLE_ADD_QUEUE, local_port, opt_netfilter); if (ret < 0) { perror("snprintf iptable rule"); goto error; } ret = system(buf); if (ret != 0) { ERR("NFQUEUE iptables command failed\n%s", buf); goto error; } DBG("Queuing UDP traffic on port 53 on queue num %d", opt_netfilter); ret = start_logging_thread(&log_thread); if (ret < 0) { goto error; } } /* * iptables DNAT option. This will redirect all UDP port 53 traffic to the * local-port. */ if (opt_dnat) { /* Execute iptable rule */ ret = snprintf(buf, sizeof(buf), IPTABLE_ADD_DNAT, local_ip, local_port); if (ret < 0) { perror("snprintf iptable rule"); goto error; } ret = system(buf); if (ret != 0) { ERR("DNAT iptables command failed\n%s", buf); goto error; } DBG("Redirecting all UDP traffic on port 53 to %s:%d", local_ip, local_port); } /* Bind on local port to catch DNS request from client */ udp_client_sock = dns_client_setup(local_port, local_ip); if (udp_client_sock < 0) { goto error; } fprintf(stderr, "Listening for DNS request on UDP port %d\n", local_port); while (1) { /* Reset buffer */ memset(buf, 0, sizeof(buf)); /* Receive DNS UDP request */ recv_size = dns_udp_recv_query(udp_client_sock, buf, sizeof(buf), (struct sockaddr *) &saddr); if (recv_size < 0) { /* At this point... better clean exit */ goto error; } /* Change buf to fit DNS TCP request */ forge_tcp_request(buf, &recv_size); /* * Make the DNS query on the TCP transport layer either using inprocess * SSH or using an already created TCP tunnel (Ex: ssh -L ... on the * command line). */ if (ssh_host != NULL) { /* * Round robin option. We must create the ssh tunnel and close it * at each DNS query. */ if (opt_rr_dns) { if ((open_dns_count - dns_index) == 0) { dns_index = 0; } /* * We don't create a new SSH channel for the first run since it * was created before the main loop hence the reason for * dns_index being -1. */ if (dns_index != -1) { dns_ip = open_dns_list[dns_index]; /* * Create new SSH direct tcp channel. We don't care about * the return value because on error, the next call will * handle it. */ libssh2_channel_free(ssh_info->channel); ret = ssh_setup_tunnel(ssh_info, dns_ip); if (ret < 0) { continue; } DBG("Round robin DNS %s", dns_ip); } dns_index++; } recv_size = dig_ssh_request(ssh_info, buf, sizeof(buf), recv_size); if (ret < 0) { do { sleep(DEFAULT_RECONNECT_TIME); ret = ssh_setup_tunnel(ssh_info, dns_ip); } while (ret < 0); continue; } } else { recv_size = dig_tcp_request(tcp_dns_sock, buf, sizeof(buf), recv_size); if (recv_size < 0) { /* Connect to forward TCP server */ do { /* Retry every DEFAULT_RECONNECT_TIME sec */ sleep(DEFAULT_RECONNECT_TIME); tcp_dns_sock = setup_forward_tcp(forward_port, forward_ip); } while (tcp_dns_sock < 0); continue; } } /* Change buf to fit DNS UDP request */ forge_udp_request(buf, &recv_size); ret = dns_udp_send_reply(udp_client_sock, buf, recv_size, (struct sockaddr *) &saddr, sizeof(saddr)); if (ret < 0) { /* UDP client disconnected, continue serving */ continue; } } /* Not suppose to get here */ error: ret = pthread_cancel(log_thread); if (ret == 0) { pthread_join(log_thread, &status); } close(tcp_dns_sock); close(udp_client_sock); cleanup(ret); return 0; }