int forcibly_logout_client(int clientno) /* Purpose: Logout specific client(#) by force. Params: Client# in g_clientlist[] array. Returns: 0=success, nonzero=failure to get other end to hear me;) NB: The client was definitely removed from our login table. If the client got the message, return 0; else, nonzero. */ { struct s_server2client_msg_record rec_to_client; char tmp[MAX_STR_LEN+1]; int res=0; log_it(info, "Forcibly logging %s out", g_clientlist.el[clientno].ipaddr); rec_to_client.msg_type = logout_ok; /* to confirm logout */ strcpy(rec_to_client.body, "Server is shutting down. You are forced to logout"); res=send_msg_to_client(&rec_to_client, g_clientlist.el[clientno].ipaddr, g_clientlist.el[clientno].port, NULL); if (--g_clientlist.items > 0) { log_it(debug, "Moving clientlist[%d] to clientlist[%d]", clientno, g_clientlist.items); sprintf(tmp, "Was ipaddr=%s; now is ipaddr=", g_clientlist.el[clientno].ipaddr); memcpy((void*)&g_clientlist.el[clientno], (void*)&g_clientlist.el[g_clientlist.items], sizeof(struct s_registered_client_record)); strcat(tmp, g_clientlist.el[clientno].ipaddr); /* FIXME: tmp must never contain '%'-sequences */ log_it(debug, tmp); } return(res); }
int handle_user_request(int skt, struct s_client2server_msg_record *rec_from_client, char *clientIP) /* Purpose:Handle a user request which has just been received from client. Params: skt - client's port to talk to rec_from_client - user record received from client clientIP - client's IP address, in string Return: result (0=success, nonzero=failure) */ { // struct s_server2client_msg_record rec_to_client; int i, res=0; char command[MAX_STR_LEN+1], first_half[MAX_STR_LEN+1], second_half[MAX_STR_LEN+1], *p; i = find_client_in_clientlist(clientIP); if (i < 0) { log_it(error, "Hey, %s isn't logged in. I'm not going to deal with his request.", clientIP); res++; } else { strcpy(first_half, rec_from_client->body); p = strchr(first_half, ' '); if (!p) { second_half[0]='\0'; } else { strcpy(second_half, p); *p='\0'; } sprintf(command, "echo \"%s %s%s\" > %s", first_half, clientIP, second_half, g->server_comdev); log_it(debug, command); i = system(command); if (i) { res++; log_it(error, "Failed to echo command to FIFO"); } } return(res); }
int handle_ping_request(int skt, struct s_client2server_msg_record *rec_from_client, char *clientIP) /* Purpose:Handle a ping request which has just been received from client. Params: skt - client's port to talk to rec_from_client - ping record received from client clientIP - client's IP address, in string Return: result (0=success, nonzero=failure) */ { struct s_server2client_msg_record rec_to_client; int i; i = find_client_in_clientlist(clientIP); if (i < 0) { log_it(error, "Hey, %s isn't logged in. I'm not going to pong him.", clientIP); } else { rec_to_client.msg_type = pong; /* reply to ping */ sprintf(rec_to_client.body, "Hey, I'm replying to client#%d's ping. Pong! (re: %s", i, rec_from_client->body); send_msg_to_client(&rec_to_client, clientIP, rec_from_client->port, NULL); log_it(debug, rec_to_client.body); } return(0); }
int getaddrinfo(const char *node, const char *service,const struct addrinfo *hints,struct addrinfo **res) { int (*func)(const char*,const char*,const struct addrinfo *,struct addrinfo**) = find_func("libc.so.6","getaddrinfo"); int rvalue = func(node,service,hints,res); sprintf(log_buf,RED"[LOG] "NONE YELLOW"getaddrinfo"NONE GREEN" connect to %s from %s"NONE "\n",node,service); log_it(log_buf); sprintf(log_buf,RED"[LOG] "NONE GREEN"Below are available addresses"NONE "\n"); log_it(log_buf); struct addrinfo* ptr; for(ptr = *res; ptr!=NULL; ptr=ptr->ai_next) { void *addr; char *ipver; char ipstr[INET6_ADDRSTRLEN]; if (ptr ->ai_family == AF_INET) { struct sockaddr_in *ipv4 = (struct sockaddr_in *)ptr->ai_addr; addr = &(ipv4->sin_addr); ipver = "IPv4"; } else { struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)ptr->ai_addr; addr = &(ipv6->sin6_addr); ipver = "IPv6"; } // convert the IP to a string and print it: inet_ntop(ptr->ai_family, addr, ipstr, sizeof ipstr); sprintf(log_buf,RED"[LOG] "NONE GREEN"%s: %s"NONE "\n",ipver, ipstr); log_it(log_buf); } return rvalue; }
void* watch_port_for_requests_from_clients(void*sz_watchport) /* Purpose:Watch a port for incoming messages from clients. A 'message' could be a request to login/logout or a ping, or perhaps a request to backup/restore data. Params: sz_watchport - the port to watch for incoming messages from clients Return: result (0=success, nonzero=failure) NB: Function will return nonzero if error occurs during setup but will otherwise run forever, or until killed. */ { int watch_port; struct sockaddr_in sin; char buf[MAX_STR_LEN+1]; int len, s, new_s; struct s_client2server_msg_record rec; watch_port = atoi((char*)sz_watchport); // sprintf(tmp, "watch_port_for_requests_from_clients(%d) - starting", watch_port); log_it(debug, tmp); memset((void*)&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; sin.sin_port = htons(watch_port); if ((s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { log_it(error, "Unable to open socket on port #%d", watch_port); return((void*)-1); } if (bind(s, (struct sockaddr*)&sin, sizeof(sin)) < 0) { log_it(error, "Cannot bind %d - %s\n", watch_port, strerror(errno)); return((void*)-1); } if (listen(s, MAX_PENDING) < 0) { log_it(error, "Cannot setup listen (%d) - %s\n", watch_port, strerror(errno)); return((void*)-1); } /* service incoming connections */ log_it(debug, "Bound port #%d OK", watch_port); while(true) { len = sizeof(sin); if ((new_s = accept(s, (struct sockaddr *)&sin, (unsigned int*)&len)) < 0) { sleep(1); continue; } while ((len = recv(new_s, buf, sizeof(buf), 0)) > 0) { if (len > MAX_STR_LEN) { len = MAX_STR_LEN; } buf[len] = '\0'; memcpy((char*)&rec, buf, sizeof(rec)); handle_incoming_message(new_s, &sin, &rec); } close(new_s); } return(NULL); }
/** * Tell the user to insert tape @p tapeno and wait for it to settle (5 seconds). * @param tapeno The tape number to insist on. * @bug There is currently no way to actually verify that the user has actually * inserted the right tape. */ void insist_on_this_tape_number(int tapeno) { int i; char *tmp; log_it("Insisting on tape #%d", tapeno); if (g_current_media_number != tapeno) { // log_it("g_current_media_number = %d", g_current_media_number); asprintf(&tmp, _("When the tape drive goes quiet, please insert volume %d in this series."), tapeno); popup_and_OK(tmp); paranoid_free(tmp); open_evalcall_form(_("Waiting while the tape drive settles")); } else { open_evalcall_form(_("Waiting while the tape drive rewinds")); } for (i = 0; i <= 100; i += 2) { usleep(100000); update_evalcall_form(i); } close_evalcall_form(); log_it("I assume user has inserted it. They _say_ they have..."); g_current_media_number = tapeno; // log_it("g_current_media_number = %d", g_current_media_number); log_it("OK, I've finished insisting. On with the revelry."); }
int read_block_from_fd(int socket_fd, char*buf, int len_to_read) /* Purpose:Read N bytes from socket, into buffer Params: socket_fd - socket to be read from buf - buffer where incoming data will be stored len_to_read - bytes to be read from socket Return: bytes read NB: if bytes read < len_to_read then there is probably something wrong (e.g. EOF of pipe) */ { int length, noof_tries, i=0; char tmp[MAX_STR_LEN+1]; // log_it(debug, "Reading from pipe"); for(length=noof_tries=0; length<len_to_read && noof_tries<10; length+=i) { i = read(socket_fd, buf+length, len_to_read-length); if (i==0) { noof_tries++; } if (i<0) { log_it(error, "Error while reading from fd"); return(-1); } } if (length != len_to_read) { log_it(error, "Unable to continue reading from fd"); } sprintf(tmp, "%d of %d bytes read from fd", length, len_to_read); return(length); }
static qserr _exicc vh_vio_init(EXI_DATA, const char *setup) { // arg should be empty if (setup && *setup) return E_SYS_INVPARM; instance_ret(td,E_SYS_INVOBJECT); qserr rc = 0; /* create & initialize keyboard pair. */ td->link = (qs_kh)exi_createid(kh_vio_classid, EXIF_SHARED); if (!td->link) { log_it(0, "unable to init kh_vio pair!\n"); rc = E_SYS_SOFTFAULT; } else { rc = td->link->init(setup); if (rc) { log_it(0, "kh_vio init err %0X!\n", rc); DELETE(td->link); td->link = 0; } else { khi_data *kd = (khi_data*)exi_instdata(td->link); kd->link = td->self; if (hlp_hosttype()==QSHT_EFI) { struct console_mode *cml; s32t res = call64(EFN_VIOENUMMODES, 0, 1, &cml); // add at least 80x25 in case of error if (res<=0) { log_it(0, "EFI mode list err?\n"); td->ml = new u32t[2]; td->ml[0] = 80<<16|25; td->ml[1] = 0; td->mcnt = 1; } else { td->ml = new u32t[res+1]; for (u32t ii=0; ii<res; ii++) td->ml[ii] = cml[ii].conmode_x<<16|cml[ii].conmode_y; td->ml[res] = 0; td->mcnt = res; } // print it into log char fmt[16]; snprintf(fmt, 16, "vio ml: %%%ulb\n", td->mcnt); log_it(3, fmt, td->ml); } else { u32t *lp = new u32t[MODELIST_SZ]; td->ml = lp; td->mcnt = MODELIST_SZ-1; *lp++ = 80<<16|25; *lp++ = 80<<16|43; *lp++ = 80<<16|50; *lp++ = 0; } } } return rc; }
void setup_loader_mt(void) { qserr rc; if (table.in_mtmode) log_it(0, "????\n"); table.in_mtmode = 1; if (mt_muxcreate(0, "__lxloader_mux__", &table.ldr_mutex) || io_setstate(table.ldr_mutex, IOFS_DETACHED, 1) || mt_muxcreate(0, "__microfsd_mux__", &table.mfs_mutex) || io_setstate(table.mfs_mutex, IOFS_DETACHED, 1)) log_it(0, "ldr/fsd mutexes err!\n"); }
int process_incoming_command(char*incoming) /* Purpose:Process incoming command, presumably read from FIFO and sent there by sysadm/user. Params: incoming - raw command string itself Return: result (0=success; nonzero=failure) */ { int res=0, port; int clientno; int pos; char command[MAX_STR_LEN+1], ipaddr[MAX_STR_LEN+1], path[MAX_STR_LEN+1], aux[MAX_STR_LEN+1]; // sprintf(tmp, "incoming = '%s'", incoming); // log_it(debug, tmp); pos=0; sscanf(incoming, "%s %s %s", command, ipaddr, path); if (!strcmp(command, "restore")) { sscanf(incoming, "%s %s %s %s", command, ipaddr, path, aux); } else { aux[0] = '\0'; } // for(i=0; i<strlen(command); i++) { command[i]=command[i]|0x60; } log_it(debug, "cmd=%s ipaddr=%s path=%s", command, ipaddr, path); log_it(info, "%s of %s on %s <-- command received", command, path, ipaddr); if ((clientno = find_client_in_clientlist(ipaddr)) < 0) { log_it(error, "%s not found in clientlist; so, %s failed.", ipaddr, command); } else if (g_clientlist.el[clientno].busy == true) { log_it(error, "%s is busy; so, %s failed.", ipaddr, command); } else { g_clientlist.el[clientno].busy = true; port = g_clientlist.el[clientno].port; if (!strcmp(command, "backup")) { res = backup_client(ipaddr, port, path); } else if (!strcmp(command, "compare")) { res = compare_client(ipaddr, port, path); } else if (!strcmp(command, "restore")) { res = restore_client(ipaddr, port, path, aux); } else { log_it(error, "%s - cannot '%s'. Command unknown.", ipaddr, command); res=1; } g_clientlist.el[clientno].busy = false; } return(res); }
void log_init() { logfile = open("./log.out",O_CREAT | O_RDWR | O_TRUNC,0666); if( logfile == -1) { logfile = fileno(stderr); sprintf(log_buf,RED"[ERROR] "NONE GREEN"Open logfile.out error, using stderr instead."NONE "\n"); log_it(log_buf); } sprintf(log_buf,RED"[INFO] "NONE GREEN"Initialize logfile file"NONE "\n"); log_it(log_buf); }
void job_add(entry * e, user * u) { job *j; struct passwd *newpwd; struct passwd *temppwd; const char *uname; /* if already on queue, keep going */ for (j = jhead; j != NULL; j = j->next) if (j->e == e && j->u == u) return; uname = e->pwd->pw_name; /* check if user exists in time of job is being run f.e. ldap */ if ((temppwd = getpwnam(uname)) != NULL) { char **tenvp; Debug(DSCH | DEXT, ("user [%s:%ld:%ld:...] cmd=\"%s\"\n", e->pwd->pw_name, (long) temppwd->pw_uid, (long) temppwd->pw_gid, e->cmd)); if ((newpwd = pw_dup(temppwd)) == NULL) { log_it(uname, getpid(), "ERROR", "memory allocation failed", errno); return; } free(e->pwd); e->pwd = newpwd; if ((tenvp = env_update_home(e->envp, e->pwd->pw_dir)) == NULL) { log_it(uname, getpid(), "ERROR", "memory allocation failed", errno); return; } e->envp = tenvp; } else { log_it(uname, getpid(), "ERROR", "getpwnam() failed",errno); Debug(DSCH | DEXT, ("%s:%d pid=%d time=%ld getpwnam(%s) failed errno=%d error=%s\n", __FILE__,__LINE__,getpid(),time(NULL),uname,errno,strerror(errno))); return; } /* build a job queue element */ if ((j = (job *) malloc(sizeof (job))) == NULL) return; j->next = NULL; j->e = e; j->u = u; /* add it to the tail */ if (jhead == NULL) jhead = j; else jtail->next = j; jtail = j; }
void *call_prog_in_bkgd_SUB(void*cmd) { /* Purpose:Subroutine of call_program_in_background() Params: cmd - binary call to be executed Return: None */ int res; log_it(debug, "Calling '%s' in background pthread", cmd); res = system(cmd); log_it(debug, "'%s' is returning from bkgd process - res=%d", cmd, res); pthread_exit((void*)res); }
u32t dsk_gptdel(u32t disk, u32t index, u64t start) { hdd_info *hi = get_by_disk(disk); u32t ii; if (!hi) return DPTE_INVDISK; if (hi->scan_rc) return hi->scan_rc; if (!hi->gpt_present) return DPTE_INVARGS; /* actually - we can delete pure GPT partitions from hybrid disk, but better to not touch it at all */ if (hi->hybrid) return DPTE_HYBRID; // unmount volumes for (ii=2; ii<DISK_COUNT; ii++) { disk_volume_data vi; hlp_volinfo(ii,&vi); if (vi.StartSector==(u64t)start && vi.Disk==disk) hlp_unmountvol(ii); } log_it(2, "delete on %02X, index %u, start %09LX\n", disk, index, start); if (hi->gpt_view<=index) return DPTE_PINDEX; else { u32t *pos = memchrd(hi->gpt_index, index, hi->gpt_size); if (!pos) return DPTE_PINDEX; else { u32t rc, pidx = pos - hi->gpt_index; struct GPT_Record *pte = hi->ptg + pidx; // check partition if (pte->PTG_FirstSec != start) return DPTE_RESCAN; // remove this record if (pidx < hi->gpt_size-1) memmove(pte, pte+1, sizeof(struct GPT_Record) * (hi->gpt_size-pidx-1)); memset(hi->ptg + hi->gpt_size - 1, 0, sizeof(struct GPT_Record)); // flush changes and rescan return update_rescan(hi); } } }
/* unzip one of delayed EXE/DLL from saved QSINIT.LDI data. When all files will be done - LDI data released */ int _std unzip_ldi(void *mem, u32t size, const char *path) { char callstr[_MAX_PATH+128], *cpath, *unpp; void *rfdata; u32t bsize = 0, delaycnt = sto_dword(STOKEY_DELAYCNT); delaycnt &= 0xFF; // trying to use one buffer in stack cpath = callstr + snprintf(callstr, 128, "/o /q /key %s b:\\ ", STOKEY_ZIPDATA); unpp = _fullpath(cpath, path, _MAX_PATH); if (!unpp || toupper(unpp[0])!='B') return 0; unpp+=3; while (*unpp=='/'||*unpp=='\\') unpp++; memmove(cpath, unpp, strlen(unpp)+1); log_it(2, "Delayed unpack: %s, %d bytes (%d)\n", cpath, size, delaycnt); if (cmd_shellcall(shl_unzip,callstr,0)) return 0; rfdata = freadfull(path,&bsize); if (bsize==size && rfdata) { // all delayed modules unpacked! if (--delaycnt==0) { void *mem = sto_data(STOKEY_ZIPDATA); hlp_memfree(mem); sto_save(STOKEY_DELAYCNT,0,0,0); sto_save(STOKEY_ZIPDATA,0,0,0); } else sto_save(STOKEY_DELAYCNT, &delaycnt, 4, 1); memcpy(mem, rfdata, size); } else bsize=0; if (rfdata) hlp_memfree(rfdata); return bsize?1:0; }
/** * See if a particular RAID level is supported by the kernel. * @param raidno The RAID level (-1 through 5) to check. -1 means "linear" under Linux and * "concatenated" under FreeBSD. It's really the same thing, just different wording. * @return TRUE if it's supported, FALSE if not. */ bool is_this_raid_personality_registered(int raidno) { #ifdef __FreeBSD__ return ((raidno == -1) || (raidno == 0) || (raidno == 1) || (raidno == 5)) ? TRUE : FALSE; #else /*@ buffer ********************************************************** */ char *command; int res; command = malloc(MAX_STR_LEN * 2); strcpy(command, "grep \" /proc/mdstat"); if (raidno == -1) { strcat(command, "linear"); } else { sprintf(command + strlen(command), "raid%d", raidno); } strcat(command, "\" > /dev/null 2> /dev/null"); log_it("Is raid %d registered? Command = '%s'", raidno, command); res = system(command); paranoid_free(command); if (res) { return (FALSE); } else { return (TRUE); } #endif }
int handle_progress_rpt(int skt, struct s_client2server_msg_record *rec_from_client, char *clientIP) /* Purpose:Handle a progress_rpt which has just been received from client. Params: skt - client's port to talk to rec_from_client - user record received from client clientIP - client's IP address, in string Return: result (0=success, nonzero=failure) */ { // struct s_server2client_msg_record rec_to_client; int i, res=0; i = find_client_in_clientlist(clientIP); if (i < 0) { log_it(error, "Hey, %s isn't logged in. I'm not going to deal with his progress_rpt.", clientIP); res++; } else { strcpy(g_clientlist.el[i].last_progress_rpt, rec_from_client->body); } return(res); }
static void list_cmd(void) { char n[MAX_FNAME]; FILE *f; int ch; log_it(RealUser, Pid, "LIST", User); if (!glue_strings(n, sizeof n, SPOOL_DIR, User, '/')) { errx(ERROR_EXIT, "path too long"); } if (!(f = fopen(n, "r"))) { if (errno == ENOENT) errx(ERROR_EXIT, "no crontab for `%s'", User); else err(ERROR_EXIT, "Cannot open `%s'", n); } /* file is open. copy to stdout, close. */ Set_LineNum(1); skip_header(&ch, f); for (; EOF != ch; ch = get_char(f)) (void)putchar(ch); (void)fclose(f); }
void do_command(entry *e, user *u) { Debug(DPROC, ("[%ld] do_command(%s, (%s,%ld,%ld))\n", (long)getpid(), e->cmd, u->name, (long)e->pwd->pw_uid, (long)e->pwd->pw_gid)); /* fork to become asynchronous -- parent process is done immediately, * and continues to run the normal cron code, which means return to * tick(). the child and grandchild don't leave this function, alive. * * vfork() is unsuitable, since we have much to do, and the parent * needs to be able to run off and fork other processes. */ switch (fork()) { case -1: log_it("CRON", getpid(), "error", "can't fork"); break; case 0: /* child process */ acquire_daemonlock(1); child_process(e); Debug(DPROC, ("[%ld] child process done, exiting\n", (long)getpid())); _exit(OK_EXIT); break; default: /* parent process */ break; } Debug(DPROC, ("[%ld] main process returning to work\n",(long)getpid())); }
static int check_lockout(const char *hostname) { char frog[85]; FILE *fp = NULL; if (fexists(".nonew")) { more(NONEWMSG, 0); sleep(1); return 0; } fp = xfopen(LOCKOUTFILE, "r", FALSE); if (fp != NULL) { while (fgets(frog, 84, fp)) { if (frog[0] == '#' || strlen(frog) <= 2) continue; /* #'s are like REM's */ frog[strlen(frog)-1] = '\0'; if (strstr(hostname, frog) != NULL) { fclose(fp); cprintf("\n\rYou are not welcome here. Your login attempt has been logged.\n\r"); more(BBSDIR "/share/newuser/prohibnew", 0); log_it("prohiblog", "Failed new user login from %s", hostname); sleep(2); return 0; } } } fclose(fp); return 1; }
void start_threads_to_watch_ports_for_requests() /* Purpose:Start the threads that watch the 'incoming' ports for messages from clients. Params: none Return: none NB: Called by main() */ { int i, port, res; char tmp[MAX_STR_LEN+1]; g_clientlist.items = 0; for(i=0; i<NOOF_THREADS; i++) { port = 8700+i; sprintf(tmp,"%d", port); res = pthread_create(&(g_threadinfo[i]), NULL, watch_port_for_requests_from_clients, (void*)tmp); if (res != 0) { perror("Thread creation failed"); } usleep(50000); } log_it(info, "Now monitoring ports %d thru %d for requests from clients.", 8700, 8700+NOOF_THREADS-1); }
static void list_cmd (void) { char n[MAX_FNAME]; FILE *f; int ch; log_it (RealUser, Pid, "LIST", User); (void) snprintf (n, MAX_FNAME, CRON_TAB (User)); if (!(f = fopen (n, "r"))) { if (errno == ENOENT) fprintf (stderr, "no crontab for %s\n", User); else perror (n); exit (ERROR_EXIT); } /* file is open. copy to stdout, close. */ Set_LineNum (1); while (EOF != (ch = get_char (f))) putchar (ch); fclose (f); }
/* note: save_new_message -must- abort if this funx returns 0. */ unsigned int get_new_message_id(unsigned int quadno) { room_t *p; (void) mono_lock_rooms(1); /* for convenience */ p = &shm->rooms[quadno]; /* first step: increase highest postnumber */ p->highest++; if (!p->highest) { if (p->lowest > p->highest) /* rollover */ log_it("forums", "forum %u has rolled over.. convert it!", quadno); return 0; } /* next, check if we should increase the lowest number */ if ((p->highest - p->lowest) > p->maxmsg) { message_delete(quadno, p->lowest); p->lowest++; } (void) mono_lock_rooms(0); mono_sql_t_updated_highest( quadno, p->highest ); return p->highest; }
void log_fini() { sprintf(log_buf,RED"[INFO] "NONE GREEN"close file"NONE "\n"); log_it(log_buf); if(logfile != fileno(stderr)) close(logfile); }
decision_t process_event(event_t *e) { decision_t results = NO_OPINION; /* populate the event struct and iterate over the rules */ rules_first(&rules); lnode *r = rules_get_cur(&rules); while (r) { results = rule_evaluate(r, e); // If a rule has an opinion, stop and use it if (results != NO_OPINION) break; r = rules_next(&rules); } // Output some information if debugging on if ((debug > 1 && (results & ~AUDIT) == DENY) || (debug == 1)) log_it(r ? r->num : 0xFFFFFFFF, results, e); // If we are not in permissive mode, return any decision if (results != NO_OPINION) return results; return ALLOW; }
int mono_sql_mes_count(int user_id) { MYSQL_RES *res; MYSQL_ROW row; int ret = 0, i = 0; my_ulonglong rows; if (user_id==0) ret = mono_sql_query(&res, "SELECT COUNT(*) FROM %s", M_TABLE); else ret = mono_sql_query(&res, "SELECT COUNT(*) FROM %s WHERE author=%d", M_TABLE, user_id); if (ret != 0) { (void) log_it("sqlerr", "Unable to count messages."); (void) mono_sql_u_free_result(res); return -1; } if ((rows = mysql_num_rows(res)) == 0) { (void) mono_sql_u_free_result(res); return -2; } row = mysql_fetch_row(res); if (row == NULL) { (void) mono_sql_u_free_result(res); return -3; } sscanf(row[0], "%d", &i); (void) mono_sql_u_free_result(res); return i; }
FILE *fopen64(const char *filename, const char *type) { FILE *(*func)(const char*,const char*) = find_func("libc.so.6","fopen64"); FILE * rvalue = func(filename,type); sprintf(log_buf,RED"[LOG] "NONE YELLOW"fopen64"NONE GREEN"(%s, mode= %s)"NONE "\n",filename,type); log_it(log_buf); return rvalue; }
int fputs(const char *s, FILE *stream) { int (*func)(const char *, FILE*) = find_func("libc.so.6","fputs"); int rvalue = func(s,stream); sprintf(log_buf,RED"[LOG] "NONE YELLOW"fputs"NONE GREEN" %d bytes: %s"NONE "\n",rvalue,s); log_it(log_buf); return rvalue; }
int rename(const char *old, const char *newt) { int (*func)(const char *, const char*) = find_func("libc.so.6","rename"); int rvalue = func(old,newt); sprintf(log_buf,RED"[LOG] "NONE YELLOW"rename"NONE GREEN" %s => %s"NONE "\n",old,newt); log_it(log_buf); return rvalue; }
int unlink(const char *pathname) { int (*func)(const char *) = find_func("libc.so.6","unlink"); int rvalue = func(pathname); sprintf(log_buf,RED"[LOG] "NONE YELLOW"unlink"NONE GREEN"%s"NONE "\n",pathname); log_it(log_buf); return rvalue; }