int ReaDirArray(char *path) { struct find_t ff; char pattern[67]; struct DirEntry *base = &DirRoot; strcpy(pattern, path); if ('/' != LAST_CHAR(pattern) && '\\' != LAST_CHAR(pattern)) strcat(pattern, "\\"); strcat(pattern, "*.*"); if (SUCCESS == _dos_findfirst(pattern, 0xff, &ff)) do { struct DirEntry *node; if (NULL == (node = malloc(sizeof(struct DirEntry)))) return ERROR; base->next = node; strcpy(base->fname, ff.name); node->next = NULL; *node->fname = '\0'; base = node; } while (SUCCESS == _dos_findnext(&ff)); return SUCCESS; }
static int ReadLine(FILE *fp, char *line) { char *cp; cp = fgets(line, INI_LINESIZE, fp); if (NULL == cp) { *line = 0; return EOF; } if (feof(fp)) { *line = 0; return EOF; } if (0 != ferror(fp)) { *line = 0; return EOF; } /* ** Allow both DOS and Unix style newlines. */ while (strlen(line) && strchr("\n\r", LAST_CHAR(line))) LAST_CHAR(line) = NUL; return strlen(line); }
int main() { char* input; char* input_copy; char* input_copy_pointer; char* token; char* command[MAX_COMMAND_ARGUMENT_COUNT + 1]; /* +1 to hold the final NULL */ int status; int token_counter; pid_t child_pid; do { /* Print prompt */ printf("> "); /* Read input */ input = (char*)malloc(INPUT_BUFFER_MAX_SIZE); fgets(input, INPUT_BUFFER_MAX_SIZE, BUFFER_INPUT_FILE); input_copy = (char*)malloc(sizeof(input)); strcpy(input_copy, input); input_copy_pointer = input_copy; /* Use a separate pointer so we can free input_copy later */ if (LAST_CHAR(input_copy) == '\n') LAST_CHAR(input_copy) = '\0'; for (token_counter = 0; (token = strsep(&input_copy_pointer, " ")); token_counter++) { command[token_counter] = token; } command[token_counter] = NULL; /* Exit if EOF or "exit" command */ if (!*input || !strcmp(command[0], "exit")) exit(0); /* Handle cd */ if (!strcmp(command[0], "cd")) { chdir(command[1]); } /* Execute command */ child_pid = fork(); if (child_pid) { waitpid(child_pid, &status, 0); if (status) { printf("Non-zero exit status: %d\n", status); } } else { if (execvp(command[0], command)) { printf("Command not found: %s\n", command[0]); } break; } /* Free allocated memory */ free(input); free(input_copy); } while (*input); return 0; }
static char *StripTrailingSpaces(char *string) { if (!string || (0 == strlen(string))) return NULL; while (isspace(LAST_CHAR(string))) LAST_CHAR(string) = NUL; return string; }
long hexorint(const char *string) { int radix = 0; char *dummy, valstr[128]; strcpy(valstr, string); if (strchr("Hh", LAST_CHAR(valstr))) { LAST_CHAR(valstr) = NUL; radix = 16; } return strtol(valstr, &dummy, radix); }
main(int argc, char *argv[]) { FILE *infile = stdin, *outfile = stdout; char line[2][256]; /* Nice & roomy */ if (Error_ == getopts(argc, argv)) usage(-1); if (help) usage(0); if (1 < xargc) infile = cant(xargv[1], "r"); if (2 < xargc) outfile = cant(xargv[2], "w"); while (NULL != fgets(line[0], 255, infile)) { char *p1, *p2; int OK; strcpy(line[1], line[0]); if ('\n' == LAST_CHAR(line[1])) LAST_CHAR(line[1]) = NUL; if (fold) strupr(line[1]); if (punc) rmpunc(line[1]); for (p1 = line[1], p2 = &LAST_CHAR(line[1]), OK = 1; p2 > p1; ++p1, --p2) { if (*p1 != *p2) { OK = 0; break; } } if (OK) fputs(line[0], outfile); } return 0; }
void dump_args (struct obstack *obs, int argc, token_data **argv, const char *sep) { int i; for (i = 1; i < argc; i++) { if (i > 1 && sep) obstack_grow (obs, sep, strlen (sep)); obstack_1grow (obs, CHAR_BGROUP); /* Remove surrounding double quotes */ if (*ARG (i) == '"' && LAST_CHAR (ARG (i)) == '"') obstack_grow (obs, ARG (i) + 1, strlen (ARG (i)) - 2); else obstack_grow (obs, ARG (i), strlen (ARG (i))); obstack_1grow (obs, CHAR_EGROUP); } }
int main(int argc, char **argv) { int i; if (2 > argc) { puts("Usage: STUB filespec [...filespec]"); puts("where: filespec = fully-specified file name, or"); puts(" filespec = wildcard-specified file name, or"); puts(" filespec = response file name, e.g. \"@FILE.LST\""); return 1; } for (i = 1; i < argc; ++i) /* Scan for simple file specs */ { if ('@' == *argv[i]) continue; else truncate(argv[i]); } for (i = 1; i < argc; ++i) /* Scan for response file specs */ { if ('@' == *argv[i]) { FILE *fp; char buf[256], *ptr = &argv[i][1]; if (NULL == (fp = fopen(ptr, "r"))) { printf("\aSTUB: Error opening %s\n", ptr); return -1; } while (NULL != fgets(buf, 255, fp)) { LAST_CHAR(buf) = '\0'; /* Strip '\n' */ truncate(buf); } fclose(fp); } } return 0; }
int deliver_mailbox(LOCAL_STATE state, USER_ATTR usr_attr, int *statusp) { const char *myname = "deliver_mailbox"; const char *mailbox_res; const char *uid_res; const char *gid_res; DSN_BUF *why = state.msg_attr.why; long n; /* * Make verbose logging easier to understand. */ state.level++; if (msg_verbose) MSG_LOG_STATE(myname, state); /* * Sanity check. */ if (*var_virt_mailbox_base != '/') msg_fatal("do not specify relative pathname: %s = %s", VAR_VIRT_MAILBOX_BASE, var_virt_mailbox_base); /* * Look up the mailbox location. Bounce if not found, defer in case of * trouble. */ #define IGNORE_EXTENSION ((char **) 0) mailbox_res = mail_addr_find(virtual_mailbox_maps, state.msg_attr.user, IGNORE_EXTENSION); if (mailbox_res == 0) { if (virtual_mailbox_maps->error == 0) return (NO); msg_warn("table %s: lookup %s: %m", virtual_mailbox_maps->title, state.msg_attr.user); dsb_simple(why, "4.3.5", "mail system configuration error"); *statusp = defer_append(BOUNCE_FLAGS(state.request), BOUNCE_ATTR(state.msg_attr)); return (YES); } usr_attr.mailbox = concatenate(var_virt_mailbox_base, "/", mailbox_res, (char *) 0); #define RETURN(res) { myfree(usr_attr.mailbox); return (res); } /* * Look up the mailbox owner rights. Defer in case of trouble. */ uid_res = mail_addr_find(virtual_uid_maps, state.msg_attr.user, IGNORE_EXTENSION); if (uid_res == 0) { msg_warn("recipient %s: not found in %s", state.msg_attr.user, virtual_uid_maps->title); dsb_simple(why, "4.3.5", "mail system configuration error"); *statusp = defer_append(BOUNCE_FLAGS(state.request), BOUNCE_ATTR(state.msg_attr)); RETURN(YES); } if ((n = atol(uid_res)) < var_virt_minimum_uid) { msg_warn("recipient %s: bad uid %s in %s", state.msg_attr.user, uid_res, virtual_uid_maps->title); dsb_simple(why, "4.3.5", "mail system configuration error"); *statusp = defer_append(BOUNCE_FLAGS(state.request), BOUNCE_ATTR(state.msg_attr)); RETURN(YES); } usr_attr.uid = (uid_t) n; /* * Look up the mailbox group rights. Defer in case of trouble. */ gid_res = mail_addr_find(virtual_gid_maps, state.msg_attr.user, IGNORE_EXTENSION); if (gid_res == 0) { msg_warn("recipient %s: not found in %s", state.msg_attr.user, virtual_gid_maps->title); dsb_simple(why, "4.3.5", "mail system configuration error"); *statusp = defer_append(BOUNCE_FLAGS(state.request), BOUNCE_ATTR(state.msg_attr)); RETURN(YES); } if ((n = atol(gid_res)) <= 0) { msg_warn("recipient %s: bad gid %s in %s", state.msg_attr.user, gid_res, virtual_gid_maps->title); dsb_simple(why, "4.3.5", "mail system configuration error"); *statusp = defer_append(BOUNCE_FLAGS(state.request), BOUNCE_ATTR(state.msg_attr)); RETURN(YES); } usr_attr.gid = (gid_t) n; if (msg_verbose) msg_info("%s[%d]: set user_attr: %s, uid = %u, gid = %u", myname, state.level, usr_attr.mailbox, (unsigned) usr_attr.uid, (unsigned) usr_attr.gid); /* * Deliver to mailbox or to maildir. */ #define LAST_CHAR(s) (s[strlen(s) - 1]) if (LAST_CHAR(usr_attr.mailbox) == '/') *statusp = deliver_maildir(state, usr_attr); else *statusp = deliver_mailbox_file(state, usr_attr); /* * Cleanup. */ RETURN(YES); }
int deliver_mailbox(LOCAL_STATE state, USER_ATTR usr_attr, int *statusp) { const char *myname = "deliver_mailbox"; int status; struct mypasswd *mbox_pwd; char *path; static MAPS *transp_maps; const char *map_transport; static MAPS *cmd_maps; const char *map_command; /* * Make verbose logging easier to understand. */ state.level++; if (msg_verbose) MSG_LOG_STATE(myname, state); /* * DUPLICATE ELIMINATION * * Don't come here more than once, whether or not the recipient exists. */ if (been_here(state.dup_filter, "mailbox %s", state.msg_attr.local)) return (YES); /* * Delegate mailbox delivery to another message transport. */ if (*var_mbox_transp_maps && transp_maps == 0) transp_maps = maps_create(VAR_MBOX_TRANSP_MAPS, var_mbox_transp_maps, DICT_FLAG_LOCK | DICT_FLAG_NO_REGSUB); /* The -1 is a hint for the down-stream deliver_completed() function. */ if (transp_maps && (map_transport = maps_find(transp_maps, state.msg_attr.user, DICT_FLAG_NONE)) != 0) { state.msg_attr.rcpt.offset = -1L; *statusp = deliver_pass(MAIL_CLASS_PRIVATE, map_transport, state.request, &state.msg_attr.rcpt); return (YES); } else if (transp_maps && transp_maps->error != 0) { /* Details in the logfile. */ dsb_simple(state.msg_attr.why, "4.3.0", "table lookup failure"); *statusp = defer_append(BOUNCE_FLAGS(state.request), BOUNCE_ATTR(state.msg_attr)); return (YES); } if (*var_mailbox_transport) { state.msg_attr.rcpt.offset = -1L; *statusp = deliver_pass(MAIL_CLASS_PRIVATE, var_mailbox_transport, state.request, &state.msg_attr.rcpt); return (YES); } /* * Skip delivery when this recipient does not exist. */ if ((errno = mypwnam_err(state.msg_attr.user, &mbox_pwd)) != 0) { msg_warn("error looking up passwd info for %s: %m", state.msg_attr.user); dsb_simple(state.msg_attr.why, "4.0.0", "user lookup error"); *statusp = defer_append(BOUNCE_FLAGS(state.request), BOUNCE_ATTR(state.msg_attr)); return (YES); } if (mbox_pwd == 0) return (NO); /* * No early returns or we have a memory leak. */ /* * DELIVERY RIGHTS * * Use the rights of the recipient user. */ SET_USER_ATTR(usr_attr, mbox_pwd, state.level); /* * Deliver to mailbox, maildir or to external command. */ #define LAST_CHAR(s) (s[strlen(s) - 1]) if (*var_mailbox_cmd_maps && cmd_maps == 0) cmd_maps = maps_create(VAR_MAILBOX_CMD_MAPS, var_mailbox_cmd_maps, DICT_FLAG_LOCK | DICT_FLAG_PARANOID); if (cmd_maps && (map_command = maps_find(cmd_maps, state.msg_attr.user, DICT_FLAG_NONE)) != 0) { status = deliver_command(state, usr_attr, map_command); } else if (cmd_maps && cmd_maps->error != 0) { /* Details in the logfile. */ dsb_simple(state.msg_attr.why, "4.3.0", "table lookup failure"); status = defer_append(BOUNCE_FLAGS(state.request), BOUNCE_ATTR(state.msg_attr)); } else if (*var_mailbox_command) { status = deliver_command(state, usr_attr, var_mailbox_command); } else if (*var_home_mailbox && LAST_CHAR(var_home_mailbox) == '/') { path = concatenate(usr_attr.home, "/", var_home_mailbox, (char *) 0); status = deliver_maildir(state, usr_attr, path); myfree(path); } else if (*var_mail_spool_dir && LAST_CHAR(var_mail_spool_dir) == '/') { path = concatenate(var_mail_spool_dir, state.msg_attr.user, "/", (char *) 0); status = deliver_maildir(state, usr_attr, path); myfree(path); } else status = deliver_mailbox_file(state, usr_attr); /* * Cleanup. */ mypwfree(mbox_pwd); *statusp = status; return (YES); }
static void smspec_node_set_flags( smspec_node_type * smspec_node) { /* Check if this is a rate variabel - that info is used when interpolating results to true_time between ministeps. */ { const char *rate_vars[] = {"OPR" , "GPR" , "WPR" , "GOR" , "WCT"}; int num_rate_vars = sizeof( rate_vars ) / sizeof( rate_vars[0] ); bool is_rate = false; int ivar; for (ivar = 0; ivar < num_rate_vars; ivar++) { const char * var_substring = &smspec_node->keyword[1]; if (strncmp( rate_vars[ivar] , var_substring , strlen( rate_vars[ivar] )) == 0) { is_rate = true; break; } } smspec_node->rate_variable = is_rate; } { if (LAST_CHAR(smspec_node->keyword) == 'H') smspec_node->historical = true; } /* This code checks in a predefined list whether a certain WGNAMES variable represents a total accumulated quantity. Only the last three characters in the variable is considered (i.e. the leading 'W', 'G' or 'F' is discarded). The list below is all the keyowrds with 'Total' in the information from the tables 2.7 - 2.11 in the ECLIPSE fileformat documentation. Have skipped some of the most exotic keywords. */ { bool is_total = false; if (smspec_node->var_type == ECL_SMSPEC_WELL_VAR || smspec_node->var_type == ECL_SMSPEC_GROUP_VAR || smspec_node->var_type == ECL_SMSPEC_FIELD_VAR || smspec_node->var_type == ECL_SMSPEC_REGION_VAR || smspec_node->var_type == ECL_SMSPEC_COMPLETION_VAR ) { const char *total_vars[] = {"OPT" , "GPT" , "WPT" , "GIT", "WIT", "OPTF" , "OPTS" , "OIT" , "OVPT" , "OVIT" , "MWT" , "WVPT" , "WVIT" , "GMT" , "GPTF" , "SGT" , "GST" , "FGT" , "GCT" , "GIMT" , "WGPT" , "WGIT" , "EGT" , "EXGT" , "GVPT" , "GVIT" , "LPT" , "VPT" , "VIT" , "NPT" , "NIT"}; int num_total_vars = sizeof( total_vars ) / sizeof( total_vars[0] ); int ivar; for (ivar = 0; ivar < num_total_vars; ivar++) { const char * var_substring = &smspec_node->keyword[1]; /* We want to mark both FOPT and FOPTH as historical variables; we use strncmp() to make certain that the trailing 'H' is not included in the comparison. */ if (strncmp( total_vars[ivar] , var_substring , strlen( total_vars[ivar] )) == 0) { is_total = true; break; } } } smspec_node->total_variable = is_total; } }
DIR *opendir(char *fname) { int i; unsigned n = 0; char *p; DOSFileData dstruct; for (i = 0; i < _NDIRS; ++i) { if (!_DIRS[i].dd_fd) break; } if (_NDIRS <= i) { DFerr = ENOMEM; return NULL; } dos2unix(fname); if (':' == fname[1] && 1 < strlen(fname)) p = &fname[2]; else p = fname; while ('/' == LAST_CHAR(p) && 1 < strlen(p)) LAST_CHAR(p) = '\0'; if (strcmp(p, "/") && strlen(p)) { if (Success_ != (FIND_FIRST(fname, _A_ANY, &_DIRS[i].dd_buf))) { DFerr = ENOENT; return NULL; } if (!(_A_SUBDIR & _DIRS[i].dd_buf.attrib)) { DFerr = ENOTDIR; return NULL; } } strcpy(_DIRS[i].dd_dirname, fname); if (!strlen(p)) strcat(_DIRS[i].dd_dirname, "."); if ('/' != LAST_CHAR(_DIRS[i].dd_dirname)) strcat(_DIRS[i].dd_dirname, "/"); strcat(strupr(_DIRS[i].dd_dirname), "*.*"); if (Success_ != FIND_FIRST(_DIRS[i].dd_dirname, _A_ANY, &_DIRS[i].dd_buf)) { DFerr = ENOENT; return NULL; } memcpy(&dstruct, &_DIRS[i].dd_buf, sizeof(DOSFileData)); do { ++n; } while (Success_ == FIND_NEXT(&_DIRS[i].dd_buf)); memcpy(&_DIRS[i].dd_buf, &dstruct, sizeof(DOSFileData)); _DIRS[i].dd_size = n; _DIRS[i].dd_loc = 0; _DIRS[i].dd_fd = i + 1; DFerr = Success_; return &_DIRS[i]; }
char *fln_fix(char *path) { LOGICAL dir_flag = FALSE, root_flag = FALSE; char *r, *p, *q, *s; if (path) strupr(path); /* Ignore leading drive specs */ if (NULL == (r = strrchr(path, ':'))) r = path; else ++r; unix2dos(r); /* Convert Unix to DOS style */ while ('\\' == *r) /* Ignore leading backslashes */ { if ('\\' == r[1]) strcpy(r, &r[1]); else { root_flag = TRUE; ++r; } } p = r; /* Change "\\" to "\" */ while (NULL != (p = strchr(p, '\\'))) { if ('\\' == p[1]) strcpy(p, &p[1]); else ++p; } while ('.' == *r) /* Scrunch leading ".\" */ { if ('.' == r[1]) { /* Ignore leading ".." */ for (p = (r += 2); *p && (*p != '\\'); ++p) ; } else { for (p = r + 1 ;*p && (*p != '\\'); ++p) ; } strcpy(r, p + ((*p) ? 1 : 0)); } while ('\\' == LAST_CHAR(path)) /* Strip trailing backslash */ { dir_flag = TRUE; LAST_CHAR(path) = '\0'; } s = r; /* Look for "\." in path */ while (NULL != (p = strstr(s, "\\."))) { if ('.' == p[2]) { /* Execute this section if ".." found */ q = p - 1; while (q > r) /* Backup one level */ { if (*q == '\\') break; --q; } if (q > r) { strcpy(q, p + 3); s = q; } else if ('.' != *q) { strcpy(q + ((*q == '\\') ? 1 : 0), p + 3 + ((*(p + 3)) ? 1 : 0)); s = q; } else s = ++p; } else { /* Execute this section if "." found */ q = p + 2; for ( ;*q && (*q != '\\'); ++q) ; strcpy (p, q); } } if (root_flag) /* Embedded ".." could have bubbled up to root */ { for (p = r; *p && ('.' == *p || '\\' == *p); ++p) ; if (r != p) strcpy(r, p); } if (dir_flag) strcat(path, "\\"); return path; }
extern char *rmail_mdir_lookup(const char *name) { const char *myname = "rmail_mdir_lookup"; char *username, *domain, *mhost, *mbox, *basedir; int domain_idx; int mailcache_hitted=0; struct passwd *pw; char sql[512]; MYSQL_RES *res; MYSQL_ROW row; char *result; username = (char *) malloc (sizeof(char *) * strlen(name)); username = strdup(name); if ((domain = strrchr(username, '@')) == 0) { // no @ domain_idx = 1; sprintf(sql, "SELECT %s, %s FROM %s WHERE %s=%d", var_rmail_transport_basedirfield, var_rmail_transport_domainfield, var_rmail_transport_table, var_rmail_transport_idxfield, domain_idx); if (msg_debug) msg_info("%s: SQL[MTA] => %s", myname, sql); if (mysql_real_query(&mta_dbh, sql, strlen(sql)) != 0) { msg_warn("%s: MTA Database query fail: %s", myname, mysql_error(&mta_dbh)); free(username); return 0; } res = mysql_store_result(&mta_dbh); if (mysql_num_rows(res) != 1) { msg_warn("%s: No default domain but want to deliver(%s)", myname, username); domain = strdup(var_mydomain); basedir = strdup(var_rmail_default_basedir); } else { row = mysql_fetch_row(res); basedir = strdup(row[0]); domain = strdup(row[1]); } mysql_free_result(res); } else { username[strlen(username)-strlen(domain)]='\0'; domain++; sprintf(sql, "SELECT %s, %s FROM %s WHERE %s='%s'", var_rmail_transport_basedirfield, var_rmail_transport_idxfield, var_rmail_transport_table, var_rmail_transport_domainfield, domain); if (msg_debug) msg_info("%s: SQL[MTA] => %s", myname, sql); if (mysql_real_query(&mta_dbh, sql, strlen(sql)) != 0) { msg_warn("%s: MTA Database query fail: %s", myname, mysql_error(&mta_dbh)); free(username); return 0; } res = mysql_store_result(&mta_dbh); if (mysql_num_rows(res) != 1) { msg_warn("%s: No such domain but want to deliver(%s)", myname, domain); basedir = strdup(var_rmail_default_basedir); domain_idx = 1; } else { row = mysql_fetch_row(res); basedir = strdup(row[0]); domain_idx = atoi(row[1]); mysql_free_result(res); } } if (msg_debug) msg_info("%s: Get domain_idx=%d, basedir=%s", myname, domain_idx, basedir); /* Find mailuser/mailcache first */ if (var_rmail_mailcache_enable) { sprintf(sql, "SELECT %s, %s, UNIX_TIMESTAMP(%s) FROM %s WHERE %s='%s' AND %s='%d'", var_rmail_mailcache_mhostfield, var_rmail_mailcache_mboxfield, var_rmail_mailcache_timefield, var_rmail_mailcache_table, var_rmail_mailcache_mailidfield, username, var_rmail_mailcache_domainfield, domain_idx); if (msg_debug) msg_info("%s: SQL[CAC] => %s", myname, sql); if (mysql_real_query(&cac_dbh, sql, strlen(sql))!=0) { // query fail msg_warn("%s: CAC Database query fail: %s", myname, mysql_error(&cac_dbh)); mailcache_hitted = 0; } else { res = mysql_store_result(&cac_dbh); if (mysql_num_rows(res)!=1) { // no cache hitted mailcache_hitted = 0; } else { // check if expire row = mysql_fetch_row(res); if (atoi(row[2]) + var_rmail_mailcache_expire < time(NULL)) { // cache expire, delete it sprintf(sql, "DELETE FROM %s WHERE %s='%s' AND %s=%d", var_rmail_mailcache_table, var_rmail_mailcache_mailidfield, username, var_rmail_mailcache_domainfield, domain_idx); if (msg_debug) msg_info("%s: SQL[CAC] => %s", myname, sql); if (mysql_real_query(&cac_dbh, sql, strlen(sql))!=0) msg_warn("%s: CAC Database query fail: %s", myname, mysql_error(&cac_dbh)); mailcache_hitted = 0; } else { mhost = strdup(row[0]); mbox = strdup(row[1]); mailcache_hitted = 1; } } mysql_free_result(res); } } else mailcache_hitted = 0; // mailcache disable or no cache hitted if (!mailcache_hitted) { sprintf(sql, "SELECT %s, %s, %s, %s, %s, %s FROM %s WHERE %s='%s' AND %s=%d", var_rmail_mailuser_mhostfield, var_rmail_mailuser_mboxfield, var_rmail_mailuser_statufield, var_rmail_mailuser_smtpfield, var_rmail_mailuser_pop3field, var_rmail_mailuser_webfield, var_rmail_mailuser_table, var_rmail_mailuser_mailidfield, username, var_rmail_mailuser_domainfield, domain_idx); if (msg_debug) msg_info("%s: SQL[MTA] => %s", myname, sql); if (mysql_real_query(&mta_dbh, sql, strlen(sql))!=0) { msg_warn("%s: MTA Database query fail(%s)", myname, mysql_error(&mta_dbh)); free(username); return 0; } res = mysql_store_result(&mta_dbh); if (mysql_num_rows(res)!=1) { msg_warn("%s: No such user but want to deliver(%s)", myname, username); free(username); return 0; } row = mysql_fetch_row(res); mhost = strdup(row[0]); mbox = strdup(row[1]); mailcache_hitted = 1; if (var_rmail_mailcache_enable) { sprintf(sql, "INSERT INTO %s SET %s='%s', %s=%d, %s='%s', %s='%s', %s=%d, %s=NOW(), %s=%d, %s=%d, %s=%d", var_rmail_mailcache_table, var_rmail_mailcache_mailidfield, username, var_rmail_mailcache_domainfield, domain_idx, var_rmail_mailcache_mhostfield, mhost, var_rmail_mailcache_mboxfield, row[1], var_rmail_mailcache_statufield, atoi(row[2]), var_rmail_mailcache_timefield, var_rmail_mailcache_smtpfield, atoi(row[3]), var_rmail_mailcache_pop3field, atoi(row[4]), var_rmail_mailcache_webfield, atoi(row[5])); if (msg_debug) msg_info("%s: SQL[CAC] => %s", myname, sql); if (mysql_real_query(&cac_dbh, sql, strlen(sql))!=0) msg_warn("%s: CAC Database query fail(%s)", myname, mysql_error(&cac_dbh)); } mysql_free_result(res); } if (!mailcache_hitted) { // no any record? check unix local account pw = getpwnam(username); if (pw && var_rmail_allow_local) { // enable local account result = concatenate(pw->pw_dir, "/", (char *) 0); free(username); return result; } else { msg_warn("%s: Not allow unix local account but want to deliver(%s)", myname, username); free(username); return 0; } } #define LAST_CHAR(s) (s[strlen(s) - 1]) if (LAST_CHAR(mbox) != '/') result = concatenate(basedir, "/", mhost, "/", mbox, (char *) 0); else result = concatenate(basedir, "/", mhost, "/", mbox, "/", (char *) 0); free(username); return result; }
DOS_DIR *opendir(char *fname) { int i; unsigned n = 0; char nametmp[13], *p; struct DSTRUCT dstruct; for (i = 0; i < _NDIRS; ++i) { if (!_DIRS[i].dd_fd) break; } if (_NDIRS <= i) { DFerr = ENOMEM; return NULL; } unix2dos(fname); if (':' == fname[1] && 1 < strlen(fname)) p = &fname[2]; else p = fname; while ('\\' == LAST_CHAR(p) && 1 < strlen(p)) LAST_CHAR(p) = '\0'; if (strcmp(p, "\\") && strlen(p)) { if (NULL == (rfind_1st(fname, FA_ANY, &_DIRS[i].dd_buf))) { DFerr = ENOENT; return NULL; } if (!(FA_DIREC & _DIRS[i].dd_buf.ATTRIBUTE)) { DFerr = ENOTDIR; return NULL; } } strcpy(_DIRS[i].dd_dirname, fname); if (!strlen(p)) strcat(_DIRS[i].dd_dirname, "."); if ('\\' != LAST_CHAR(_DIRS[i].dd_dirname)) strcat(_DIRS[i].dd_dirname, "\\"); strcat(strupr(_DIRS[i].dd_dirname), "*.*"); if (NULL == rfind_1st(_DIRS[i].dd_dirname, FA_ANY, &_DIRS[i].dd_buf)) { DFerr = ENOENT; return NULL; } memcpy(&dstruct, &_DIRS[i].dd_buf, sizeof(struct DSTRUCT)); do { ++n; } while (rfind_nxt(&_DIRS[i].dd_buf)); memcpy(&_DIRS[i].dd_buf, &dstruct, sizeof(struct DSTRUCT)); _DIRS[i].dd_size = n; _DIRS[i].dd_loc = 0; _DIRS[i].dd_fd = i + 1; DFerr = SUCCESS; return &_DIRS[i]; }
int main (int argc, char *argv[]) { FILE *fp = NULL; char *buf = NULL, *getbuf(void); fpos_t rpos; int i, patterns, max_bytes = 0; LOGICAL hex2char(const char *, char *); if (2 > argc) /* no filename */ return 1; if (3 > argc) /* no argument */ return 2; if (NULL == (fp = fopen(argv[1], "r+b"))) return 3; /* file open error */ if (NULL == (buf = getbuf())) return 4; /* no memory for buffer */ patterns = argc - 2; /* process arguments */ for (i = 2; i < argc; ++i) { char *p, *ptr; if (NULL != (ptr = strtok(argv[i], ","))) { p = search[i - 2].pattern; do { search[i - 2].numbytes++; if (1 == strlen(ptr)) { *p++ = *ptr; continue; } switch (toupper(LAST_CHAR(ptr))) { case 'D': LAST_CHAR(ptr) = '\0'; *p++ = (char)atoi(ptr); break; case 'H': LAST_CHAR(ptr) = '\0'; if (ERROR == hex2char(ptr, p++)) return 5; break; default: return 5; } } while (NULL != (ptr = strtok(NULL, ","))); *p = '\0'; max_bytes = max(max_bytes, search[i - 2].numbytes); } else return 5; } fgetpos(fp, &rpos); /* save where we are */ while (1) { int bytes, n; LOGICAL modified; if (max_bytes > (bytes = (int)fread(buf, 1, bufsize, fp))) { if (0 == bytes && !feof(fp)) return 6; /* something's wrong! */ else break; /* all done! */ } for (n = 0, modified = FALSE; n < patterns; ++n) { /* check each pattern in turn */ for (i = 0; i < (bytes - max_bytes + 1); ++i) { int j; if (buf[i] != *(search[n].pattern)) continue; if (SUCCESS != strncmp(&buf[i], search[n].pattern, search[n].numbytes)) { continue; } /* found one! replace it in the buffer */ for (j = 0; j < search[n].numbytes; ++j, ++i) buf[i] = '\0'; modified = TRUE; } } if (modified) /* write changes, if any*/ { fpos_t wpos = rpos; fsetpos(fp, &wpos); if (bytes != (int)fwrite(buf, 1, bytes, fp)) return 7; fsetpos(fp, &rpos); } rpos += bytes - max_bytes + 1; /* get another buffer */ fsetpos(fp, &rpos); } fclose(fp); return SUCCESS; }
static void init_c(statedes *st, bindes *bd) {int i; char fn[BFLRG], upck[BFLRG], s[BFMG]; char *p, **el, **sl, **ul, **hl; const char *pck; FILE *fc, *fh, *fp; cmeta *cm; pck = st->pck; snprintf(upck, BFLRG, pck, -1); upcase(upck); /* make the C metadata from the derivedc file */ hl = NULL; el = NULL; sl = NULL; ul = NULL; fp = open_file("r", "%s.derivedc", pck); if (fp != NULL) {for (i = 0; TRUE; i++) {p = fgets(s, BFMG, fp); if (p == NULL) break; LAST_CHAR(p) = '\0'; if (blank_line(p) == TRUE) continue; else if (strncmp(p, "include = ", 10) == 0) hl = tokenize(p+10, " \t", 0); else if (strncmp(p, "enum e_", 7) == 0) el = lst_add(el, p); else if (strncmp(p, "struct s_", 9) == 0) sl = lst_add(sl, p); else if (strncmp(p, "union u_", 8) == 0) ul = lst_add(ul, p);}; el = lst_add(el, NULL); sl = lst_add(sl, NULL); ul = lst_add(ul, NULL); fclose(fp);}; cm = MAKE(cmeta); cm->hdrs = hl; cm->enums = el; cm->structs = sl; cm->unions = ul; bd->data = cm; /* open C file */ if ((st->path == NULL) || (strcmp(st->path, ".") == 0)) snprintf(fn, BFLRG, "gc-%s.c", pck); else snprintf(fn, BFLRG, "%s/gc-%s.c", st->path, pck); fc = open_file("w", fn); bd->fp[0] = fc; fprintf(fc, "/*\n"); fprintf(fc, " * GC-%s.C - support routines for %s\n", upck, upck); fprintf(fc, " * NOTE: this file was automatically generated by blang\n"); fprintf(fc, " * any manual changes will not be effective\n"); fprintf(fc, " *\n"); fprintf(fc, " */\n"); fprintf(fc, "\n"); fprintf(fc, "#include \"cpyright.h\"\n"); if (hl != NULL) {for (i = 0; hl[i] != NULL; i++) fprintf(fc, "#include \"%s\"\n", hl[i]);}; /* fprintf(fc, "#include \"%s_int.h\"\n", pck); */ fprintf(fc, "#include \"%s_gen.h\"\n", pck); fprintf(fc, "\n"); /* open header file */ if ((st->path == NULL) || (strcmp(st->path, ".") == 0)) snprintf(fn, BFLRG, "gc-%s.h", pck); else snprintf(fn, BFLRG, "%s/gc-%s.h", st->path, pck); fh = open_file("w", fn); bd->fp[1] = fh; fprintf(fh, "/*\n"); fprintf(fh, " * GC-%s.H - header containing support for %s\n", upck, upck); fprintf(fh, " * NOTE: this file was automatically generated by blang\n"); fprintf(fh, " * any manual changes will not be effective\n"); fprintf(fh, " *\n"); fprintf(fh, " */\n"); fprintf(fh, "\n"); fprintf(fh, "#include \"cpyright.h\"\n"); fprintf(fh, "\n"); fprintf(fh, "#ifndef GEN_%s_H\n", upck); fprintf(fh, "#define GEN_%s_H\n", upck); fprintf(fh, "\n"); return;}