/* SHLIB-INIT funtab &optional (version -1) (oldest version) */ LVAL xshlibinit() { LVAL subr, val, sym; xlshlib_modinfo_t *info = getnpaddr(xlganatptr()); FUNDEF *p = info->funs; FIXCONSTDEF *pfix = info->fixconsts; FLOCONSTDEF *pflo = info->floconsts; STRCONSTDEF *pstr = info->strconsts; struct version_info defversion; defversion.current = moreargs()?getfixnum(xlgafixnum()):-1; defversion.oldest = moreargs()?getfixnum(xlgafixnum()):defversion.current; xllastarg(); if (! check_version(&defsysversion, &(info->sysversion))) xlfail("shared library not compatible with current system"); if (defversion.current >= 0 && ! check_version(&defversion, &(info->modversion))) xlfail("module not compatible with requested version"); xlsave1(val); val = NIL; if (p != NULL) for (val = NIL; (p->fd_subr) != (LVAL(*)(void)) NULL; p++) { subr = cvsubr(p->fd_subr, p->fd_type & TYPEFIELD, 0); setmulvalp(subr, (p->fd_type & (TYPEFIELD + 1)) ? TRUE : FALSE); val = cons(subr, val); if (p->fd_name != NULL) { sym = xlenter(p->fd_name); setfunction(sym, subr); } } if (pfix != NULL) for (; pfix->name != NULL; pfix++) { sym = xlenter(pfix->name); defconstant(sym, cvfixnum(pfix->val)); } if (pflo != NULL) for (; pflo->name != NULL; pflo++) { sym = xlenter(pflo->name); defconstant(sym, cvflonum(pflo->val)); } if (pstr != NULL) for (; pstr->name != NULL; pstr++) { sym = xlenter(pstr->name); defconstant(sym, cvstring(pstr->val)); } if (info->sysversion.current >= MAKEVERSION(0,1)) { ULONGCONSTDEF *pulong = info->ulongconsts; if (pulong != NULL) for (; pulong->name != NULL; pulong++) { sym = xlenter(pulong->name); defconstant(sym, ulong2lisp(pulong->val)); } } xlpop(); return xlnreverse(val); }
unsigned char restart_netupdate_process() { UINT8 test; UINT8 ipadd[200]; osal_task_sleep(41000); libc_printf("RUN in updata process!!!\n"); //check first time if(check_updata_feasibility()) { // get_service_ipadd(ipadd); // if(1 == libnet_ping_servicer(ipadd)) //zhouxp 2012-02-01 { if(1 == check_version()) { #ifdef AUTO_NETUPDATE ap_send_msg(CTRL_MSG_SUBTYPE_STATUS_NET_UPDATA_NEED_MSG,1,TRUE); #endif return 1; } else { return 0; } } } //check again after one minute in case the system not get IP address in // time osal_task_sleep(60000); while(1) { if(check_updata_feasibility()) { // get_service_ipadd(ipadd); // if(1 == libnet_ping_servicer(ipadd)) //zhouxp 2012-02-01 { if(1 == check_version()) { #ifdef AUTO_NETUPDATE ap_send_msg(CTRL_MSG_SUBTYPE_STATUS_NET_UPDATA_NEED_MSG,1,TRUE); #endif return 1; } else { return 0; } } } osal_task_sleep(1800000); } //libc_printf("end updata process!!!\n"); libc_printf("RUN out updata process!!!\n"); return 0; }
int64_t ClusterMigrate::migrate_kv_data(Node *src_node, Node *dst_node, int num_keys){ src = init_client(src_node->ip, src_node->port); if(src == NULL){ log_error("failed to connect to server!"); return -1; } dst = init_client(dst_node->ip, dst_node->port); if(dst == NULL){ log_error("failed to connect to server!"); return -1; } if(check_version(src) == -1){ return -1; } if(check_version(dst) == -1){ return -1; } ssdb::Status s; KeyRange src_range = src_node->range; KeyRange dst_range = dst_node->range; log_info("old src %s", src_range.str().c_str()); log_info("old dst %s", dst_range.str().c_str()); std::string moved_max_key; int64_t bytes; bytes = move_range(src_range.end, &moved_max_key, num_keys); if(bytes == -1){ return -1; } if(bytes == 0){ return 0; } // update key range src_node->range = KeyRange(moved_max_key, src_range.end); { dst_node->range = KeyRange(dst_range.begin, moved_max_key); log_info("new dst: %s", dst_node->range.str().c_str()); ssdb::Status s = dst->set_kv_range(dst_node->range.begin, dst_node->range.end); if(!s.ok()){ log_fatal("dst server set_kv_range error!"); return -1; } } return bytes; }
static int load_avformat(ffmpeglib_t *lib) { if (!avformat_so) { avformat_so = vice_dynlib_open(AVFORMAT_SO_NAME); if (!avformat_so) { log_debug("opening dynamic library " AVFORMAT_SO_NAME " failed! error: %s", vice_dynlib_error()); return -1; } GET_SYMBOL_AND_TEST_AVFORMAT(av_register_all); GET_SYMBOL_AND_TEST_AVFORMAT(avformat_alloc_context); GET_SYMBOL_AND_TEST_AVFORMAT(avformat_new_stream); GET_SYMBOL_AND_TEST_AVFORMAT(avformat_write_header); GET_SYMBOL_AND_TEST_AVFORMAT(av_interleaved_write_frame); GET_SYMBOL_AND_TEST_AVFORMAT(av_write_trailer); GET_SYMBOL_AND_TEST_AVFORMAT(avio_open); GET_SYMBOL_AND_TEST_AVFORMAT(avio_close); GET_SYMBOL_AND_TEST_AVFORMAT(av_dump_format); GET_SYMBOL_AND_TEST_AVFORMAT(av_guess_format); } #ifdef NO_AVFORMAT_CHECK return 0; #else return check_version("avformat", avformat_so, "avformat_version", LIBAVFORMAT_VERSION_INT); #endif }
static int load_avformat(ffmpeglib_t *lib) { if (!avformat_so) { avformat_so = vice_dynlib_open(AVFORMAT_SO_NAME); if (!avformat_so) { log_debug("opening dynamic library " AVFORMAT_SO_NAME " failed!"); return -1; } GET_SYMBOL_AND_TEST_AVFORMAT(av_init_packet); GET_SYMBOL_AND_TEST_AVFORMAT(av_register_all); GET_SYMBOL_AND_TEST_AVFORMAT(av_new_stream); GET_SYMBOL_AND_TEST_AVFORMAT(av_set_parameters); GET_SYMBOL_AND_TEST_AVFORMAT(av_write_header); GET_SYMBOL_AND_TEST_AVFORMAT(av_write_frame); GET_SYMBOL_AND_TEST_AVFORMAT(av_write_trailer); GET_SYMBOL_AND_TEST_AVFORMAT(url_fopen); GET_SYMBOL_AND_TEST_AVFORMAT(url_fclose); GET_SYMBOL_AND_TEST_AVFORMAT(dump_format); GET_SYMBOL_AND_TEST_AVFORMAT(av_guess_format); #ifndef HAVE_FFMPEG_SWSCALE GET_SYMBOL_AND_TEST_AVFORMAT(img_convert); #endif } #ifdef NO_AVFORMAT_CHECK return 0; #else return check_version("avformat",avformat_so,"avformat_version",LIBAVFORMAT_VERSION_INT); #endif }
static int load_avutil(ffmpeglib_t *lib) { if (!avutil_so) { avutil_so = vice_dynlib_open(AVUTIL_SO_NAME); if (!avutil_so) { log_debug("opening dynamic library " AVUTIL_SO_NAME " failed! error: %s", vice_dynlib_error()); return -1; } GET_SYMBOL_AND_TEST_AVUTIL(av_free); GET_SYMBOL_AND_TEST_AVUTIL(av_frame_alloc); GET_SYMBOL_AND_TEST_AVUTIL(av_frame_get_buffer); GET_SYMBOL_AND_TEST_AVUTIL(av_compare_ts); GET_SYMBOL_AND_TEST_AVUTIL(av_get_channel_layout_nb_channels); GET_SYMBOL_AND_TEST_AVUTIL(av_opt_set_int); #ifndef HAVE_FFMPEG_AVRESAMPLE GET_SYMBOL_AND_TEST_AVUTIL(av_opt_set_sample_fmt); #endif GET_SYMBOL_AND_TEST_AVUTIL(av_rescale_rnd); GET_SYMBOL_AND_TEST_AVUTIL(av_rescale_q); GET_SYMBOL_AND_TEST_AVUTIL(av_d2q); GET_SYMBOL_AND_TEST_AVUTIL(av_frame_make_writable); GET_SYMBOL_AND_TEST_AVUTIL(av_frame_free); GET_SYMBOL_AND_TEST_AVUTIL(av_dict_set); GET_SYMBOL_AND_TEST_AVUTIL(av_dict_free); } #ifdef NO_AVUTIL_CHECK return 0; #else return check_version("avutil", avutil_so, "avutil_version", LIBAVUTIL_VERSION_INT); #endif }
ContactSection::GroupMap ContactSection::extract_groups( const std::string& nym, const std::uint32_t parentVersion, const proto::ContactSection& serialized) { GroupMap groupMap{}; std::map<proto::ContactItemType, ContactGroup::ItemMap> itemMaps{}; const auto& section = serialized.name(); for (const auto& item : serialized.item()) { const auto& itemType = item.type(); auto instantiated = std::make_shared<ContactItem>( nym, check_version(serialized.version(), parentVersion), section, item); OT_ASSERT(instantiated); const auto& itemID = instantiated->ID(); auto& itemMap = itemMaps[itemType]; itemMap.emplace(itemID, instantiated); } for (const auto& itemMap : itemMaps) { const auto& type = itemMap.first; const auto& map = itemMap.second; auto& group = groupMap[type]; group.reset(new ContactGroup(nym, section, type, map)); } return groupMap; }
int main(int argc, char** argv) { #if (defined(WIN32) || defined(WINNT)) // Verify if current running system fulfil minimum requeriments. int retval = check_version(); if (retval != NO_ERROR) return retval; #endif build_package_paths(); #ifdef TEST printf("glade_dir: %s\nlocale_dir: %s\n", glade_dir, locale_dir); #endif // Gettext initialization setlocale(LC_ALL, ""); bindtextdomain(GETTEXT_PACKAGE, locale_dir); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); Gtk::Main kit(argc, argv); wndMain wndmain; kit.run(*wndmain.get_root()); return (EXIT_SUCCESS); }
AboutDialog::AboutDialog(MainWindow *parent) : QDialog(parent) , ui(new Ui::AboutDialog) , m_version(Version()) { ui->setupUi(this); ui->lbl_our_version->setText(QString("VERSION %1 - BRANCH VERSION %2").arg(m_version.to_string()).arg("21.8")); connect(ui->pb_check_version, SIGNAL(clicked()), SLOT(check_version())); }
static void dbus_migration (void) { /* Since version 0.14 dbus is statically linked and not a plugin anymore. * We have to remove it from the autoload list to avoid a crash. * The file has to be removed too so it won't be displayed in the plugins list. */ if (check_version (0, 14, 0) == -1) { dbus_migration_remove_autoload (); dbus_migration_check_file (); } }
static int init_server(AvahiClient *client, int *ret_error) { int r; if ((r = check_version(client, ret_error)) < 0) return r; if ((r = get_server_state(client, ret_error)) < 0) return r; return AVAHI_OK; }
/* this used to be based on file date and somewhat OS-dependant, but now examines the initial part of the file's contents */ boolean uptodate(struct memfile *mf, const char *name) { struct version_info vers_info; boolean verbose = name ? TRUE : FALSE; vers_info.incarnation = mread32(mf); vers_info.feature_set = mread32(mf); vers_info.entity_count = mread32(mf); if (!check_version(&vers_info, name, verbose)) return FALSE; return TRUE; }
extern version_e is_encrypted_aux(bool b, const char *n, char **c, char **h, char **m) { struct stat s; stat(n, &s); if (S_ISDIR(s.st_mode)) return VERSION_UNKNOWN; int64_t f = open(n, O_RDONLY | F_RDLCK | O_BINARY, S_IRUSR | S_IWUSR); if (f < 0) return VERSION_UNKNOWN; uint64_t head[3] = { 0x0 }; if ((read(f, head, sizeof head)) < 0) return close(f) , VERSION_UNKNOWN; if (head[0] != htonll(HEADER_0) && head[1] != htonll(HEADER_1)) return close(f) , VERSION_UNKNOWN; version_e version = check_version(ntohll(head[2])); if (b) { if (version >= VERSION_2015_10) { /* skips past ECC length byte */ uint8_t b; read(f, &b, sizeof b); } uint8_t l; read(f, &l, sizeof l); char *a = gcry_calloc_secure(l + sizeof( char ), sizeof( char )); read(f, a, l); char *s = strchr(a, '/'); *s = '\0'; s++; char *d = strrchr(s, '/'); if (d) { *d = '\0'; d++; } else d = "CBC"; if (*c) *c = strdup(a); if (*h) *h = strdup(s); if (*m) *m = strdup(d); gcry_free(a); } close(f); return version; }
int bootstrap_module_main(int argc, char *argv[], const pt::wptree &data) { init(); check_version(data.get<int>(L"bootstrap.tools.version")); wpath base_dir = current_path(); wpath download_dir = base_dir / BOOTSTRAP_DOWNLOADS; download_files(download_dir, current_path(), data.get_child(L"tools")); PRINT("Bootstraped Polygon-4 Tools successfully"); return 0; }
static void server (int sock) { int command; msock = sock; quit_server = 0; check_version (); do { if (rpc_get (sock, RPC_INT, &command, RPC_END) && (logged_in || command == MC_LOGIN)) exec_command (command); } while (!quit_server); }
JournalStore* journal_store_open(JamAccount *acc, gboolean create, GError **err) { JournalStore *js = NULL; char *path = NULL; sqlite3 *db = NULL; int ret; gboolean exists; path = conf_make_account_path(acc, "journal.db"); exists = g_file_test(path, G_FILE_TEST_EXISTS); if (!exists && !create) { g_set_error(err, 0, 0, "No offline copy of this journal."); goto out; } if (!verify_path(path, FALSE, &err)) goto out; ret = sqlite3_open(path, &db); if (ret != SQLITE_OK) { g_set_error(err, 0, 0, "sqlite error %d: %s", ret, sqlite3_errmsg(db)); goto out; } sqlite3_trace(db, sql_trace, NULL); if (exists) { if (!check_version(db)) { g_set_error(err, 0, 0, "The on-disk journal version differs from " "the version understood by this version of LogJam. " "You need to resynchronize your journal."); goto out; } } else { if (!init_db(db, err)) goto out; } js = g_new0(JournalStore, 1); js->account = acc; js->db = db; out: g_free(path); if (!js && db) sqlite3_close(db); return js; }
static int load_swscale(ffmpeglib_t *lib) { if (!swscale_so) { swscale_so = vice_dynlib_open(SWSCALE_SO_NAME); if (!swscale_so) { log_debug("opening dynamic library " SWSCALE_SO_NAME " failed! error: %s", vice_dynlib_error()); return -1; } GET_SYMBOL_AND_TEST_SWSCALE(sws_getContext); GET_SYMBOL_AND_TEST_SWSCALE(sws_freeContext); GET_SYMBOL_AND_TEST_SWSCALE(sws_scale); } return check_version("swscale", swscale_so, "swscale_version", LIBSWSCALE_VERSION_INT); }
/** * Repondre a une requete Initiate * @param sock Socket du joueur ayant envoye une demande de connexion * @param the_players Liste des joueurs * @param recv_frame Trame Initiate recue * @return Resultat de l'echange (cf. fonction respond pour plus d'informations) */ Result* respond_initiate(int sock, Players the_players, Frame frame) { /* Compteur persistant de joueurs connectes */ static uint16_t nb_connected_players = 0; /* Resultat de l'echange */ Result* result = NULL; /* Acquittement de la requete, negatif par defaut */ Frame ack_frame = create_ack(0); /* Verification de la requete du client */ int format_check = ERROR; int constraint_check = ERROR; constraint_check = check_initiate_constraint(sock, nb_connected_players, the_players); format_check = check_initiate_format(frame); /* Traitement de la requete */ if(constraint_check == SUCCESS && format_check == SUCCESS) { /* Verification du nom d'application et de la version du protocole */ if(check_appname(frame->data[0]->string.content) == SUCCESS && check_version(frame->data[1]->string.content) == SUCCESS) { /* Creation du resultat de l'echange */ result = malloc(sizeof(Result)); result->type = Initiate; result->content = NULL; /* Connexion du nouveau joueur */ the_players->player[nb_connected_players]->sock = sock; the_players->player[nb_connected_players]->is_connected = 1; nb_connected_players++; free_frame(ack_frame); ack_frame = create_ack(1); } } /* Envoi de l'acquittement */ send_frame(sock, ack_frame); return result; }
static int load_swresample(ffmpeglib_t *lib) { if (!swresample_so) { swresample_so = vice_dynlib_open(SWRESAMPLE_SO_NAME); if (!swresample_so) { log_debug("opening dynamic library " SWRESAMPLE_SO_NAME " failed! error: %s", vice_dynlib_error()); return -1; } GET_SYMBOL_AND_TEST_SWRESAMPLE(swr_alloc); GET_SYMBOL_AND_TEST_SWRESAMPLE(swr_init); GET_SYMBOL_AND_TEST_SWRESAMPLE(swr_convert); GET_SYMBOL_AND_TEST_SWRESAMPLE(swr_get_delay); GET_SYMBOL_AND_TEST_SWRESAMPLE(swr_free); } return check_version("swresample", swresample_so, "swresample_version", LIBSWRESAMPLE_VERSION_INT); }
static int print_version_quiet (void *userdata) { char *version = check_version (); /* if it's not the current version AND not network error */ if (!(strcmp (version, hexchat_get_info (ph, "version")) == 0) && !(strcmp (version, "Unknown") == 0)) { #ifdef _WIN64 /* use this approach, the wProcessorArchitecture method always returns 0 (=x86) for plugins for some reason */ hexchat_printf (ph, "%s\tA HexChat update is available! You can download it from here:\nhttps://github.com/downloads/hexchat/hexchat/HexChat%%20%s%%20x64.exe\n", name, version); #else hexchat_printf (ph, "%s\tA HexChat update is available! You can download it from here:\nhttps://github.com/downloads/hexchat/hexchat/HexChat%%20%s%%20x86.exe\n", name, version); #endif /* print update url once, then stop the timer */ return 0; } /* keep checking */ return 1; }
static int load_avutil(ffmpeglib_t *lib) { if (!avutil_so) { avutil_so = vice_dynlib_open(AVUTIL_SO_NAME); if (!avutil_so) { log_debug("opening dynamic library " AVUTIL_SO_NAME " failed!"); return -1; } GET_SYMBOL_AND_TEST_AVUTIL(av_free); } #ifdef NO_AVUTIL_CHECK return 0; #else return check_version("avutil",avutil_so,"avutil_version",LIBAVUTIL_VERSION_INT); #endif }
void boot_other(char *loader,char *boot,char *part,IMAGE_DESCR *descr) { int l_fd,p_fd,walk,found; BOOT_SECTOR buff; if (verbose) printf("Boot other: %s, on %s, loader %s\n",boot,part,loader); (void) geo_open(&geo,boot,O_NOACCESS); if ((l_fd = open(loader,O_RDONLY)) < 0) die("open %s: %s",loader,strerror(errno)); if (!*part) memset(&buff,0,SECTOR_SIZE); else { if ((p_fd = open(part,O_RDONLY)) < 0) die("open %s: %s",part,strerror(errno)); if (read(p_fd,(char *) &buff,SECTOR_SIZE) != SECTOR_SIZE) die("read %s: %s",part,strerror(errno)); } if (read(l_fd,(char *) &buff,PART_TABLE_OFFSET) < 0) die("read %s: %s",loader,strerror(errno)); check_version(&buff,STAGE_CHAIN); if (*part) { found = 0; for (walk = 0; walk < PARTITION_ENTRIES; walk++) if (!PART(buff,walk).sys_ind || PART(buff,walk).start_sect != geo.start) { if (PART(buff,walk).sys_ind != PART_DOS12 && PART(buff,walk). sys_ind != PART_DOS16) PART(buff,walk).sys_ind = PART_INVALID; } else { if (found) die("Duplicate entry in partition table"); buff.par_c.offset = walk*PARTITION_ENTRY; PART(buff,walk).boot_ind = 0x80; found = 1; } if (!found) die("Partition entry not found."); (void) close(p_fd); } (void) close(l_fd); map_begin_section(); map_add_sector(&buff); map_add(&geo,0,1); (void) map_end_section(&descr->start); geo_close(&geo); if (verbose > 1) printf("Mapped 2 (1+1) sectors.\n"); }
static int load_avresample(ffmpeglib_t *lib) { if (!avresample_so) { avresample_so = vice_dynlib_open(AVRESAMPLE_SO_NAME); if (!avresample_so) { log_debug("opening dynamic library " AVRESAMPLE_SO_NAME " failed! error: %s", vice_dynlib_error()); return -1; } GET_SYMBOL_AND_TEST_AVRESAMPLE(avresample_alloc_context); GET_SYMBOL_AND_TEST_AVRESAMPLE(avresample_open); GET_SYMBOL_AND_TEST_AVRESAMPLE(avresample_convert); GET_SYMBOL_AND_TEST_AVRESAMPLE(avresample_get_delay); GET_SYMBOL_AND_TEST_AVRESAMPLE(avresample_free); } return check_version("avresample", avresample_so, "avresample_version", LIBAVRESAMPLE_VERSION_INT); }
static int get_header(FILE *fp, struct file_header *hdr) { rewind(fp); if (fread(hdr, sizeof(struct file_header) - sizeof(__u64), 1, fp) != 1) { fprintf(stderr, "%s: Could not read header\n", toolname); return -1; } swap_header(hdr); if (hdr->magic != DATA_MGR_MAGIC) { fprintf(stderr, "%s: Unregocgnized data in .log file.\n", toolname); return -2; } if (check_version(hdr->version)) return -2; hdr->begin_time = 0; return 0; }
/* SHLIB-INFO funtab */ LVAL xshlibinfo() { LVAL val; xlshlib_modinfo_t *info = getnpaddr(xlganatptr()); FUNDEF *p = info->funs; FIXCONSTDEF *pfix = info->fixconsts; FLOCONSTDEF *pflo = info->floconsts; STRCONSTDEF *pstr = info->strconsts; xllastarg(); if (! check_version(&defsysversion, &(info->sysversion))) xlfail("shared library not compatible with current system"); xlsave1(val); val = cons(cvfixnum((FIXTYPE) info->modversion.current), NIL); val = cons(cvfixnum((FIXTYPE) info->modversion.oldest), val); val = cons(NIL, val); if (p != NULL) { for (; (p->fd_subr) != (LVAL(*)(void)) NULL; p++) rplaca(val, cons(cvstring(p->fd_name), car(val))); rplaca(val, xlnreverse(car(val))); } val = cons(NIL, val); if (pfix != NULL) for (; pfix->name != NULL; pfix++) rplaca(val, cons(cvstring(pfix->name), car(val))); if (pflo != NULL) for (; pflo->name != NULL; pflo++) rplaca(val, cons(cvstring(pflo->name), car(val))); if (pstr != NULL) for (; pstr->name != NULL; pstr++) rplaca(val, cons(cvstring(pstr->name), car(val))); if (info->sysversion.current >= MAKEVERSION(0,1)) { ULONGCONSTDEF *pulong = info->ulongconsts; for (; pulong->name != NULL; pulong++) rplaca(val, cons(cvstring(pulong->name), car(val))); } rplaca(val, xlnreverse(car(val))); xlpop(); return xlnreverse(val); }
static int load_avcodec(ffmpeglib_t *lib) { if (!avcodec_so) { avcodec_so = vice_dynlib_open(AVCODEC_SO_NAME); if (!avcodec_so) { log_debug("opening dynamic library " AVCODEC_SO_NAME " failed!"); return -1; } GET_SYMBOL_AND_TEST_AVCODEC(avcodec_open); GET_SYMBOL_AND_TEST_AVCODEC(avcodec_close); GET_SYMBOL_AND_TEST_AVCODEC(avcodec_find_encoder); GET_SYMBOL_AND_TEST_AVCODEC(avcodec_encode_audio); GET_SYMBOL_AND_TEST_AVCODEC(avcodec_encode_video); GET_SYMBOL_AND_TEST_AVCODEC(avpicture_fill); GET_SYMBOL_AND_TEST_AVCODEC(avpicture_get_size); } return check_version("avcodec",avcodec_so,"avcodec_version",LIBAVCODEC_VERSION_INT); }
static int bmp_checking(const struct bmp_type* img, const unsigned int in_size, const unsigned int max_size) { if (!check_version(img)) { fprintf(stderr,"Wrong BMP version (stegobmp only supports BMPv3\n"); return WRONG_VERSION_ERR; } if (in_size > max_size) { fprintf(stderr,"The chosen image is too small to contain the message (of size %i bytes whereas maximum file size usable with this image is %i bytes)\n",in_size,max_size); return TOO_SMALL_ERR; } if (!check_compression(img)) { fprintf(stderr,"stegobmp doesn't support compressed bmp\n"); return COMPRESSED_ERR; } return 0; }
static int mod_init(void) { if (bind_dbmod(db_url.s, &db )) { LOG(L_CRIT, "Cannot bind to database module! " "Did you forget to load a database module ?\n"); return -1; } /* Check if cache needs to be loaded from domain table */ if (db_mode) { if (connect_db() < 0) goto error; if (check_version() < 0) goto error; if (allocate_tables() < 0) goto error; if (reload_domain_list() < 0) goto error; disconnect_db(); } return 0; error: disconnect_db(); return -1; }
static int mount_fuse(const char *mnt, const char *opts, char *devfd) { int res; int fd; char *dev; struct stat stbuf; char *type = NULL; char *source = NULL; char *mnt_opts = NULL; const char *real_mnt = mnt; int mountpoint_fd = -1; fd = devfd ? check_fuse_device(devfd, &dev) : open_fuse_device(&dev); if (fd == -1) return -1; drop_privs(); read_conf(); if (getuid() != 0 && mount_max != -1) { int mount_count = count_fuse_fs(); if (mount_count >= mount_max) { fprintf(stderr, "%s: too many FUSE filesystems mounted; mount_max=N can be set in /etc/fuse.conf\n", progname); goto fail_close_fd; } } res = check_version(dev); if (res != -1) { res = check_perm(&real_mnt, &stbuf, &mountpoint_fd); restore_privs(); if (res != -1) res = do_mount(real_mnt, &type, stbuf.st_mode & S_IFMT, fd, opts, dev, &source, &mnt_opts, stbuf.st_size); } else restore_privs(); if (mountpoint_fd != -1) close(mountpoint_fd); if (res == -1) goto fail_close_fd; res = chdir("/"); if (res == -1) { fprintf(stderr, "%s: failed to chdir to '/'\n", progname); goto fail_close_fd; } if (geteuid() == 0) { res = add_mount(source, mnt, type, mnt_opts); if (res == -1) { /* Can't clean up mount in a non-racy way */ goto fail_close_fd; } } out_free: free(source); free(type); free(mnt_opts); free(dev); return fd; fail_close_fd: close(fd); fd = -1; goto out_free; }
int main(int argc, const char * argv[]) { struct { int verbose, _1_, keepalive, _2_, timeout, _3_; char * hostname, * port, * source_type, * source_name; } cfg; struct config_var vars[] = { // {"name", {0, f, r, n}, '-', "ENV_NAME", DEFAULT_VALUE, &my_variable}, {"verbose", {0, 1, 0, 0}, 'v', NULL, (void *)1, &cfg.verbose}, {"quiet", {0, 1, 0, 0}, 'q', NULL, (void *)-1, &cfg.verbose}, {"hostname", {0, 0, 1, 0}, 'h', "HOSTNAME", "localhost", &cfg.hostname}, {"port", {0, 0, 1, 0}, 'p', "PORT", SERVER_PORT, &cfg.port}, {"source-type", {0, 0, 1, 0}, 't', "SOURCE_TYPE", "file", &cfg.source_type}, {"source-name", {0, 0, 1, 0}, 's', "SOURCE_NAME", NULL, &cfg.source_name}, {"keepalive-int", {0, 0, 1, 1}, 'k', "KEEPALIVE_INTERVAL", (void *)300, &cfg.keepalive}, {"packet-timeout", {0, 0, 1, 1}, 't', "PACKET_TIMEOUT", (void *)DEFAULT_TIMEOUT, &cfg.timeout} }; int sockfd = 0; ssize_t retv = 0; char buf[256]; pk_keepalive_t * pk = (pk_keepalive_t *)buf; pk_advertize_t * ad; pid_t keepalive_pid = 0; struct keepalive_param kp = {&sockfd, &cfg.keepalive}; config(argc, argv, sizeof(vars)/sizeof(struct config_var), vars); ad = (pk_advertize_t *)alloc_packet(PACKET_SIZE_MAX); if ((retv = !ad)) goto exit; printf("Connecting to %s:%s\n", cfg.hostname, cfg.port); if ((retv = connect_socket(cfg.hostname, cfg.port, &sockfd))) { fprintf(stderr, "Connection failed\n"); goto free; } if ((retv = send_handshake(sockfd, cfg.timeout))) { fprintf(stderr, "Bad handshake\n"); goto free; } _fork(&keepalive_pid, &do_keepalive, &kp); if (!strcasecmp("file", cfg.source_type)) { FILE * file = fopen(cfg.source_name, "r"); if ((retv = !file)) { perror("fopen"); goto free; } // states: // 0 - whitespace before name // 1 - name // 2 - whitespace between name and port // 3 - port // 4 - whitespace after port char state = 0, name[220], port[7]; for (int c = 0, i = 0, j = 0; (c = fgetc(file)) > 0;) switch (state) { case 0: // whitespace before name if (c == '#') { state = 4; break; } else if (c <= 0x20 || 0x7F <= c) break; state = 1; i = 0; case 1: // name if ((retv = i >= sizeof(name))) { fprintf(stderr, "Names cannot be more than %lu characters\n", sizeof(name) - 1); goto fclose; } else if (j == 0 && 0x30 <= c && c <= 0x39) { // if the first character is a number, interpret it as a port port[j++] = c; state = 3; break; } if (0x20 < c && c < 0x7F) { name[i++] = c; break; } state = 2; case 2: // whitespace between name and port if (c <= 0x20 || 0x7F <= c) break; state = 3; j = 0; case 3: // port if ((retv = j >= sizeof(port))) { fprintf(stderr, "Port number cannot be greater than 65535\n"); goto fclose; } else if (0x30 <= c && c <= 0x39) { port[j++] = c; state = 3; break; } else if (0x20 < c && c < 0x7F && c != '#') { fprintf(stderr, "Port numbers must be numeric\n"); goto fclose; } state = 4; case 4: // whitespace after port if (c == '\n' || c == '\r') { name[i] = 0; port[j] = 0; if (i == 0 && j == 0) { state = 0; break; } int portnum = atoi(port); if ((retv = portnum > USHRT_MAX)) { fprintf(stderr, "Port number cannot be greater than 65535\n"); goto fclose; } init_pk_advertize(ad, portnum, name); if (!*name) ad->name.data[0] = '+'; retv = pk_send(sockfd, (pk_keepalive_t *)ad, 0); if ((retv = retv < 0)) goto free; state = 0; } break; default: fprintf(stderr, "Internal error\n"); retv = 1; goto fclose; break; } fclose: fclose(file); } else if (!strcasecmp("sqlite", cfg.source_type)) { fprintf(stderr, "Using SQLite as a source is currently unsupported\n"); retv = 1; goto free; } else { fprintf(stderr, "Bad source type %s\n", cfg.source_type); retv = 1; goto free; } free: free_packet((pk_keepalive_t *)ad); while (!retv) { retv = pk_recv(sockfd, buf, cfg.timeout, 0); if (retv <= 0) break; retv = check_version(pk); } //close: if (sockfd) close(sockfd); kill(keepalive_pid, SIGTERM); exit: return (int)retv; }