static void log_lastlog(struct login_context *cxt) { struct sigaction sa, oldsa_xfsz; struct lastlog ll; time_t t; int fd; if (!cxt->pwd) return; /* lastlog is huge on systems with large UIDs, ignore SIGXFSZ */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; sigaction(SIGXFSZ, &sa, &oldsa_xfsz); fd = open(_PATH_LASTLOG, O_RDWR, 0); if (fd < 0) goto done; if (lseek(fd, (off_t) cxt->pwd->pw_uid * sizeof(ll), SEEK_SET) == -1) goto done; /* * Print last log message. */ if (!cxt->quiet) { if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) && ll.ll_time != 0) { time_t ll_time = (time_t) ll.ll_time; printf(_("Last login: %.*s "), 24 - 5, ctime(&ll_time)); if (*ll.ll_host != '\0') printf(_("from %.*s\n"), (int)sizeof(ll.ll_host), ll.ll_host); else printf(_("on %.*s\n"), (int)sizeof(ll.ll_line), ll.ll_line); } if (lseek(fd, (off_t) cxt->pwd->pw_uid * sizeof(ll), SEEK_SET) == -1) goto done; } memset((char *)&ll, 0, sizeof(ll)); time(&t); ll.ll_time = t; /* ll_time is always 32bit */ if (cxt->tty_name) xstrncpy(ll.ll_line, cxt->tty_name, sizeof(ll.ll_line)); if (cxt->hostname) xstrncpy(ll.ll_host, cxt->hostname, sizeof(ll.ll_host)); if (write_all(fd, (char *)&ll, sizeof(ll))) warn(_("write lastlog failed")); done: if (fd >= 0) close(fd); sigaction(SIGXFSZ, &oldsa_xfsz, NULL); /* restore original setting */ }
/* * Logs failed login attempts in _PATH_BTMP, if it exists. * Must be called only with username the name of an actual user. * The most common login failure is to give password instead of username. */ static void log_btmp(struct login_context *cxt) { struct utmpx ut; struct timeval tv; memset(&ut, 0, sizeof(ut)); strncpy(ut.ut_user, cxt->username ? cxt->username : "******", sizeof(ut.ut_user)); if (cxt->tty_number) strncpy(ut.ut_id, cxt->tty_number, sizeof(ut.ut_id)); if (cxt->tty_name) xstrncpy(ut.ut_line, cxt->tty_name, sizeof(ut.ut_line)); gettimeofday(&tv, NULL); ut.ut_tv.tv_sec = tv.tv_sec; ut.ut_tv.tv_usec = tv.tv_usec; ut.ut_type = LOGIN_PROCESS; /* XXX doesn't matter */ ut.ut_pid = cxt->pid; if (cxt->hostname) { xstrncpy(ut.ut_host, cxt->hostname, sizeof(ut.ut_host)); if (*cxt->hostaddress) memcpy(&ut.ut_addr_v6, cxt->hostaddress, sizeof(ut.ut_addr_v6)); } updwtmpx(_PATH_BTMP, &ut); }
void dolastlog(int quiet) { struct lastlog ll; int fd; if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) { lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), SEEK_SET); if (!quiet) { if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) && ll.ll_time != 0) { time_t ll_time = (time_t) ll.ll_time; printf("Last login: %.*s ", 24-5, ctime(&ll_time)); if (*ll.ll_host != '\0') printf("from %.*s\n", (int)sizeof(ll.ll_host), ll.ll_host); else printf("on %.*s\n", (int)sizeof(ll.ll_line), ll.ll_line); } lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), SEEK_SET); } memset((char *)&ll, 0, sizeof(ll)); time(&ll.ll_time); xstrncpy(ll.ll_line, tty_name, sizeof(ll.ll_line)); if (hostname) xstrncpy(ll.ll_host, hostname, sizeof(ll.ll_host)); write(fd, (char *)&ll, sizeof(ll)); close(fd); } }
int get_hostname_hostip() { static int configured = 0; if (!configured) { struct hostent *hbuf; struct in_addr in; if(gethostname(myhostname, sizeof(myhostname)) == -1) return -1; if ((hbuf = gethostbyname(myhostname)) != NULL) { #if 0 xstrncpy(myhostname, hbuf->h_name, sizeof(myhostname)); xstrncpy(myhostip, hbuf->h_addr, sizeof(myhostip)); #endif if(find_fqdn(myhostname, hbuf) == NULL) /* by asuka */ return -2; memcpy(&in.s_addr, *(hbuf->h_addr_list), sizeof(in.s_addr)); xstrncpy(myhostip, inet_ntoa(in), sizeof(myhostip)); } configured = 1; } return 0; }
/* * Log failed login attempts in _PATH_BTMP if that exists. */ static void log_btmp(struct passwd const* pw) { struct utmp ut; struct timeval tv; const char* tty_name, *tty_num; memset(&ut, 0, sizeof(ut)); strncpy(ut.ut_user, pw && pw->pw_name ? pw->pw_name : "(unknown)", sizeof(ut.ut_user)); get_terminal_name(STDERR_FILENO, NULL, &tty_name, &tty_num); if (tty_num) { xstrncpy(ut.ut_id, tty_num, sizeof(ut.ut_id)); } if (tty_name) { xstrncpy(ut.ut_line, tty_name, sizeof(ut.ut_line)); } #if defined(_HAVE_UT_TV) /* in <utmpbits.h> included by <utmp.h> */ gettimeofday(&tv, NULL); ut.ut_tv.tv_sec = tv.tv_sec; ut.ut_tv.tv_usec = tv.tv_usec; #else { time_t t; time(&t); ut.ut_time = t; /* ut_time is not always a time_t */ } #endif ut.ut_type = LOGIN_PROCESS; /* XXX doesn't matter */ ut.ut_pid = getpid(); updwtmp(_PATH_BTMP, &ut); }
static void logbtmp(const char *line, const char *username, const char *hostname) { struct utmp ut; memset(&ut, 0, sizeof(ut)); strncpy(ut.ut_user, username ? username : "******", sizeof(ut.ut_user)); strncpy(ut.ut_id, line + 3, sizeof(ut.ut_id)); xstrncpy(ut.ut_line, line, sizeof(ut.ut_line)); #if defined(_HAVE_UT_TV) /* in <utmpbits.h> included by <utmp.h> */ gettimeofday(&ut.ut_tv, NULL); #else { time_t t; time(&t); ut.ut_time = t; /* ut_time is not always a time_t */ } #endif ut.ut_type = LOGIN_PROCESS; /* XXX doesn't matter */ ut.ut_pid = pid; if (hostname) { xstrncpy(ut.ut_host, hostname, sizeof(ut.ut_host)); if (hostaddress[0]) memcpy(&ut.ut_addr, hostaddress, sizeof(ut.ut_addr)); } #if HAVE_UPDWTMP /* bad luck for ancient systems */ updwtmp(_PATH_BTMP, &ut); #endif }
char *update_txtbox(char *str, SDL_KeyboardEvent *event) { int len; char *tmp; // enter 13 + numpad 271 // bksp = 8 // esc = 27 len = xstrlen(str); if (event->keysym.sym >= ' ' && event->keysym.sym <= '~') { tmp = (char*)xmalloc(len + 2); xstrncpy(tmp, str, len); tmp[len] = event->keysym.sym; tmp[len + 1] = 0; free(str); str = tmp; } else if (event->keysym.sym == 266) { tmp = (char*)xmalloc(len + 2); xstrncpy(tmp, str, len); tmp[len] = '.'; tmp[len + 1] = 0; free(str); str = tmp; } else if (event->keysym.sym >= 256 && event->keysym.sym <= 265) { tmp = (char*)xmalloc(len + 2); xstrncpy(tmp, str, len); tmp[len] = (event->keysym.sym - 256 + '0'); tmp[len + 1] = 0; free(str); str = tmp; } else if (event->keysym.sym == 27) gfx->win->focus = -1; else if (event->keysym.sym == 8) { if (len > 1) { tmp = xstrndup(str, len - 1); free(str); str = tmp; } else if (len == 1) { free(str); str = 0; } else if (!str) printf("%c", 7); } return (str); }
void redirectStart(clientHttpRequest * http, RH * handler, void *data) { ConnStateData *conn = http->conn; redirectStateData *r = NULL; const char *fqdn; char *urlgroup = conn->port->urlgroup; char buf[8192]; char claddr[20]; char myaddr[20]; assert(http); assert(handler); debug(61, 5) ("redirectStart: '%s'\n", http->uri); if (Config.onoff.redirector_bypass && redirectors->stats.queue_size) { /* Skip redirector if there is one request queued */ n_bypassed++; handler(data, NULL); return; } r = cbdataAlloc(redirectStateData); r->orig_url = xstrdup(http->uri); r->client_addr = conn->log_addr; r->client_ident = NULL; if (http->request->auth_user_request) r->client_ident = authenticateUserRequestUsername(http->request->auth_user_request); else if (http->request->extacl_user) { r->client_ident = http->request->extacl_user; } if (!r->client_ident && conn->rfc931[0]) r->client_ident = conn->rfc931; #if USE_SSL if (!r->client_ident) r->client_ident = sslGetUserEmail(fd_table[conn->fd].ssl); #endif if (!r->client_ident) r->client_ident = dash_str; r->method_s = http->request->method->string; r->handler = handler; r->data = data; cbdataLock(r->data); if ((fqdn = fqdncache_gethostbyaddr(r->client_addr, 0)) == NULL) fqdn = dash_str; xstrncpy(claddr, inet_ntoa(r->client_addr), 20); xstrncpy(myaddr, inet_ntoa(http->request->my_addr), 20); snprintf(buf, 8191, "%s %s/%s %s %s %s myip=%s myport=%d", r->orig_url, claddr, fqdn, r->client_ident[0] ? rfc1738_escape(r->client_ident) : dash_str, r->method_s, urlgroup ? urlgroup : "-", myaddr, http->request->my_port); debug(61, 6) ("redirectStart: sending '%s' to the helper\n", buf); strcat(buf, "\n"); helperSubmit(redirectors, buf, redirectHandleReply, r); }
void voice_init_section(void) { xstrncpy(setup.voice.standardmsg , setup.spool , VOICE_MAX_MESSAGE ); xstrncat(setup.voice.standardmsg , "/messages/standard.msg" , VOICE_MAX_MESSAGE ); xstrncpy(setup.voice.beepmsg , setup.spool , VOICE_MAX_MESSAGE ); xstrncat(setup.voice.beepmsg , "/messages/beep.msg" , VOICE_MAX_MESSAGE ); xstrncpy(setup.voice.timeoutmsg , setup.spool , VOICE_MAX_MESSAGE ); xstrncat(setup.voice.timeoutmsg , "/messages/timeout.msg" , VOICE_MAX_MESSAGE ); xstrncpy(setup.voice.tclscriptname , setup.spool , VOICE_MAX_SCRIPT ); xstrncat(setup.voice.tclscriptname , "/standard.tcl" , VOICE_MAX_SCRIPT ); xstrncpy(setup.voice.checknewpath , setup.spool , VOICE_MAX_CHECKNEW); xstrncat(setup.voice.checknewpath , "/incoming" , VOICE_MAX_CHECKNEW); xstrncpy(setup.voice.callerid , "*** Unknown ***" , VOICE_MAX_CALLERID); xstrncpy(setup.voice.phone , "*** Unknown ***" , VOICE_MAX_PHONE ); xstrncpy(setup.voice.name , "*** Unknown ***" , VOICE_MAX_NAME ); xstrncpy(setup.voice.section , "STANDARD" , VOICE_MAX_SECTION ); setup.voice.rings = -1; setup.voice.ringsonnew = -1; setup.voice.doanswer = TRUE; setup.voice.dorecord = TRUE; setup.voice.dobeep = TRUE; setup.voice.domessage = TRUE; setup.voice.dotimeout = TRUE; setup.voice.recordtime = TRUE; }
/* send the initial data to a basic authenticator module */ static void authenticateBasicStart(auth_user_request_t * auth_user_request, RH * handler, void *data) { authenticateStateData *r = NULL; char buf[8192]; char user[1024], pass[1024]; basic_data *basic_auth; assert(auth_user_request); assert(handler); assert(auth_user_request->auth_user->auth_type == AUTH_BASIC); assert(auth_user_request->auth_user->scheme_data != NULL); basic_auth = auth_user_request->auth_user->scheme_data; debug(29, 9) ("authenticateStart: '%s:%s'\n", basic_auth->username, basic_auth->passwd); if (basicConfig->authenticate == NULL) { handler(data, NULL); return; } /* check to see if the auth_user already has a request outstanding */ if (basic_auth->flags.credentials_ok == 2) { /* there is a request with the same credentials already being verified */ auth_basic_queue_node *node; node = xmalloc(sizeof(auth_basic_queue_node)); assert(node); /* save the details */ node->next = basic_auth->auth_queue; basic_auth->auth_queue = node; node->handler = handler; node->data = data; cbdataLock(data); return; } else { r = cbdataAlloc(authenticateStateData); r->handler = handler; cbdataLock(data); r->data = data; r->auth_user_request = auth_user_request; authenticateAuthUserRequestLock(r->auth_user_request); /* mark the user as haveing verification in progress */ basic_auth->flags.credentials_ok = 2; if (basicConfig->utf8) { latin1_to_utf8(user, sizeof(user), basic_auth->username); latin1_to_utf8(pass, sizeof(pass), basic_auth->passwd); xstrncpy(user, rfc1738_escape(user), sizeof(user)); xstrncpy(pass, rfc1738_escape(pass), sizeof(pass)); } else { xstrncpy(user, rfc1738_escape(basic_auth->username), sizeof(user)); xstrncpy(pass, rfc1738_escape(basic_auth->passwd), sizeof(pass)); } snprintf(buf, sizeof(buf), "%s %s\n", user, pass); helperSubmit(basicauthenticators, buf, authenticateBasicHandleReply, r); } }
static int vboxgettyrc_parse(unsigned char *tty) { unsigned char tempsectname[VBOX_MAX_RCLINE_SIZE + 1]; xstrncpy(temppathname, SYSCONFDIR , PATH_MAX); xstrncat(temppathname, "/vboxgetty.conf", PATH_MAX); /* First time, the global ttyI settings will be */ /* parsed. */ xstrncpy(tempsectname, "vboxgetty-tty", VBOX_MAX_RCLINE_SIZE); if (rc_read(rc_getty_c, temppathname, tempsectname) == -1) return(-1); /* Second, the settings for the used ttyI will be */ /* parsed. */ xstrncpy(tempsectname, "vboxgetty-", VBOX_MAX_RCLINE_SIZE); xstrncat(tempsectname, tty , VBOX_MAX_RCLINE_SIZE); if (rc_read(rc_getty_c, temppathname, tempsectname) == -1) return(-1); /* After this, all unset variables will be filled with */ /* the defaults. */ log_line(LOG_D, "Filling unset configuration variables with defaults...\n"); if (!rc_set_empty(rc_getty_c, "init" , "ATZ&B512" )) return(-1); if (!rc_set_empty(rc_getty_c, "badinitsexit" , "10" )) return(-1); if (!rc_set_empty(rc_getty_c, "initpause" , "2500" )) return(-1); if (!rc_set_empty(rc_getty_c, "commandtimeout" , "4" )) return(-1); if (!rc_set_empty(rc_getty_c, "echotimeout" , "4" )) return(-1); if (!rc_set_empty(rc_getty_c, "ringtimeout" , "6" )) return(-1); if (!rc_set_empty(rc_getty_c, "alivetimeout" , "1800" )) return(-1); if (!rc_set_empty(rc_getty_c, "toggledtrtime" , "400" )) return(-1); if (!rc_set_empty(rc_getty_c, "spooldir" , "/var/spool/vbox")) return(-1); modemsetup.echotimeout = xstrtol(rc_get_entry(rc_getty_c, "echotimeout" ), 4 ); modemsetup.commandtimeout = xstrtol(rc_get_entry(rc_getty_c, "commandtimeout"), 4 ); modemsetup.ringtimeout = xstrtol(rc_get_entry(rc_getty_c, "ringtimeout" ), 6 ); modemsetup.alivetimeout = xstrtol(rc_get_entry(rc_getty_c, "alivetimeout" ), 1800 ); modemsetup.toggle_dtr_time = xstrtol(rc_get_entry(rc_getty_c, "toggledtrtime" ), 400 ); if (!rc_get_entry(rc_getty_c, "initnumber")) { log_line(LOG_E, "Variable \"initnumber\" *must* be set!\n"); return(-1); } return(0); }
static void voice_set_header(vaheader_t *header) { memset(header, 0, sizeof(vaheader_t)); xstrncpy(header->magic , VAH_MAGIC , VAH_MAX_MAGIC ); xstrncpy(header->name , setup.voice.name , VAH_MAX_NAME ); xstrncpy(header->callerid, setup.voice.callerid , VAH_MAX_CALLERID); xstrncpy(header->phone , setup.voice.phone , VAH_MAX_PHONE ); xstrncpy(header->location, "*** Unknown ***" , VAH_MAX_LOCATION); header->time = htonl(time(NULL)); header->compression = htonl(setup.modem.compression); }
static void log_lastlog(struct login_context *cxt) { struct lastlog ll; time_t t; int fd; if (!cxt->pwd) return; fd = open(_PATH_LASTLOG, O_RDWR, 0); if (fd < 0) return; if (lseek(fd, (off_t) cxt->pwd->pw_uid * sizeof(ll), SEEK_SET) == -1) goto done; /* * Print last log message */ if (!cxt->quiet) { if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) && ll.ll_time != 0) { time_t ll_time = (time_t) ll.ll_time; printf(_("Last login: %.*s "), 24 - 5, ctime(&ll_time)); if (*ll.ll_host != '\0') printf(_("from %.*s\n"), (int)sizeof(ll.ll_host), ll.ll_host); else printf(_("on %.*s\n"), (int)sizeof(ll.ll_line), ll.ll_line); } if (lseek(fd, (off_t) cxt->pwd->pw_uid * sizeof(ll), SEEK_SET) == -1) goto done; } memset((char *)&ll, 0, sizeof(ll)); time(&t); ll.ll_time = t; /* ll_time is always 32bit */ if (cxt->tty_name) xstrncpy(ll.ll_line, cxt->tty_name, sizeof(ll.ll_line)); if (cxt->hostname) xstrncpy(ll.ll_host, cxt->hostname, sizeof(ll.ll_host)); if (write_all(fd, (char *)&ll, sizeof(ll))) warn(_("write lastlog failed")); done: close(fd); }
int main(int argc, char *argv[]) { setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); if (!strcmp(program_invocation_short_name, "vigr")) { program = VIGR; xstrncpy(orig_file, GROUP_FILE, sizeof(orig_file)); } else { program = VIPW; xstrncpy(orig_file, PASSWD_FILE, sizeof(orig_file)); } if (1 < argc) { if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) { printf(UTIL_LINUX_VERSION); exit(EXIT_SUCCESS); } if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) usage(stdout); usage(stderr); } edit_file(0); if (program == VIGR) { strncpy(orig_file, SGROUP_FILE, FILENAMELEN - 1); } else { strncpy(orig_file, SHADOW_FILE, FILENAMELEN - 1); } if (access(orig_file, F_OK) == 0) { char response[80]; printf((program == VIGR) ? _("You are using shadow groups on this system.\n") : _("You are using shadow passwords on this system.\n")); /* TRANSLATORS: this program uses for y and n rpmatch(3), * which means they can be translated. */ printf(_("Would you like to edit %s now [y/n]? "), orig_file); if (fgets(response, sizeof(response), stdin)) { if (rpmatch(response) == RPMATCH_YES) edit_file(1); } } exit(EXIT_SUCCESS); }
/* Given a user agent, determine the browser used. * * ###NOTE: The size of the list is proportional to the run time, * which makes this pretty slow * * On error, NULL is returned. * On success, a malloc'd string containing the browser is returned. */ char * verify_browser (char *str, char *type) { char *a, *b, *ptr, *slash; size_t i; if (str == NULL || *str == '\0') return NULL; for (i = 0; i < ARRAY_SIZE (browsers); i++) { if ((a = strstr (str, browsers[i][0])) == NULL) continue; /* check if there is a space char in the token string, that way strpbrk * does not stop at the first space within the token string */ if ((strchr (browsers[i][0], ' ')) != NULL && (b = strchr (a, ' ')) != NULL) b++; else b = a; xstrncpy (type, browsers[i][1], BROWSER_TYPE_LEN); /* Internet Explorer 11 */ if (strstr (a, "rv:11") && strstr (a, "Trident/7.0")) { return alloc_string ("MSIE/11.0"); } /* Opera +15 uses OPR/# */ if (strstr (a, "OPR") != NULL && (slash = strrchr (a, '/'))) { return parse_opera (slash); } /* Opera has the version number at the end */ if (strstr (a, "Opera") && (slash = strrchr (a, '/')) && a < slash) { memmove (a + 5, slash, strlen (slash) + 1); } /* IE Old */ if (strstr (a, "MSIE") != NULL) { if ((ptr = strpbrk (a, ";)-")) != NULL) *ptr = '\0'; a = char_replace (a, ' ', '/'); } /* all others */ else if ((ptr = strpbrk (b, ";) ")) != NULL) { *ptr = '\0'; } return alloc_string (a); } xstrncpy (type, "Unknown", BROWSER_TYPE_LEN); return alloc_string ("Unknown"); }
static void sslProxyConnected(int fd, void *data) { SslStateData *sslState = data; MemBuf mb; HttpHeader hdr_out; Packer p; http_state_flags flags; debug(26, 3) ("sslProxyConnected: FD %d sslState=%p\n", fd, sslState); memset(&flags, '\0', sizeof(flags)); memBufDefInit(&mb); memBufPrintf(&mb, "CONNECT %s HTTP/1.0\r\n", sslState->url); httpBuildRequestHeader(sslState->request, sslState->request, NULL, /* StoreEntry */ &hdr_out, sslState->client.fd, flags); /* flags */ packerToMemInit(&p, &mb); httpHeaderPackInto(&hdr_out, &p); httpHeaderClean(&hdr_out); packerClean(&p); memBufAppend(&mb, "\r\n", 2); xstrncpy(sslState->client.buf, mb.buf, SQUID_TCP_SO_RCVBUF); debug(26, 3) ("sslProxyConnected: Sending {%s}\n", sslState->client.buf); sslState->client.len = mb.size; memBufClean(&mb); commSetTimeout(sslState->server.fd, Config.Timeout.read, sslTimeout, sslState); sslSetSelect(sslState); }
static struct tm * parse_date3(const char *str) { /* Wed Jun 9 01:29:59 1993 GMT */ static struct tm tm; char *s; static char buf[128]; while (*str && *str == ' ') str++; xstrncpy(buf, str, 128); if (NULL == (s = strtok(buf, w_space))) return NULL; if (NULL == (s = strtok(NULL, w_space))) return NULL; tm.tm_mon = make_month(s); if (NULL == (s = strtok(NULL, w_space))) return NULL; tm.tm_mday = atoi(s); if (NULL == (s = strtok(NULL, ":"))) return NULL; tm.tm_hour = atoi(s); if (NULL == (s = strtok(NULL, ":"))) return NULL; tm.tm_min = atoi(s); if (NULL == (s = strtok(NULL, w_space))) return NULL; tm.tm_sec = atoi(s); if (NULL == (s = strtok(NULL, w_space))) return NULL; /* Y2K fix, [email protected] */ tm.tm_year = atoi(s) - 1900; return tmSaneValues(&tm) ? &tm : NULL; }
void storeDiskdUnlink(SwapDir * SD, StoreEntry * e) { int x; int shm_offset; char *buf; diskdinfo_t *diskdinfo = SD->fsdata; debug(79, 3) ("storeDiskdUnlink: dirno %d, fileno %08X\n", SD->index, e->swap_filen); storeDiskdDirReplRemove(e); storeDiskdDirMapBitReset(SD, e->swap_filen); if (diskdinfo->away >= diskdinfo->magic1) { /* Damn, we need to issue a sync unlink here :( */ debug(79, 2) ("storeDiskUnlink: Out of queue space, sync unlink\n"); storeDiskdDirUnlinkFile(SD, e->swap_filen); return; } /* We can attempt a diskd unlink */ buf = storeDiskdShmGet(SD, &shm_offset); xstrncpy(buf, storeDiskdDirFullPath(SD, e->swap_filen, NULL), SHMBUF_BLKSZ); x = storeDiskdSend(_MQD_UNLINK, SD, e->swap_filen, NULL, 0, 0, shm_offset); if (x < 0) { debug(79, 1) ("storeDiskdSend UNLINK: %s\n", xstrerror()); unlink(buf); /* XXX EWW! */ storeDiskdShmPut(SD, shm_offset); } diskd_stats.unlink.ops++; }
int proto_new( int protocol, const char *name, int (*init_func)(struct pork_proto *)) { struct pork_proto *new_proto; int ret; if (protocol < -1 || protocol > PROTO_MAX || proto_table[protocol + 1] != NULL || init_func == NULL) { return (-1); } new_proto = xcalloc(1, sizeof(*new_proto)); new_proto->protocol = protocol; xstrncpy(new_proto->name, name, sizeof(new_proto->name)); ret = init_func(new_proto); if (ret != 0) { free(new_proto); return (ret); } proto_table[protocol + 1] = new_proto; return (0); }
BOOL cl_eval_file(char* file_name) { sByteCode code; sConst constant; sVarTable gv_table; int max_stack; int gv_var_num; char compiled_file_name[PATH_MAX]; /// make compiled file name /// xstrncpy(compiled_file_name, file_name, PATH_MAX-3); xstrncat(compiled_file_name, ".o", PATH_MAX); sByteCode_init(&code); sConst_init(&constant); if(!load_code(&code, &constant, &gv_var_num, &max_stack, compiled_file_name)) { fprintf(stderr, "load script file (%s) failure.\n", compiled_file_name); sByteCode_free(&code); sConst_free(&constant); return FALSE; } if(!cl_main(&code, &constant, gv_var_num, max_stack, CL_STACK_SIZE)) { sByteCode_free(&code); sConst_free(&constant); return FALSE; } sByteCode_free(&code); sConst_free(&constant); return TRUE; }
static BOOL set_flag_to_entried_class(char* real_class_name) { int hash; struct sEntriedClassItem* item; hash = get_hash(real_class_name) % CLASS_HASH_SIZE; item = gEntriedClass + hash; while(1) { if(item->mName[0] == 0) { xstrncpy(item->mName, real_class_name, CL_CLASS_NAME_MAX); break; } else { item ++ ; if(item == gEntriedClass + CLASS_HASH_SIZE) { item = gEntriedClass; } else if(item == gEntriedClass + hash) { return FALSE; } } } return TRUE; }
ani_response_t *ani_send_retry_request(const ani_request_t *request, int retries) { int i = 0; ssize_t length = strlen(request->msg) * sizeof(char); ani_response_t *response = NULL; assert(NULL != request); retries = retries <= 0 ? ANI_DEFAULT_RETRIES : retries; for (i = 0; i < retries; ++i) { if (-1 == ani_send((const void *)request->msg, length) || NULL == (response = ani_get_response(request))) { WARN("communication failed, retrying (iteration=%d)\n", i); continue; } return response; } WARN("ani_send failed, not retrying anymore\n", NULL); response = (ani_response_t *)xmalloc(sizeof(ani_response_t)); response->status_code = ANI_STATUS_SEND_FAILED; (void)xstrncpy(response->msg, "Communication process timed out", RAW_LEN - 1); return response; }
void netdbExchangeStart(void *data) { #if USE_ICMP peer *p = data; char *uri; netdbExchangeState *ex; method_t *method_get; CBDATA_INIT_TYPE(netdbExchangeState); ex = cbdataAlloc(netdbExchangeState); cbdataLock(p); ex->p = p; uri = internalRemoteUri(p->host, p->http_port, "/squid-internal-dynamic/", "netdb"); debug(38, 3) ("netdbExchangeStart: Requesting '%s'\n", uri); assert(NULL != uri); method_get = urlMethodGetKnownByCode(METHOD_GET); ex->r = urlParse(method_get, uri); if (NULL == ex->r) { debug(38, 1) ("netdbExchangeStart: Bad URI %s\n", uri); return; } requestLink(ex->r); assert(NULL != ex->r); httpBuildVersion(&ex->r->http_ver, 1, 0); ex->e = storeCreateEntry(uri, null_request_flags, method_get); assert(NULL != ex->e); ex->sc = storeClientRegister(ex->e, ex); storeClientRef(ex->sc, ex->e, ex->seen, ex->used, SM_PAGE_SIZE, netdbExchangeHandleReply, ex); ex->r->flags.loopdetect = 1; /* cheat! -- force direct */ if (p->login) xstrncpy(ex->r->login, p->login, MAX_LOGIN_SZ); fwdStart(-1, ex->e, ex->r); #endif }
static int del_ident_article(const char *userid) { int fd; FILEHEADER fh; char filename[PATHLEN]; sprintf(filename, "ID/%s", DIR_REC); if ((fd = open(filename, O_RDWR)) < 0) return -1; if (myflock(fd, LOCK_EX)) { close(fd); return -1; } while (read(fd, &fh, FH_SIZE) == FH_SIZE) { if (!(fh.accessed & FILE_DELE) && (!strcmp(fh.owner, userid) || is_ident_ok(fh.owner))) { fh.accessed |= FILE_DELE; xstrncpy(fh.delby, "idcheck", IDLEN); if (lseek(fd, -((off_t) FH_SIZE), SEEK_CUR) == -1 || write(fd, &fh, FH_SIZE) != FH_SIZE) { flock(fd, LOCK_UN); close(fd); return -1; } } } flock(fd, LOCK_UN); close(fd); return 0; }
static xmlChar * new_string_n(const xmlChar *src, size_t len) { xmlChar *ns = (xmlChar *) mmalloc(len + 1); xstrncpy(ns, src, len); ns[len] = 0; return ns; }
void input_history_next(struct input *input) { if (input->history_cur == NULL) return; input->dirty = 1; /* ** If the user hits down when they're already at the end ** of the history list, clear the line. */ if (input->history_cur->prev == NULL) { input->history_cur = NULL; input->input_buf[0] = '\0'; input->cur = input->prompt_len; input->begin_completion = input->cur; input->len = 0; return; } input->history_cur = input->history_cur->prev; xstrncpy(input->input_buf, (char *) input->history_cur->data, sizeof(input->input_buf)); input->cur = strlen(input->input_buf) + input->prompt_len; input->len = input->cur - input->prompt_len; input->begin_completion = input->cur; }
static void mimeLoadIconFile(const char *icon) { int fd; int n; request_flags flags; struct stat sb; StoreEntry *e; LOCAL_ARRAY(char, path, MAXPATHLEN); LOCAL_ARRAY(char, url, MAX_URL); char *buf; const char *type = mimeGetContentType(icon); HttpReply *reply; if (type == NULL) fatal("Unknown icon format while reading mime.conf\n"); buf = internalLocalUri("/squid-internal-static/icons/", icon); xstrncpy(url, buf, MAX_URL); if (storeGetPublic(url, METHOD_GET)) return; snprintf(path, MAXPATHLEN, "%s/%s", Config.icons.directory, icon); fd = file_open(path, O_RDONLY); if (fd < 0) { debug(25, 0) ("mimeLoadIconFile: %s: %s\n", path, xstrerror()); return; } if (fstat(fd, &sb) < 0) { debug(50, 0) ("mimeLoadIconFile: FD %d: fstat: %s\n", fd, xstrerror()); return; } flags = null_request_flags; flags.cachable = 1; e = storeCreateEntry(url, url, flags, METHOD_GET); assert(e != NULL); storeSetPublicKey(e); storeBuffer(e); e->mem_obj->request = requestLink(urlParse(METHOD_GET, url)); httpReplyReset(reply = e->mem_obj->reply); httpReplySetHeaders(reply, 1.0, HTTP_OK, NULL, type, (int) sb.st_size, sb.st_mtime, -1); reply->cache_control = httpHdrCcCreate(); httpHdrCcSetMaxAge(reply->cache_control, 86400); httpHeaderPutCc(&reply->header, reply->cache_control); httpReplySwapOut(reply, e); reply->hdr_sz = e->mem_obj->inmem_hi; /* yuk */ /* read the file into the buffer and append it to store */ buf = memAllocate(MEM_4K_BUF); while ((n = read(fd, buf, 4096)) > 0) storeAppend(e, buf, n); file_close(fd); EBIT_SET(e->flags, ENTRY_SPECIAL); storeBufferFlush(e); storeComplete(e); storeTimestampsSet(e); debug(25, 3) ("Loaded icon %s\n", url); storeUnlockObject(e); memFree(buf, MEM_4K_BUF); }
int errorMapStart(const errormap * map, request_t * client_req, HttpReply * reply, const char *aclname, ERRMAPCB * callback, void *callback_data) { char squid_error[100]; int len = 0; const char *errorUrl; ErrorMapState *state; const char *tmp; http_status status; request_t *req; HttpHeaderPos hdrpos; HttpHeaderEntry *hdr; if (!client_req || !reply) return 0; status = reply->sline.status; tmp = httpHeaderGetStr(&reply->header, HDR_X_SQUID_ERROR); squid_error[0] = '\0'; if (tmp) { xstrncpy(squid_error, tmp, sizeof(squid_error)); len = strcspn(squid_error, " "); } squid_error[len] = '\0'; errorUrl = getErrorMap(map, status, squid_error, aclname); if (!errorUrl) return 0; req = urlParse(urlMethodGetKnownByCode(METHOD_GET), (char *) errorUrl); if (!req) { debug(0, 0) ("errorMapStart: Invalid error URL '%s'\n", errorUrl); return 0; } req->urlgroup = xstrdup("error"); state = cbdataAlloc(ErrorMapState); state->req = requestLink(req); state->e = storeCreateEntry(errorUrl, req->flags, req->method); state->sc = storeClientRegister(state->e, state); state->callback = callback; state->callback_data = callback_data; cbdataLock(callback_data); hdrpos = HttpHeaderInitPos; while ((hdr = httpHeaderGetEntry(&client_req->header, &hdrpos)) != NULL) { if (CBIT_TEST(client_headers, hdr->id)) httpHeaderAddClone(&req->header, hdr); } hdrpos = HttpHeaderInitPos; while ((hdr = httpHeaderGetEntry(&reply->header, &hdrpos)) != NULL) { if (CBIT_TEST(server_headers, hdr->id)) httpHeaderAddClone(&req->header, hdr); } httpHeaderPutInt(&req->header, HDR_X_ERROR_STATUS, (int) reply->sline.status); httpHeaderPutStr(&req->header, HDR_X_REQUEST_URI, urlCanonical(client_req)); fwdStart(-1, state->e, req); storeClientRef(state->sc, state->e, 0, 0, SM_PAGE_SIZE, errorMapFetchHeaders, state); return 1; }
static void write_uuid_and_label(unsigned char *uuid, char *volume_name) { struct swap_header_v1_2 *h; /* Sanity check */ if (sizeof(struct swap_header_v1) != sizeof(struct swap_header_v1_2)) { warnx(_("Bad swap header size, no label written.")); return; } h = (struct swap_header_v1_2 *) signature_page; if (uuid) memcpy(h->uuid, uuid, sizeof(h->uuid)); if (volume_name) { xstrncpy(h->volume_name, volume_name, sizeof(h->volume_name)); if (strlen(volume_name) > strlen(h->volume_name)) warnx(_("Label was truncated.")); } if (uuid || volume_name) { if (volume_name) printf("LABEL=%s, ", h->volume_name); else printf(_("no label, ")); #ifdef HAVE_LIBUUID if (uuid) { char uuid_string[37]; uuid_unparse(uuid, uuid_string); printf("UUID=%s\n", uuid_string); } else #endif printf(_("no uuid\n")); } }
static void set_uuid_and_label(const struct mkswap_control *ctl) { assert(ctl); assert(ctl->hdr); /* set UUID */ if (ctl->uuid) memcpy(ctl->hdr->uuid, ctl->uuid, sizeof(ctl->hdr->uuid)); /* set LABEL */ if (ctl->opt_label) { xstrncpy(ctl->hdr->volume_name, ctl->opt_label, sizeof(ctl->hdr->volume_name)); if (strlen(ctl->opt_label) > strlen(ctl->hdr->volume_name)) warnx(_("Label was truncated.")); } /* report resuls */ if (ctl->uuid || ctl->opt_label) { if (ctl->opt_label) printf("LABEL=%s, ", ctl->hdr->volume_name); else printf(_("no label, ")); #ifdef HAVE_LIBUUID if (ctl->uuid) { char uuid_string[37]; uuid_unparse(ctl->uuid, uuid_string); printf("UUID=%s\n", uuid_string); } else #endif printf(_("no uuid\n")); } }