static struct a2dp_preset *select_preset(struct a2dp_endpoint *endpoint, struct avdtp_remote_sep *rsep) { struct avdtp_service_capability *service; struct avdtp_media_codec_capability *codec; GSList *l; uint8_t codec_len; service = avdtp_get_codec(rsep); codec = (struct avdtp_media_codec_capability *) service->data; codec_len = service->length - sizeof(*codec); for (l = endpoint->presets; l; l = g_slist_next(l)) { struct a2dp_preset *preset = l->data; int err; err = check_capabilities(preset, codec, codec_len); if (err == 0) return preset; if (err == -ERANGE) return select_preset_range(preset, codec, codec_len); } return NULL; }
static void initial_setup() { #ifdef OPENWRT OOR_LOG(LINF,"Open Overlay Router %s compiled for openWRT\n", OOR_VERSION); #else #ifdef ANDROID #ifdef VPNAPI OOR_LOG(LINF,"Open Overlay Router %s compiled for not rooted Android\n", OOR_VERSION); #else OOR_LOG(LINF,"Open Overlay Router %s compiled for rooted Android\n", OOR_VERSION); #endif #else OOR_LOG(LINF,"Open Overlay Router %s compiled for Linux\n", OOR_VERSION); #endif #endif #if UINTPTR_MAX == 0xffffffff OOR_LOG(LDBG_1,"x32 system"); #elif UINTPTR_MAX == 0xffffffffffffffff OOR_LOG(LDBG_1,"x64 system"); #else OOR_LOG(LERR,"Unknow system. Please contact the Open Overlay Router team providing your hardware"); #endif #ifndef VPNAPI if (check_capabilities() != GOOD){ exit(EXIT_SUCCESS); } if(pid_file_check_not_exist() == BAD){ exit(EXIT_SUCCESS); } pid_file_create(); #endif /* Initialize the random number generator */ iseed = (unsigned int) time(NULL); srandom(iseed); setup_signal_handlers(); /* Initialize hash table that control timers */ nonces_ht = htable_nonces_new(); ptrs_to_timers_ht = htable_ptrs_new(); }
int main(int argc, char **argv) { uint32_t iseed = 0; /* initial random number generator */ pid_t pid = 0; /* child pid */ pid_t sid = 0; init_globales(); /* * Parse command line options */ handle_lispd_command_line(argc, argv); #ifndef ANDROID /* * Check for required capabilities and drop unnecssary privileges */ if(check_capabilities() != GOOD) { exit_cleanup(); } #else /* * Check for superuser privileges */ if (geteuid() != 0) { lispd_log_msg(LISP_LOG_INFO,"Running %s requires superuser privileges! Exiting...\n", LISPD); exit_cleanup(); } #endif /* * Initialize the random number generator */ iseed = (unsigned int) time (NULL); srandom(iseed); /* * Set up signal handlers */ signal(SIGHUP, signal_handler); signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); signal(SIGQUIT, signal_handler); /* * set up databases */ if (db_init() != GOOD || map_cache_init() != GOOD || init_referral_cache() != GOOD){ exit_cleanup(); } /* * see if we need to daemonize, and if so, do it */ if (daemonize) { lispd_log_msg(LISP_LOG_DEBUG_1, "Starting the daemonizing process1"); if ((pid = fork()) < 0) { exit_cleanup(); } umask(0); if (pid > 0){ exit(EXIT_SUCCESS); } if ((sid = setsid()) < 0){ exit_cleanup(); } if ((chdir("/")) < 0){ exit_cleanup(); } } /* * create timers */ if (build_timers_event_socket(&timers_fd) != GOOD) { lispd_log_msg(LISP_LOG_CRIT, " Error programing the timer signal. Exiting..."); exit_cleanup(); } init_timers(); /* * Create net_link socket to receive notifications of changes of RLOC status. */ if ((netlink_fd = opent_netlink_socket()) == -1){ lispd_log_msg(LISP_LOG_CRIT, " Error programing netlink socket. Exiting..."); exit_cleanup(); } /* * Parse config file. Format of the file depends on the node: Linux Box or OpenWRT router */ #ifdef OPENWRT if (config_file == NULL){ config_file = strdup("/etc/config/lispd"); } err = handle_uci_lispd_config_file(config_file); #else if (config_file == NULL){ config_file = strdup("/etc/lispd.conf"); } err = handle_lispd_config_file(config_file); #endif if (err != GOOD){ lispd_log_msg(LISP_LOG_CRIT,"Wrong configuration."); exit_cleanup(); } if (ddt_client == FALSE){ drop_referral_cache(); } if (nat_aware == TRUE){ nat_set_xTR_ID(); } /* * Select the default rlocs for output data packets and output control packets */ set_default_output_ifaces(); set_default_ctrl_ifaces(); /* * Create tun interface */ if (create_tun(TUN_IFACE_NAME, TUN_RECEIVE_SIZE, TUN_MTU) != GOOD){ exit_cleanup(); } /* * Assign address to the tun interface and add routing to this interface */ if (configure_routing_to_tun() != GOOD){ exit_cleanup(); } /* * Generate receive sockets for control (4342) and data port (4341) */ if (default_rloc_afi == AF_UNSPEC || default_rloc_afi == AF_INET){ ipv4_control_input_fd = open_control_input_socket(AF_INET); ipv4_data_input_fd = open_data_input_socket(AF_INET); } if (default_rloc_afi == AF_UNSPEC || default_rloc_afi == AF_INET6){ ipv6_control_input_fd = open_control_input_socket(AF_INET6); ipv6_data_input_fd = open_data_input_socket(AF_INET6); } /* * Request to dump the routing tables to obtain the gatways when processing the netlink messages */ request_route_table(RT_TABLE_MAIN, AF_INET); process_netlink_msg(netlink_fd); request_route_table(RT_TABLE_MAIN, AF_INET6); process_netlink_msg(netlink_fd); #ifdef OPENWRT lispd_log_msg(LISP_LOG_INFO,"LISPmob %s compiled for openWRT\n", LISPD_VERSION); #else #ifdef ANDROID lispd_log_msg(LISP_LOG_INFO,"LISPmob %s compiled for Android\n", LISPD_VERSION); #else lispd_log_msg(LISP_LOG_INFO,"LISPmob %s compiled for Linux\n", LISPD_VERSION); #endif #endif lispd_log_msg(LISP_LOG_INFO,"LISPmob (%s): 'lispd' started...", LISPD_VERSION); if (router_mode == TRUE){ lispd_log_msg(LISP_LOG_INFO,"Running as an xTR router"); }else{ lispd_log_msg(LISP_LOG_INFO,"Running as a LISP mobile node"); } /* * Register to the Map-Server(s) */ if (nat_aware == TRUE){ initial_info_request_process(); }else{ initial_map_register_process(); /* * SMR proxy-ITRs list to be updated with new mappings */ init_smr(NULL,NULL); } /* * RLOC Probing proxy ETRs */ programming_petr_rloc_probing(); event_loop(); lispd_log_msg(LISP_LOG_INFO, "Exiting..."); /* event_loop returned bad */ closelog(); return(0); }
int main(int argc, char **argv) { uid_t uid, euid; pid_t pid, parent_pid; gid_t gid; int pipe_fds[2]; int err; parent_pid = getpid (); /* get real user and group ids, effective user id */ uid = getuid (); gid = getgid (); euid = geteuid (); /* are we running suid root? */ if (uid != 0) { if (euid != 0) { fprintf (stderr, "jackstart: not running suid root, can't use capabilities\n"); fprintf (stderr, " (currently running with uid=%d and euid=%d),\n", uid, euid); fprintf (stderr, " make jackstart suid root or start jackd directly\n\n"); } } /* see if we can get the required capabilities */ if (check_capabilities () == 0) { size_t size; cap_t cap = cap_init(); capgetp(0, cap); fprintf (stderr, "jackstart: cannot get realtime capabilities, current capabilities are:\n"); fprintf (stderr, " %s\n", cap_to_text(cap, &size)); fprintf (stderr, " probably running under a kernel with capabilities disabled,\n"); fprintf (stderr, " a suitable kernel would have printed something like \"=eip\"\n\n"); } /* check the executable, owner, permissions, md5 checksum */ if (check_binary(jackd_bin_path)) { exit(1); } /* set process group to current pid */ if (setpgid (0, getpid())) { fprintf (stderr, "jackstart: failed to set process group: %s\n", strerror(errno)); exit (1); } /* create pipe to synchronize with jackd */ if (pipe (pipe_fds)) { fprintf (stderr, "jackstart: could not create pipe: %s\n", strerror(errno)); exit (1); } /* make sure the file descriptors are the right ones, otherwise dup them, this is to make sure that both jackstart and jackd use the same fds */ if (pipe_fds[0] != PIPE_READ_FD) { if (dup2 (pipe_fds[0], PIPE_READ_FD) != PIPE_READ_FD) { fprintf (stderr, "jackstart: could not dup pipe read file descriptor: %s\n", strerror(errno)); exit (1); } } if (pipe_fds[1] != PIPE_WRITE_FD) { if (dup2(pipe_fds[1], PIPE_WRITE_FD)!=PIPE_WRITE_FD) { fprintf (stderr, "jackstart: could not dup pipe write file descriptor: %s\n", strerror(errno)); exit (1); } } /* fork off a child to wait for jackd to start */ fflush(NULL); pid = fork(); if (pid == -1) { fprintf (stderr, "jackstart: fork failed\n"); exit (1); } if (pid) { /* mother process: drops privileges, execs jackd */ close(PIPE_READ_FD); /* get rid of any supplemental groups */ if (!getuid () && setgroups (0, 0)) { fprintf (stderr, "jackstart: setgroups failed: %s\n", strerror(errno)); exit (1); } /* set gid and uid */ setregid(gid, gid); setreuid(uid, uid); execvp(jackd_bin_path, argv); /* we could not start jackd, clean up and exit */ fprintf(stderr, "jackstart: unable to execute %s: %s\n", jackd_bin_path, strerror(errno)); close (PIPE_WRITE_FD); wait (&err); exit (1); } else { /* child process: grants privileges to jackd */ close(PIPE_WRITE_FD); /* wait for jackd to start */ while (1) { int ret; char c; /* picking up pipe closure is a tricky business. this seems to work as well as anything else. */ ret = read(PIPE_READ_FD, &c, 1); fprintf (stderr, "back from read, ret = %d errno == %s\n", ret, strerror (errno)); if (ret == 1) { break; } else if (errno != EINTR) { break; } } /* set privileges on jackd process */ give_capabilities (parent_pid); } exit (0); }