int GSI_SOCKET_credentials_accept_ext(GSI_SOCKET *self, char *credentials, int credentials_len) { int return_value = GSI_SOCKET_ERROR; SSL_CREDENTIALS *creds = NULL; SSL_PROXY_RESTRICTIONS *proxy_restrictions = NULL; unsigned char *input_buffer = NULL; size_t input_buffer_length; unsigned char *fmsg; int i; char *filename = NULL; char *certstart; int rval, fd = 0; int size; if (self == NULL) { goto error; } if (self->gss_context == GSS_C_NO_CONTEXT) { GSI_SOCKET_set_error_string(self, "GSI_SOCKET not authenticated"); goto error; } /* Read the Cred sent from the client. */ if (GSI_SOCKET_read_token(self, &input_buffer, &input_buffer_length) == GSI_SOCKET_ERROR) { goto error; } myproxy_debug( "Read credentials" ); /* MAJOR HACK: We don't have application-level framing in our protocol. We can't separate the certificate chain easily from the final protocol message, so just discard it. */ fmsg = input_buffer; for (i=0; i < input_buffer_length-strlen("VERSION"); i++, fmsg++) { if (strncmp((const char *)fmsg, "VERSION", strlen("VERSION")) == 0) { input_buffer_length = fmsg-input_buffer; break; } } /* Now store the credentials */ filename = myproxy_creds_path_template(); if (filename == NULL) { /* should never happen */ verror_put_string("myproxy_creds_path_template() failed"); goto error; } fd = mkstemp(filename); if (fd == -1) { verror_put_string("Error creating temporary file (%s)", filename); verror_put_errno(errno); goto error; } size = strlen( (char *)input_buffer ); certstart = (char *)input_buffer; while (size) { if ((rval = write(fd, certstart, size)) < 0) { perror("write"); goto error; } size -= rval; certstart += rval; } if (write(fd, "\n\0", 1) < 0) { perror("write"); goto error; } if (my_strncpy(credentials, filename, credentials_len) < 0) { verror_put_string("credential path too long"); goto error; } /* Success */ return_value = GSI_SOCKET_SUCCESS; error: if (input_buffer != NULL) { GSI_SOCKET_free_token(input_buffer); } if (creds != NULL) { ssl_credentials_destroy(creds); } if (proxy_restrictions != NULL) { ssl_proxy_restrictions_destroy(proxy_restrictions); } if( fd >= 0) { close( fd ); } if (return_value != GSI_SOCKET_SUCCESS && fd >= 0) { ssl_proxy_file_destroy(filename); } if (filename) free(filename); return return_value; }
/*########################### show_job_list() ###########################*/ void show_job_list(FILE *p_data) { int fd; char fullname[MAX_PATH_LENGTH]; (void)snprintf(fullname, MAX_PATH_LENGTH, "%s%s%s", p_work_dir, FIFO_DIR, JOB_ID_DATA_FILE); if ((fd = open(fullname, O_RDONLY)) == -1) { system_log(ERROR_SIGN, __FILE__, __LINE__, _("Failed to open() `%s' : %s"), fullname, strerror(errno)); } else { struct stat stat_buf; if (fstat(fd, &stat_buf) == -1) { system_log(ERROR_SIGN, __FILE__, __LINE__, _("Failed to fstat() `%s' : %s"), fullname, strerror(errno)); } else { if (stat_buf.st_size > AFD_WORD_OFFSET) { off_t job_id_db_size; char *ptr; #ifdef HAVE_MMAP job_id_db_size = stat_buf.st_size; if ((ptr = mmap(NULL, stat_buf.st_size, PROT_READ, MAP_SHARED, fd, 0)) == (caddr_t)-1) #else if ((ptr = mmap_emu(NULL, stat_buf.st_size, PROT_READ, MAP_SHARED, fullname, 0)) == (caddr_t)-1) #endif { system_log(ERROR_SIGN, __FILE__, __LINE__, _("Failed to mmap() to `%s' : %s"), fullname, strerror(errno)); } else { int cml_fd, no_of_job_ids; struct job_id_data *jd; no_of_job_ids = *(int *)ptr; ptr += AFD_WORD_OFFSET; jd = (struct job_id_data *)ptr; (void)snprintf(fullname, MAX_PATH_LENGTH, "%s%s%s", p_work_dir, FIFO_DIR, CURRENT_MSG_LIST_FILE); if ((cml_fd = open(fullname, O_RDONLY)) == -1) { system_log(ERROR_SIGN, __FILE__, __LINE__, _("Failed to open() `%s' : %s"), fullname, strerror(errno)); } else { if (fstat(cml_fd, &stat_buf) == -1) { system_log(ERROR_SIGN, __FILE__, __LINE__, _("Failed to fstat() `%s' : %s"), fullname, strerror(errno)); } else { if (stat_buf.st_size > sizeof(int)) { #ifdef HAVE_MMAP if ((ptr = mmap(NULL, stat_buf.st_size, PROT_READ, MAP_SHARED, cml_fd, 0)) == (caddr_t)-1) #else if ((ptr = mmap_emu(NULL, stat_buf.st_size, PROT_READ, MAP_SHARED, fullname, 0)) == (caddr_t)-1) #endif { system_log(ERROR_SIGN, __FILE__, __LINE__, _("Failed to mmap() to `%s' : %s"), fullname, strerror(errno)); } else { int no_of_current_jobs; no_of_current_jobs = *(int *)ptr; if ((no_of_current_jobs > 0) && (no_of_job_ids > 0)) { int gotcha, i, j; char *cjn; /* Current Job Number. */ #ifndef WITHOUT_BLUR_DATA int offset, m; unsigned char buffer[3 + MAX_INT_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + 2 + MAX_RECIPIENT_LENGTH + 2]; #endif cjn = ptr + sizeof(int); (void)fprintf(p_data, "211- AFD current job list:\r\n"); (void)fflush(p_data); (void)fprintf(p_data, "NJ %d\r\n", no_of_current_jobs); (void)fflush(p_data); for (i = 0; i < no_of_current_jobs; i++) { gotcha = NO; for (j = 0; j < no_of_job_ids; j++) { if (*(int *)cjn == jd[j].job_id) { #ifdef WITHOUT_BLUR_DATA (void)fprintf(p_data, "JL %d %x %x %x %c %s\r\n", i, jd[j].job_id, jd[j].dir_id, jd[j].no_of_loptions, jd[j].priority, jd[j].recipient); #else m = snprintf((char *)buffer, 3 + MAX_INT_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + 2 + MAX_RECIPIENT_LENGTH + 2, "Jl %d %x %x %x %c ", i, jd[j].job_id, jd[j].dir_id, jd[j].no_of_loptions, jd[j].priority); if (m > (3 + MAX_INT_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + 2 + MAX_RECIPIENT_LENGTH + 2)) { system_log(WARN_SIGN, __FILE__, __LINE__, "Buffer to small (%d > %d).", m, 3 + MAX_INT_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + 2 + MAX_RECIPIENT_LENGTH + 2); m = 3 + MAX_INT_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + 2 + MAX_RECIPIENT_LENGTH + 2; } else { (void)my_strncpy((char *)&buffer[m], jd[j].recipient, MAX_RECIPIENT_LENGTH + 1); } offset = m; while (buffer[m] != '\0') { if ((m - offset) > 28) { offset += 28; } if (((m - offset) % 3) == 0) { buffer[m] = buffer[m] - 9 + (m - offset); } else { buffer[m] = buffer[m] - 17 + (m - offset); } m++; } buffer[m] = '\r'; buffer[m + 1] = '\n'; if (fwrite(buffer, 1, m + 2, p_data) != (m + 2)) { system_log(ERROR_SIGN, __FILE__, __LINE__, _("fwrite() error : %s"), strerror(errno)); } #endif j = no_of_job_ids; gotcha = YES; } } if (gotcha == NO) { #ifdef WITHOUT_BLUR_DATA (void)fprintf(p_data, "JL %d 0 0 none 0 0\r\n", i); #else m = snprintf((char *)buffer, 3 + MAX_INT_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + 2 + MAX_RECIPIENT_LENGTH + 2, "Jl %d 0 0 0 0 none\r\n", i); if (m > (3 + MAX_INT_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + 2 + MAX_RECIPIENT_LENGTH + 2)) { system_log(WARN_SIGN, __FILE__, __LINE__, "Buffer to small (%d > %d).", m, 3 + MAX_INT_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + 2 + MAX_RECIPIENT_LENGTH + 2); m = 3 + MAX_INT_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + MAX_INT_HEX_LENGTH + 2 + MAX_RECIPIENT_LENGTH + 2; } else { (void)my_strncpy((char *)&buffer[m], jd[j].recipient, MAX_RECIPIENT_LENGTH + 1); } offset = m; while (buffer[m] != '\0') { if ((m - offset) > 28) { offset += 28; } if (((m - offset) % 3) == 0) { buffer[m] = buffer[m] - 9 + (m - offset); } else { buffer[m] = buffer[m] - 17 + (m - offset); } m++; } buffer[m] = '\r'; buffer[m + 1] = '\n'; if (fwrite(buffer, 1, m + 2, p_data) != (m + 2)) { system_log(ERROR_SIGN, __FILE__, __LINE__, _("fwrite() error : %s"), strerror(errno)); } #endif } (void)fflush(p_data); cjn += sizeof(int); } } else { (void)fprintf(p_data, "211- AFD current job list:\r\n"); (void)fflush(p_data); (void)fprintf(p_data, "NJ 0\r\n"); (void)fflush(p_data); } #ifdef HAVE_MMAP if (munmap(ptr, stat_buf.st_size) == -1) #else if (munmap_emu(ptr) == -1) #endif { system_log(WARN_SIGN, __FILE__, __LINE__, _("Failed to munmap() `%s' : %s"), fullname, strerror(errno)); } } } } if (close(cml_fd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, _("close() error : %s"), strerror(errno)); } } #ifdef HAVE_MMAP if (munmap(((char *)jd - AFD_WORD_OFFSET), job_id_db_size) == -1) #else if (munmap_emu((void *)((char *)jd - AFD_WORD_OFFSET)) == -1) #endif { (void)snprintf(fullname, MAX_PATH_LENGTH, "%s%s%s", p_work_dir, FIFO_DIR, JOB_ID_DATA_FILE); system_log(WARN_SIGN, __FILE__, __LINE__, _("Failed to munmap() `%s' : %s"), fullname, strerror(errno)); } } } else { (void)snprintf(fullname, MAX_PATH_LENGTH, "%s%s%s", p_work_dir, FIFO_DIR, JOB_ID_DATA_FILE); system_log(DEBUG_SIGN, __FILE__, __LINE__, _("Hmmm, `%s' is less then %d bytes long."), fullname, AFD_WORD_OFFSET); } } if (close(fd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, _("close() error : %s"), strerror(errno)); } } return; }
int GSI_SOCKET_delegation_accept_ext(GSI_SOCKET *self, char *delegated_credentials, int delegated_credentials_len, char *passphrase) { int return_value = GSI_SOCKET_ERROR; unsigned char *output_buffer = NULL; int output_buffer_len; char *filename = NULL; int fd = -1; if (GSI_SOCKET_delegation_accept(self, &output_buffer, &output_buffer_len, passphrase) != GSI_SOCKET_SUCCESS) { goto error; } /* Now store the credentials */ filename = myproxy_creds_path_template(); if (filename == NULL) { /* should never happen */ verror_put_string("myproxy_creds_path_template() failed"); goto error; } fd = mkstemp(filename); if (fd == -1) { verror_put_string("Error creating temporary file (%s)", filename); verror_put_errno(errno); goto error; } if (write(fd, output_buffer, output_buffer_len) == -1) { verror_put_errno(errno); verror_put_string("Error writing proxy to %s", filename); goto error; } if (delegated_credentials != NULL) { if (my_strncpy(delegated_credentials, filename, delegated_credentials_len) < 0) { verror_put_string("credential path too long"); goto error; } } /* Success */ return_value = GSI_SOCKET_SUCCESS; error: if (output_buffer != NULL) { ssl_free_buffer(output_buffer); } if (fd >= 0) close(fd); if (return_value != GSI_SOCKET_SUCCESS && fd >= 0) { ssl_proxy_file_destroy(filename); } if (filename) free(filename); return return_value; }
/* * @func parse_args() * @desc parse command line parameters */ int parse_args(int argc, char **argv, conf_t *conf) { const char *conf_file = NULL; bzero(conf, sizeof(conf_t)); for (int i = 1; i < argc; i++) { if ((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)) { help(); return -1; } else if ((strcmp(argv[i], "-c") == 0) || (strcmp(argv[i], "--config") == 0)) { if (i + 2 > argc) { fprintf(stderr, "missing filename after '%s'\n", argv[i]); return 1; } conf_file = argv[i + 1]; i++; } else if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--daemon") == 0)) { conf->daemon = 1; } else if (strcmp(argv[i], "--pidfile") == 0) { if (i + 2 > argc) { fprintf(stderr, "missing filename after '%s'\n", argv[i]); return 1; } my_strncpy(conf->pidfile, argv[i + 1]); i++; } else if (strcmp(argv[i], "--logfile") == 0) { if (i + 2 > argc) { fprintf(stderr, "missing filename after '%s'\n", argv[i]); return 1; } my_strncpy(conf->logfile, argv[i + 1]); i++; } else if ((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--verbose") == 0)) { conf->verbose = 1; } else if ((strcmp(argv[i], "-V") == 0) || (strcmp(argv[i], "--version") == 0)) { printf("%s %s\n", PACKAGE, VERSION); return -1; } else { fprintf(stderr, "invalid option: %s\n", argv[i]); return -1; } } if (conf_file != NULL) { if (read_conf(conf_file, conf) != 0) { return -1; } } if (conf->pidfile[0] == '\0') { strcpy(conf->pidfile, "/run/sans.pid"); } if (conf->logfile[0] == '\0') { strcpy(conf->logfile, "/var/log/sans.log"); } if (conf->listen.addr[0] == '\0') { strcpy(conf->listen.addr, "127.0.0.1"); } if (conf->listen.port[0] == '\0') { strcpy(conf->listen.port, "53"); } if (conf->test_server.addr[0] == '\0') { strcpy(conf->test_server.addr, "8.8.8.8"); } if (conf->test_server.port[0] == '\0') { strcpy(conf->test_server.port, "53"); } if (conf->cn_server.addr[0] == '\0') { strcpy(conf->cn_server.addr, "114.114.114.114"); } if (conf->cn_server.port[0] == '\0') { strcpy(conf->cn_server.port, "53"); } if (conf->server.addr[0] == '\0') { strcpy(conf->server.addr, "8.8.4.4"); } if (conf->server.port[0] == '\0') { strcpy(conf->server.port, "53"); } return 0; }
/* * @func read_conf() * @desc read config file */ static int read_conf(const char *file, conf_t *conf) { FILE *f = fopen(file, "rb"); if (f == NULL) { fprintf(stderr, "failed to open config file\n"); return -1; } int line_num = 0; char buf[LINE_MAX]; while (!feof(f)) { char *line = fgets(buf, LINE_MAX, f); if (line == NULL) { break; } line_num++; // 跳过行首空白符 while (isspace(*line)) { line++; } // 去除行尾的空白符 char *end = line + strlen(line) - 1; while ((end >= line) && (isspace(*end))) { *end = '\0'; end--; } // 跳过注释和空白行 if ((*line == '#') || (*line == '\0')) { continue; } // 开始解析 char *p = strchr(line, '='); if (p == NULL) { fprintf(stderr, "parse config file failed at line: %d\n", line_num); fclose(f); return -1; } *p = '\0'; char *key = line; char *value = p + 1; if (strcmp(key, "user") == 0) { my_strncpy(conf->user, value); } else if (strcmp(key, "listen") == 0) { p = strrchr(value, ':'); if (p == NULL) { fprintf(stderr, "parse config file failed at line: %d\n", line_num); fclose(f); return -1; } *p = '\0'; my_strncpy(conf->listen.addr, value); my_strncpy(conf->listen.port, p + 1); } else if (strcmp(key, "test_server") == 0) { p = strrchr(value, ':'); if (p == NULL) { fprintf(stderr, "parse config file failed at line: %d\n", line_num); fclose(f); return -1; } *p = '\0'; my_strncpy(conf->test_server.addr, value); my_strncpy(conf->test_server.port, p + 1); } else if (strcmp(key, "cn_server") == 0) { p = strrchr(value, ':'); if (p == NULL) { fprintf(stderr, "parse config file failed at line: %d\n", line_num); fclose(f); return -1; } *p = '\0'; my_strncpy(conf->cn_server.addr, value); my_strncpy(conf->cn_server.port, p + 1); } else if (strcmp(key, "server") == 0) { p = strrchr(value, ':'); if (p == NULL) { fprintf(stderr, "parse config file failed at line: %d\n", line_num); fclose(f); return -1; } *p = '\0'; my_strncpy(conf->server.addr, value); my_strncpy(conf->server.port, p + 1); } else if (strcmp(key, "socks5") == 0) { p = strrchr(value, ':'); if (p == NULL) { fprintf(stderr, "parse config file failed at line: %d\n", line_num); fclose(f); return -1; } *p = '\0'; my_strncpy(conf->socks5.addr, value); my_strncpy(conf->socks5.port, p + 1); } } fclose(f); return 0; }
int main(int argc, char *argv[]) { // if(testme()) // return 0; if (argc == 2 && (strcmp(argv[0], "-h") == 0 || strcmp(argv[0], "--help") == 0)) { printUsage(argv[0]); return EXIT_SUCCESS; } if (argc != 3) { printUsage(argv[0]); return EXIT_FAILURE; } FILE * f; if ((f = fopen(argv[2], "r")) == NULL) { printf("Unable to open file '%s', aborting!\n", argv[2]); return EXIT_FAILURE; } FILE * fptrout = stdout; int line_count = 0; char line_buffer[LINE_SIZE]; while (fgets(line_buffer, LINE_SIZE, f) != NULL) { line_count++; } int file_length = ftell(f); rewind(f); char * * src = malloc(sizeof(char *) * line_count); char * * copy = malloc(sizeof(char *) * line_count); int i; for (i = 0; i < line_count; i++) { if (feof(f)) { printf("Not enough lines in file!\n"); fclose(f); return EXIT_FAILURE; } copy[i] = malloc(sizeof(char) * LINE_SIZE); fgets(copy[i], LINE_SIZE, f); trim(copy[i]); src[i] = strdup(copy[i]); } fclose(f); char * buffer = malloc(sizeof(char) * file_length); buffer[0] = '\0'; //Partitioning outputs const char * command = argv[1]; if (strcmp(command, "my_strlen") == 0) { for (i = 0; i < line_count; i++) { fprintf(fptrout, "length: %d\n", my_strlen(copy[i])); } } else if (strcmp(command, "my_countchar") == 0) { for (i = 0; i < line_count; i++) { fprintf(fptrout, "count(%c): %d\n", copy[i][0], my_countchar(copy[i], copy[i][0])); } } else if (strcmp(command, "my_strupper") == 0) { for (i = 0; i < line_count; i++) { my_strupper(copy[i]); fprintf(fptrout, "uppercase: %s\n", copy[i]); } } else if (strcmp(command, "my_strlower") == 0) { for (i = 0; i < line_count; i++) { my_strlower(copy[i]); fprintf(fptrout, "lowercase: %s\n", copy[i]); } } else if (strcmp(command, "my_strcat") == 0) { for (i = 0; i < line_count; i++) { my_strcat(copy[i], " "); my_strcat(copy[i], src[i]); fprintf(fptrout, "%s\n", copy[i]); } } else if (strcmp(command, "my_strncat") == 0) { for (i = 0; i < line_count; i++) { my_strncat(copy[i], " ", 2); my_strncat(copy[i], "........", 1); fprintf(fptrout, "%s\n", copy[i]); } } else if (strcmp(command, "my_strcpy") == 0) { for (i = 0; i < line_count; i++) { my_strcpy(copy[i], "Copying this String."); fprintf(fptrout, "%s\n", copy[i]); } } else if (strcmp(command, "my_strncpy") == 0) { for (i = 0; i < line_count; i++) { my_strncpy(copy[i], src[i], 5); fprintf(fptrout, "%s\n", copy[i]); } } else if (strcmp(command, "my_strstr") == 0) { for (i = 0; i < line_count; i++) { fprintf(fptrout, "%d\n", my_strstr(copy[i], src[i]) != NULL); } } else if (strcmp(command, "my_strinsert") == 0) { for (i = 0; i < line_count; i++) { my_strinsert(buffer, "\n", 0); my_strinsert(buffer, src[i], 0); } fprintf(fptrout, "[%s]\n", buffer); } else if (strcmp(command, "my_strdelete") == 0) { for (i = 0; i < line_count; i++) { my_strinsert(buffer, "\n", 0); my_strinsert(buffer, src[i], 0); my_strdelete(buffer, 0, 10); } fprintf(fptrout, "[%s]\n", buffer); } for (i = 0; i < line_count; i++) { free(copy[i]); free(src[i]); } free(src); free(copy); free(buffer); fclose(fptrout); return EXIT_SUCCESS; }
/*############################ init_aftp() ##############################*/ int init_aftp(int argc, char *argv[], struct data *p_db) { int correct = YES, /* Was input/syntax correct? */ set_extended_mode = NO; char *ptr; ptr = argv[0] + strlen(argv[0]) - 1; while ((*ptr != '/') && (ptr != &argv[0][0])) { ptr--; } if (*ptr == '/') { ptr++; } (void)my_strncpy(name, ptr, 30); if (name[0] == 'r') { p_db->exec_mode = RETRIEVE_MODE; } else if (name[0] == 't') { p_db->exec_mode = TEST_MODE; } else { p_db->exec_mode = TRANSFER_MODE; } /* First initialize all values with default values. */ p_db->file_size_offset = -1; /* No appending. */ p_db->blocksize = DEFAULT_TRANSFER_BLOCKSIZE; p_db->remote_dir[0] = '\0'; p_db->hostname[0] = '\0'; p_db->lock = DOT; p_db->lock_notation[0] = '.'; p_db->lock_notation[1] = '\0'; p_db->transfer_mode = 'I'; p_db->ftp_mode = ACTIVE_MODE; #ifdef FTP_CTRL_KEEP_ALIVE_INTERVAL p_db->keepalive = NO; #endif p_db->port = DEFAULT_FTP_PORT; (void)strcpy(p_db->user, DEFAULT_AFD_USER); (void)strcpy(p_db->password, DEFAULT_AFD_PASSWORD); p_db->remove = NO; p_db->transfer_timeout = DEFAULT_TRANSFER_TIMEOUT; p_db->verbose = NO; p_db->append = NO; #ifdef WITH_SSL p_db->auth = NO; #endif p_db->create_target_dir = NO; p_db->dir_mode_str[0] = '\0'; if (name[0] == 't') { p_db->no_of_files = 1; p_db->dummy_size = DEFAULT_TRANSFER_BLOCKSIZE; } else { p_db->no_of_files = 0; } p_db->filename = NULL; p_db->realname = NULL; p_db->sndbuf_size = 0; p_db->rcvbuf_size = 0; p_db->proxy_name[0] = '\0'; /* Evaluate all arguments with '-'. */ while ((--argc > 0) && ((*++argv)[0] == '-')) { switch (*(argv[0] + 1)) { case 'A' : /* Search for file localy for appending. */ p_db->append = YES; break; case 'a' : /* Remote file size offset for appending. */ if ((argc == 1) || ((*(argv + 1)[0] == '-') && ((argv + 1)[0][1] != '2'))) { (void)fprintf(stderr, _("ERROR : No file size offset specified for option -a.\n")); correct = NO; } else { if ((name[0] == 'r') || (name[0] == 't')) { (void)fprintf(stderr, _("ERROR : This option is only for %s.\n"), &name[1]); correct = NO; } else { p_db->file_size_offset = (signed char)atoi(*(argv + 1)); } argc--; argv++; } break; case 'b' : /* FTP transfer block size. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No block size specified for option -b.\n")); correct = NO; } else { p_db->blocksize = atoi(*(argv + 1)); argc--; argv++; } break; case 'c' : /* Configuration file for user, passwd, etc. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No config file specified for option -c.\n")); correct = NO; } else { char config_file[MAX_PATH_LENGTH]; argv++; (void)my_strncpy(config_file, argv[0], MAX_PATH_LENGTH); argc--; eval_config_file(config_file, p_db); } break; case 'C' : /* Create target dir. */ p_db->create_target_dir = YES; if ((argc > 1) && (*(argv + 1)[0] != '-')) { int i = 0; char *aptr; aptr = argv[1]; do { if ((isdigit((int)*aptr)) && (i < 4)) { p_db->dir_mode_str[i] = *aptr; i++; aptr++; } else { i = 0; p_db->dir_mode_str[0] = '\0'; break; } } while (*aptr != '\0'); if (i > 0) { argv++; argc--; p_db->dir_mode_str[i] = '\0'; } } break; case 'd' : /* Target directory on remote host. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No target directory for option -d.\n")); correct = NO; } else { argv++; (void)my_strncpy(p_db->remote_dir, argv[0], MAX_PATH_LENGTH); argc--; } break; case 'f' : /* Configuration file for filenames. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No filename file specified for option -f.\n")); correct = NO; } else { char filename_file[MAX_PATH_LENGTH]; argv++; (void)my_strncpy(filename_file, argv[0], MAX_PATH_LENGTH); argc--; if (eval_filename_file(filename_file, p_db) == INCORRECT) { exit(FILE_NAME_FILE_ERROR); } } break; #ifdef FTP_CTRL_KEEP_ALIVE_INTERVAL case 'k' : /* Keep control connection alive. */ p_db->keepalive = YES; break; #endif case 'h' : /* Remote host name. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No host name or IP number specified for option -h.\n")); correct = NO; } else { argv++; (void)my_strncpy(p_db->hostname, argv[0], MAX_FILENAME_LENGTH); argc--; } break; case 'l' : /* Lock type. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No lock type specified for option -l.\n")); correct = NO; } else { argv++; argc--; if (name[0] == 'r') { (void)fprintf(stderr, _("ERROR : This option is only for %s.\n"), &name[1]); correct = NO; } else { /* Check which lock type is specified. */ if (strcmp(argv[0], LOCK_DOT) == 0) { p_db->lock = DOT; } else if (CHECK_STRCMP(ptr, LOCK_DOT_VMS) == 0) { p_db->lock = DOT_VMS; } #ifdef WITH_READY_FILES else if (strcmp(argv[0], READY_FILE_ASCII) == 0) { p_db->lock = READY_A_FILE; } else if (strcmp(argv[0], READY_FILE_BINARY) == 0) { p_db->lock = READY_B_FILE; } #endif /* WITH_READY_FILES */ else if (strcmp(argv[0], LOCK_OFF) == 0) { p_db->lock = OFF; } else { (void)my_strncpy(p_db->lock_notation, argv[0], MAX_FILENAME_LENGTH); } } } break; case 'm' : /* FTP transfer mode. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No transfer mode specified for option -m.\n")); correct = NO; } else { switch (*(argv + 1)[0]) { case 'a': case 'A': /* ASCII mode. */ p_db->transfer_mode = 'A'; argv++; argc--; break; case 'i': case 'I': case 'b': case 'B': /* Bianary mode. */ p_db->transfer_mode = 'I'; argv++; argc--; break; case 'd': case 'D': /* DOS mode. */ p_db->transfer_mode = 'D'; argv++; argc--; break; default : /* Wrong/unknown mode! */ (void)fprintf(stderr, _("ERROR : Unknown FTP transfer mode <%c> specified for option -m.\n"), *(argv + 1)[0]); correct = NO; break; } } break; case 'n' : /* Specify the number of files. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No number of files specified for option -n.\n")); correct = NO; } else { if (name[0] != 't') { char *p_name; if (name[0] == 'r') { p_name = &name[1]; } else { p_name = name; } (void)fprintf(stderr, _("ERROR : This option is only for t%s.\n"), p_name); correct = NO; } else { p_db->no_of_files = atoi(*(argv + 1)); } argc--; argv++; } break; case 'o' : /* Change mode of file. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No mode number specified for option -o.\n")); correct = NO; } else { int n; ptr = *(argv + 1); n = 0; while ((*ptr != '\n') && (*ptr != '\0') && (n < 4) && (isdigit((int)(*ptr)))) { p_db->chmod_str[n] = *ptr; ptr++; n++; } if (n > 1) { p_db->chmod_str[n] = '\0'; } else { (void)fprintf(stderr, _("ERROR : Not a correct mode number for option -o.\n")); correct = NO; } argc--; argv++; } break; case 'p' : /* Remote TCP port number. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No port number specified for option -p.\n")); correct = NO; } else { p_db->port = atoi(*(argv + 1)); argc--; argv++; } break; case 'P' : /* Use the given proxy procedure to login. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No proxy procedure for option -P.\n")); correct = NO; } else { argv++; (void)my_strncpy(p_db->proxy_name, argv[0], MAX_PROXY_NAME_LENGTH + 1); argc--; } break; case 'u' : /* User name and password for remote login. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No user and password specified for option -u.\n")); correct = NO; } else { argv++; (void)my_strncpy(p_db->user, argv[0], MAX_USER_NAME_LENGTH); argc--; /* If user is specified a password must be there as well! */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No password specified for option -u.\n")); correct = NO; } else { argv++; (void)my_strncpy(p_db->password, argv[0], MAX_USER_NAME_LENGTH); argc--; } } break; case 'r' : /* Remove file that was transmitted. */ p_db->remove = YES; break; case 'R' : /* Socket receive buffer. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No buffer size specified for option -R.\n")); correct = NO; } else { p_db->rcvbuf_size = atoi(*(argv + 1)); argc--; argv++; } break; case 'S' : /* Socket send buffer. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No buffer size specified for option -S.\n")); correct = NO; } else { p_db->sndbuf_size = atoi(*(argv + 1)); argc--; argv++; } break; case 's' : /* Dummy file size. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No file size specified for option -s.\n")); correct = NO; } else { if (name[0] != 't') { char *p_name; if (name[0] == 'r') { p_name = &name[1]; } else { p_name = name; } (void)fprintf(stderr, _("ERROR : This option is only for t%s.\n"), p_name); correct = NO; } else { p_db->dummy_size = atoi(*(argv + 1)); } argc--; argv++; } break; case 't' : /* FTP timeout. */ if ((argc == 1) || (*(argv + 1)[0] == '-')) { (void)fprintf(stderr, _("ERROR : No timeout specified for option -t.\n")); correct = NO; } else { p_db->transfer_timeout = atol(*(argv + 1)); argc--; argv++; } break; case 'v' : /* Verbose mode. */ p_db->verbose = YES; break; case 'x' : /* Use passive mode instead of active mode. */ p_db->ftp_mode = PASSIVE_MODE; break; case 'X' : /* Set extended mode. */ set_extended_mode = YES; break; #ifdef WITH_SSL case 'z' : /* SSL/TLS authentification for control connection only. */ p_db->auth = YES; break; case 'Z' : /* SSL/TLS authentification for control and data connection. */ p_db->auth = BOTH; break; #endif case '?' : /* Help. */ usage(); exit(0); default : /* Unknown parameter. */ (void)fprintf(stderr, _("ERROR : Unknown parameter <%c>. (%s %d)\n"), *(argv[0] + 1), __FILE__, __LINE__); correct = NO; break; } /* switch (*(argv[0] + 1)) */ } if ((*argv)[0] != '-') { argc++; argv--; } if (set_extended_mode == YES) { p_db->ftp_mode |= EXTENDED_MODE; } if (p_db->hostname[0] == '\0') { (void)fprintf(stderr, _("ERROR : No host name or IP number specified.\n")); correct = NO; } if ((p_db->no_of_files == 0) && (argc == 0)) { (void)fprintf(stderr, _("ERROR : No files to be send specified.\n")); correct = NO; } else if ((correct == YES) && (argc > 0) && (p_db->no_of_files == 0)) { if (name[0] == 't') { if (p_db->filename == NULL) { RT_ARRAY(p_db->filename, 1, MAX_PATH_LENGTH, char); (void)my_strncpy(p_db->filename[0], argv[1], MAX_PATH_LENGTH); } else { /* Ignore what ever the dummy user has written. */; } }
/* *** SCRIPT SYMBOL: [String] StrCopy *** */ static void _sc_strcpy(char*s1,char*s2) { check_strlen(s1); my_strncpy(s1, s2, MAXSTRLEN - 1); }
void Instrument::setName(const char *_name) { my_strncpy(name, _name, MAX_INST_NAME_LENGTH); }
/*+++++++++++++++++++++++++++++ init_cmd() ++++++++++++++++++++++++++++++*/ static void init_cmd(int *argc, char *argv[], char *title_cmd) { int length = 0; char *ptr; if ((get_arg(argc, argv, "-?", NULL, 0) == SUCCESS) || (get_arg(argc, argv, "-help", NULL, 0) == SUCCESS) || (get_arg(argc, argv, "--help", NULL, 0) == SUCCESS)) { usage(argv[0]); exit(SUCCESS); } /* Get working directory for the AFD. */ if (get_afd_path(argc, argv, work_dir) < 0) { exit(INCORRECT); } if (get_arg(argc, argv, "-f", font_name, 40) == INCORRECT) { (void)strcpy(font_name, "fixed"); } if (get_arg(argc, argv, "-b", NULL, 0) == SUCCESS) { go_to_beginning = YES; } if (*argc < 2) { usage(argv[0]); exit(INCORRECT); } if (argv[1][0] == '"') { (void)my_strncpy(cmd, &argv[1][1], MAX_PATH_LENGTH); length = strlen(cmd); if (cmd[length - 1] == '"') { cmd[length - 1] = '\0'; } } else { (void)my_strncpy(cmd, argv[1], MAX_PATH_LENGTH); } if (*argc > 2) { register int j; for (j = 1; j < *argc; j++) { argv[j] = argv[j + 1]; } argv[j] = NULL; } else { argv[1] = NULL; } (*argc)--; /* Cut out command for title of window. */ ptr = cmd; if ((cmd[0] == '/') || (cmd[0] == '.') || (cmd[0] == '~')) { char *p_end; while ((*ptr != ' ') && (*ptr != '\0')) { ptr++; } p_end = ptr; while ((*ptr != '/') && (*ptr != '.') && (*ptr != '~')) { ptr--; } ptr++; length = p_end - ptr; if (length > MAX_TITLE_CMD_LENGTH) { length = MAX_TITLE_CMD_LENGTH; } (void)my_strncpy(title_cmd, ptr, length + 1); } else { length = 0; while ((*ptr != ' ') && (*ptr != '\0') && (length < MAX_TITLE_CMD_LENGTH)) { title_cmd[length] = *ptr; ptr++; length++; } } title_cmd[length] = ' '; title_cmd[length + 1] = '\0'; /* Cut out target hostname. */ while (*ptr != '\0') { ptr++; } while ((*ptr != ' ') && (ptr != cmd)) { ptr--; } if (*ptr == ' ') { *ptr = '\0'; ptr++; } (void)strncat(title_cmd, ptr, 25); return; }
int get_termcaps( void) { static struct { char **value; char capname[6]; } table[] = { { &_clearinverse, CAPNAME("se", "rmso") }, { &_clearscreen, CAPNAME("cl", "clear") }, { &_cleartoeoln, CAPNAME("ce", "el") }, { &_cleartoeos, CAPNAME("cd", "ed") }, { &_clearunderline, CAPNAME("ue", "rmul") }, { &_cursoroff, CAPNAME("vi", "civis") }, { &_cursoron, CAPNAME("ve", "cnorm") }, { &_keypadlocal, CAPNAME("ke", "rmkx") }, { &_keypadxmit, CAPNAME("ks", "smkx") }, { &_moveto, CAPNAME("cm", "cup") }, { &_scrollback, CAPNAME("sr", "ri") }, { &_scrollfwd, CAPNAME("sf", "ind") }, { &_scrollregion, CAPNAME("cs", "csr") }, { &_setinverse, CAPNAME("so", "smso") }, { &_setunderline, CAPNAME("us", "smul") }, { &_terminalend, CAPNAME("te", "rmcup") }, { &_terminalinit, CAPNAME("ti", "smcup") }, /* extra caps needed for word highlighting */ { &_reset, CAPNAME("me", "sgr0") }, { &_reversevideo, CAPNAME("mr", "rev") }, { &_blink, CAPNAME("mb", "blink") }, { &_dim, CAPNAME("mh", "dim") }, { &_bold, CAPNAME("mb", "bold") }, }; static char _terminal[1024]; /* Storage for terminal entry */ # if defined(USE_TERMCAP) static char _capabilities[1024]; /* String for cursor motion */ static char *ptr = _capabilities; /* for buffering */ # if defined(HAVE_EXTERN_TCAP_PC) char *t; # endif /* HAVE_EXTERN_TCAP_PC */ # endif /* USE_TERMCAP */ char the_termname[40], *p; unsigned n; if ((p = getenv("TERM")) == NULL) { my_fprintf(stderr, _(txt_no_term_set), tin_progname); return FALSE; } my_strncpy(the_termname, p, sizeof(the_termname) - 1); # ifdef USE_TERMINFO setupterm(the_termname, fileno(stdout), (int *) 0); # else if (tgetent(_terminal, the_termname) != 1) { my_fprintf(stderr, _(txt_cannot_get_term_entry), tin_progname); return FALSE; } # endif /* USE_TERMINFO */ /* load in all those pesky values */ for (n = 0; n < ARRAY_SIZE(table); n++) { *(table[n].value) = TGETSTR(table[n].capname, &ptr); } _lines = TGETNUM(dCAPNAME("li", "lines")); _columns = TGETNUM(dCAPNAME("co", "cols")); _hp_glitch = TGETFLAG(dCAPNAME("xs", "xhp")); # if defined(USE_TERMCAP) && defined(HAVE_EXTERN_TCAP_PC) t = TGETSTR(CAPNAME("pc", "pad"), &p); if (t != 0) PC = *t; # endif /* USE_TERMCAP && HAVE_EXTERN_TCAP_PC */ if (STRCMPEQ(the_termname, "xterm")) { static char x_init[] = "\033[?9h"; static char x_end[] = "\033[?9l"; xclicks = TRUE; _xclickinit = x_init; _xclickend = x_end; } if (NO_CAP(_clearscreen)) { my_fprintf(stderr, _(txt_no_term_clearscreen), tin_progname); return FALSE; } if (NO_CAP(_moveto)) { my_fprintf(stderr, _(txt_no_term_cursor_motion), tin_progname); return FALSE; } if (NO_CAP(_cleartoeoln)) { my_fprintf(stderr, _(txt_no_term_clear_eol), tin_progname); return FALSE; } if (NO_CAP(_cleartoeos)) { my_fprintf(stderr, _(txt_no_term_clear_eos), tin_progname); return FALSE; } if (_lines == -1) _lines = DEFAULT_LINES_ON_TERMINAL; if (_columns == -1) _columns = DEFAULT_COLUMNS_ON_TERMINAL; if (_lines < MIN_LINES_ON_TERMINAL || _columns < MIN_COLUMNS_ON_TERMINAL) { my_fprintf(stderr, _(txt_screen_too_small), tin_progname); return FALSE; } /* * kludge to workaround no inverse */ if (NO_CAP(_setinverse)) { _setinverse = _setunderline; _clearinverse = _clearunderline; if (NO_CAP(_setinverse)) tinrc.draw_arrow = 1; } if (NO_CAP(_scrollregion) || NO_CAP(_scrollfwd) || NO_CAP(_scrollback)) have_linescroll = FALSE; else have_linescroll = TRUE; return TRUE; }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$ msa_view() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { int flush_output, i, j, last = 0, position = -1; unsigned int interval; FILE *output; char afdname[MAX_AFDNAME_LENGTH + 1], *ptr, str_fc[5], str_fs[5], str_tr[5], str_fr[4], str_jq[4], str_at[4], str_ec[3], str_hec[3], val[MAX_PATH_LENGTH + 1], work_dir[MAX_PATH_LENGTH]; const char *color_pool[COLOR_POOL_SIZE] = { HTML_COLOR_0, HTML_COLOR_1, HTML_COLOR_2, HTML_COLOR_3, HTML_COLOR_4, HTML_COLOR_5, HTML_COLOR_6, HTML_COLOR_7, HTML_COLOR_8, HTML_COLOR_9, HTML_COLOR_10, HTML_COLOR_11, HTML_COLOR_12, HTML_COLOR_13, HTML_COLOR_14, HTML_COLOR_15, HTML_COLOR_16, HTML_COLOR_17, HTML_COLOR_18, #ifdef _WITH_WMO_SUPPORT HTML_COLOR_19, HTML_COLOR_20 #else HTML_COLOR_19 #endif }; CHECK_FOR_VERSION(argc, argv); if (get_mon_path(&argc, argv, work_dir) < 0) { exit(INCORRECT); } p_work_dir = work_dir; #ifdef WITH_SETUID_PROGS set_afd_euid(work_dir); #endif if (get_arg(&argc, argv, "-d", val, MAX_INT_LENGTH) == SUCCESS) { interval = atoi(val); } else { interval = 0; } if (get_arg(&argc, argv, "-o", val, MAX_PATH_LENGTH) == SUCCESS) { if ((output = fopen(val, "w")) == NULL) { (void)fprintf(stderr, "Failed to fopen() %s : %s\n", val, strerror(errno)); exit(INCORRECT); } flush_output = YES; } else { output = stdout; flush_output = NO; } if (argc == 2) { if (isdigit((int)(argv[1][0])) != 0) { position = atoi(argv[1]); last = position + 1; } else { (void)my_strncpy(afdname, argv[1], MAX_AFDNAME_LENGTH + 1); } } else if (argc == 1) { position = -2; } else { usage(); exit(INCORRECT); } if ((i = msa_attach_passive()) < 0) { if (i == INCORRECT_VERSION) { (void)fprintf(stderr, "ERROR : This program is not able to attach to the MSA due to incorrect version. (%s %d)\n", __FILE__, __LINE__); } else { (void)fprintf(stderr, "ERROR : Failed to attach to MSA. (%s %d)\n", __FILE__, __LINE__); } exit(INCORRECT); } if (position == -1) { for (i = 0; i < no_of_afds; i++) { if (my_strcmp(msa[i].afd_alias, afdname) == 0) { position = i; break; } } if (position < 0) { (void)fprintf(stderr, "WARNING : Could not find AFD `%s' in MSA. (%s %d)\n", afdname, __FILE__, __LINE__); exit(INCORRECT); } last = position + 1; } else if (position == -2) { last = no_of_afds; position = 0; } else if (position >= no_of_afds) { (void)fprintf(stderr, "WARNING : There are only %d AFD's in the MSA. (%s %d)\n", no_of_afds, __FILE__, __LINE__); exit(INCORRECT); } ptr = (char *)msa; ptr -= AFD_WORD_OFFSET; for (;;) { (void)fprintf(output, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"); (void)fprintf(output, "<html>\n<head>\n <meta charset=\"utf-8\"/>\n"); (void)fprintf(output, " <meta http-equiv=\"refresh\" content=\"5\"/>\n"); (void)fprintf(output, " <title>AFD Monitor</title>\n</head>\n"); (void)fprintf(output, "<body bgcolor=\"#F0ECD6\">\n"); (void)fprintf(output, "<table align=center bgcolor=\"%s\">\n", color_pool[(int)DEFAULT_BG]); (void)fprintf(output, "<tr>\n"); (void)fprintf(output, "<th style=\"width:%dem;\" align=\"center\" valign=\"middle\" bgcolor=\"%s\">%s</th>\n", MAX_AFDNAME_LENGTH, color_pool[(int)LABEL_BG], "AFD"); (void)fprintf(output, "<th style=\"width:4em;\" align=\"center\" valign=\"middle\" bgcolor=\"%s\">fc</th>\n", color_pool[(int)LABEL_BG]); (void)fprintf(output, "<th style=\"width:4em;\" align=\"center\" valign=\"middle\" bgcolor=\"%s\">fs</th>\n", color_pool[(int)LABEL_BG]); (void)fprintf(output, "<th style=\"width:4em;\" align=\"center\" valign=\"middle\" bgcolor=\"%s\">tr</th>\n", color_pool[(int)LABEL_BG]); (void)fprintf(output, "<th style=\"width:3em;\" align=\"center\" valign=\"middle\" bgcolor=\"%s\">fr</th>\n", color_pool[(int)LABEL_BG]); (void)fprintf(output, "<th style=\"width:3em;\" align=\"center\" valign=\"middle\" bgcolor=\"%s\">jq</th>\n", color_pool[(int)LABEL_BG]); (void)fprintf(output, "<th style=\"width:3em;\" align=\"center\" valign=\"middle\" bgcolor=\"%s\">at</th>\n", color_pool[(int)LABEL_BG]); (void)fprintf(output, "<th style=\"width:2em;\" align=\"center\" valign=\"middle\" bgcolor=\"%s\">ec</th>\n", color_pool[(int)LABEL_BG]); (void)fprintf(output, "<th style=\"width:2em;\" align=\"center\" valign=\"middle\" bgcolor=\"%s\">eh</th>\n", color_pool[(int)LABEL_BG]); (void)fprintf(output, "</tr>\n"); for (j = position; j < last; j++) { (void)fprintf(output, "<tr>\n"); if (msa[j].connect_status == NOT_WORKING2) { (void)fprintf(output, "<td align=\"left\" valign=\"middle\" style=\"background-color:%s; color:%s\">%-*s</td>\n", color_pool[(int)NOT_WORKING2], color_pool[(int)WHITE], MAX_AFDNAME_LENGTH, msa[j].afd_alias); } else { (void)fprintf(output, "<td align=\"left\" valign=\"middle\" bgcolor=\"%s\">%-*s</td>\n", color_pool[(int)msa[j].connect_status], MAX_AFDNAME_LENGTH, msa[j].afd_alias); } CREATE_FC_STRING(str_fc, msa[j].fc); (void)fprintf(output, "<td align=\"right\" valign=\"middle\" bgcolor=\"%s\">%s</td>\n", color_pool[(int)CHAR_BACKGROUND], str_fc); CREATE_FS_STRING(str_fs, msa[j].fs); (void)fprintf(output, "<td align=\"right\" valign=\"middle\" bgcolor=\"%s\">%s</td>\n", color_pool[(int)CHAR_BACKGROUND], str_fs); CREATE_FS_STRING(str_tr, msa[j].tr); (void)fprintf(output, "<td align=\"right\" valign=\"middle\" bgcolor=\"%s\">%s</td>\n", color_pool[(int)CHAR_BACKGROUND], str_tr); CREATE_JQ_STRING(str_fr, msa[j].fr); (void)fprintf(output, "<td align=\"right\" valign=\"middle\" bgcolor=\"%s\">%s</td>\n", color_pool[(int)CHAR_BACKGROUND], str_fr); CREATE_JQ_STRING(str_jq, msa[j].jobs_in_queue); if ((msa[j].danger_no_of_jobs != 0) && (msa[j].jobs_in_queue > msa[j].danger_no_of_jobs) && (msa[j].jobs_in_queue <= ((msa[j].danger_no_of_jobs * 2) - STOP_AMG_THRESHOLD - DIRS_IN_FILE_DIR))) { (void)fprintf(output, "<td align=\"right\" valign=\"middle\" bgcolor=\"%s\">%s</td>\n", color_pool[(int)WARNING_ID], str_jq); } else if ((msa[j].danger_no_of_jobs != 0) && (msa[j].jobs_in_queue > ((msa[j].danger_no_of_jobs * 2) - STOP_AMG_THRESHOLD - DIRS_IN_FILE_DIR))) { (void)fprintf(output, "<td align=\"right\" valign=\"middle\" style=\"background-color:%s; color:%s\">%s</td>\n", color_pool[(int)NOT_WORKING2], color_pool[(int)WHITE], str_jq); } else { (void)fprintf(output, "<td align=\"right\" valign=\"middle\" bgcolor=\"%s\">%s</td>\n", color_pool[(int)CHAR_BACKGROUND], str_jq); } CREATE_JQ_STRING(str_at, msa[j].no_of_transfers); (void)fprintf(output, "<td align=\"right\" valign=\"middle\" bgcolor=\"%s\">%s</td>\n", color_pool[(int)CHAR_BACKGROUND], str_at); CREATE_EC_STRING(str_ec, msa[j].ec); if (msa[j].ec > 0) { (void)fprintf(output, "<td align=\"right\" valign=\"middle\" style=\"background-color:%s; color:%s\">%s</td>\n", color_pool[(int)CHAR_BACKGROUND], color_pool[(int)NOT_WORKING2], str_ec); } else { (void)fprintf(output, "<td align=\"right\" valign=\"middle\" bgcolor=\"%s\">%s</td>\n", color_pool[(int)CHAR_BACKGROUND], str_ec); } CREATE_EC_STRING(str_hec, msa[j].host_error_counter); if (msa[j].host_error_counter > 0) { (void)fprintf(output, "<td align=\"right\" valign=\"middle\" style=\"background-color:%s; color:%s\">%s</td>\n", color_pool[(int)NOT_WORKING2], color_pool[(int)WHITE], str_hec); } else { (void)fprintf(output, "<td align=\"right\" valign=\"middle\" bgcolor=\"%s\">%s</td>\n", color_pool[(int)CHAR_BACKGROUND], str_hec); } (void)fprintf(output, "</tr>\n"); } (void)fprintf(output, "</table>\n</body>\n</html>\n"); if (interval > 0) { if (flush_output == YES) { (void)fflush(output); } (void)sleep(interval); if (flush_output == YES) { (void)ftruncate(fileno(output), 0); (void)fseek(output, 0L, SEEK_SET); } } else { break; } } exit(SUCCESS); }
/* Returns 1 if elems should continue being read, 0 otherwise */ static int procheadelem(struct connstruct *cn, char *buf) { char *delim, *value; if ((delim = strchr(buf, ' ')) == NULL) return 0; *delim = 0; value = delim + 1; if (strcmp(buf, "GET") == 0 || strcmp(buf, "HEAD") == 0 || strcmp(buf, "POST") == 0) { if (buf[0] == 'H') cn->reqtype = TYPE_HEAD; else if (buf[0] == 'P') cn->reqtype = TYPE_POST; if ((delim = strchr(value, ' ')) == NULL) /* expect HTTP type */ return 0; *delim++ = 0; urldecode(value); if (sanitizefile(value) == 0) { send_error(cn, 403); return 0; } #if defined(CONFIG_HTTP_HAS_CGI) decode_path_info(cn, value); #else my_strncpy(cn->filereq, value, MAXREQUESTLENGTH); #endif cn->if_modified_since = -1; if (strcmp(delim, "HTTP/1.0") == 0) /* v1.0 HTTP? */ cn->is_v1_0 = 1; } else if (strcasecmp(buf, "Host:") == 0) { if (sanitizehost(value) == 0) { removeconnection(cn); return 0; } my_strncpy(cn->server_name, value, MAXREQUESTLENGTH); } else if (strcasecmp(buf, "Connection:") == 0 && strcmp(value, "close") == 0) { cn->close_when_done = 1; } else if (strcasecmp(buf, "If-Modified-Since:") == 0) { cn->if_modified_since = tdate_parse(value); } else if (strcasecmp(buf, "Expect:") == 0) { /* supposed to be safe to ignore 100-continue */ if (strcasecmp(value, "100-continue") != 0) { send_error(cn, 417); /* expectation failed */ return 0; } } #ifdef CONFIG_HTTP_HAS_AUTHORIZATION else if (strcasecmp(buf, "Authorization:") == 0 && strncmp(value, "Basic ", 6) == 0) { int size = sizeof(cn->authorization); if (base64_decode(&value[6], strlen(&value[6]), (uint8_t *)cn->authorization, &size)) cn->authorization[0] = 0; /* error */ else cn->authorization[size] = 0; } #endif #if defined(CONFIG_HTTP_HAS_CGI) else if (strcasecmp(buf, "Content-Length:") == 0) { sscanf(value, "%d", &cn->content_length); } else if (strcasecmp(buf, "Content-Type:") == 0) { my_strncpy(cn->cgicontenttype, value, MAXREQUESTLENGTH); } else if (strcasecmp(buf, "Cookie:") == 0) { my_strncpy(cn->cookie, value, MAXREQUESTLENGTH); } #endif return 1; }
/* In this function we assume that the file has been checked for * maliciousness (".."s, etc) and has been decoded */ void procsendhead(struct connstruct *cn) { char buf[MAXREQUESTLENGTH]; struct stat stbuf; time_t t_time; struct tm *ptm; char date[32]; char last_modified[32]; char expires[32]; int file_exists; /* are we trying to access a file over the HTTP connection instead of a * HTTPS connection? Or is this directory disabled? */ if (htaccess_check(cn)) { send_error(cn, 403); return; } #ifdef CONFIG_HTTP_HAS_AUTHORIZATION if (auth_check(cn)) { /* see if there is a '.htpasswd' file */ #ifdef CONFIG_HTTP_VERBOSE printf("axhttpd: access to %s denied\n", cn->filereq); TTY_FLUSH(); #endif removeconnection(cn); return; } #endif file_exists = stat(cn->actualfile, &stbuf); #if defined(CONFIG_HTTP_HAS_CGI) if (file_exists != -1 && cn->is_cgi) { proccgi(cn); return; } #endif /* look for "index.html"? */ if (isdir(cn->actualfile)) { char tbuf[MAXREQUESTLENGTH]; snprintf(tbuf, MAXREQUESTLENGTH, "%s%s", cn->actualfile, index_file); if ((file_exists = stat(tbuf, &stbuf)) != -1) my_strncpy(cn->actualfile, tbuf, MAXREQUESTLENGTH); else { #if defined(CONFIG_HTTP_DIRECTORIES) /* If not, we do a directory listing of it */ procdirlisting(cn); #else send_error(cn, 404); #endif return; } } if (file_exists == -1) { send_error(cn, 404); return; } time(&t_time); ptm = gmtime(&t_time); strftime(date, sizeof(date), rfc1123_format, ptm); /* has the file been read before? */ if (cn->if_modified_since != -1) { ptm = gmtime(&stbuf.st_mtime); t_time = mktime(ptm); if (cn->if_modified_since >= t_time) { snprintf(buf, sizeof(buf), HTTP_VERSION" 304 Not Modified\nServer: " "%s\nDate: %s\n\n", server_version, date); special_write(cn, buf, strlen(buf)); cn->state = STATE_WANT_TO_READ_HEAD; return; } } if (cn->reqtype == TYPE_HEAD) { removeconnection(cn); return; } else { int flags = O_RDONLY; #if defined(CONFIG_PLATFORM_CYGWIN) flags |= O_BINARY; #endif cn->filedesc = open(cn->actualfile, flags); if (cn->filedesc < 0) { send_error(cn, 404); return; } ptm = gmtime(&stbuf.st_mtime); strftime(last_modified, sizeof(last_modified), rfc1123_format, ptm); t_time += CONFIG_HTTP_TIMEOUT; ptm = gmtime(&t_time); strftime(expires, sizeof(expires), rfc1123_format, ptm); snprintf(buf, sizeof(buf), HTTP_VERSION" 200 OK\nServer: %s\n" "Content-Type: %s\nContent-Length: %ld\n" "Date: %s\nLast-Modified: %s\nExpires: %s\n\n", server_version, getmimetype(cn->actualfile), (long) stbuf.st_size, date, last_modified, expires); special_write(cn, buf, strlen(buf)); #ifdef CONFIG_HTTP_VERBOSE printf("axhttpd: %s:/%s\n", cn->is_ssl ? "https" : "http", cn->filereq); TTY_FLUSH(); #endif cn->state = STATE_WANT_TO_READ_FILE; } }
int GSI_SOCKET_get_error_string(GSI_SOCKET *self, char *buffer, int bufferlen) { int total_chars = 0; int chars; if ((buffer == NULL) || (bufferlen == 0)) { /* Punt */ return -1; } if (self == NULL) { return my_strncpy(buffer, "GSI SOCKET not initialized", bufferlen); } if (self->error_string != NULL) { chars = my_strncpy(buffer, self->error_string, bufferlen); if (chars == -1) { goto truncated; } total_chars += chars; buffer = &buffer[chars]; bufferlen -= chars; } if (self->error_number != 0) { if (total_chars && bufferlen && *(buffer-1) != '\n') { *buffer = '\n'; buffer++; total_chars++; bufferlen--; } chars = my_strncpy(buffer, strerror(self->error_number), bufferlen); if (chars == -1) { goto truncated; } total_chars += chars; buffer = &buffer[chars]; bufferlen -= chars; } if (self->major_status) { if (total_chars && bufferlen && *(buffer-1) != '\n') { *buffer = '\n'; buffer++; total_chars++; bufferlen--; } /* Parse errors from gss-assist routines */ switch(self->major_status) { case GSS_S_DEFECTIVE_TOKEN | GSS_S_CALL_INACCESSIBLE_READ: case GSS_S_DEFECTIVE_TOKEN | GSS_S_CALL_INACCESSIBLE_WRITE: chars = my_strncpy(buffer, "Connection closed.", bufferlen); break; default: chars = append_gss_status(buffer, bufferlen, self->major_status, GSS_C_GSS_CODE); if (chars == -1) { goto truncated; } total_chars += chars; buffer = &buffer[chars]; bufferlen -= chars; chars = append_gss_status(buffer, bufferlen, self->minor_status, GSS_C_MECH_CODE); if (chars == -1) { goto truncated; } } total_chars += chars; buffer = &buffer[chars]; bufferlen -= chars; } if (total_chars == 0) { /* No error */ buffer[0] = '\0'; } return total_chars; truncated: return -1; }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$ watch_dir() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { int gotcha, ret; off_t filesize = 0; char *ptr, filename[MAX_FILENAME_LENGTH], watch_dir[MAX_PATH_LENGTH]; struct stat stat_buf; struct dirent *dirp; DIR *dp; if (argc == 2) { (void)my_strncpy(watch_dir, argv[1], MAX_PATH_LENGTH); } else { usage(argv[0]); exit(0); } if ((dp = opendir(watch_dir)) == NULL) { (void)fprintf(stderr, "ERROR : Failed to opendir() %s : %s (%s %d)\n", watch_dir, strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } ptr = watch_dir + strlen(watch_dir); *ptr++ = '/'; (void)printf(" File name | File size | File date\n"); (void)printf("----------------------------------------+-----------+-------------------------\n"); for (;;) { gotcha = 0; while ((dirp = readdir(dp)) != NULL) { if ((strcmp(dirp->d_name, ".") == 0) || (strcmp(dirp->d_name, "..") == 0)) { continue; } (void)strcpy(ptr, dirp->d_name); if (stat(watch_dir, &stat_buf) < 0) { (void)fprintf(stderr, "WARNING : Failed to stat() %s : %s (%s %d)\n", watch_dir, strerror(errno), __FILE__, __LINE__); continue; } /* Make sure it's NOT a directory. */ if (S_ISDIR(stat_buf.st_mode) == 0) { if (((ret = strcmp(dirp->d_name, filename)) != 0) || ((ret == 0) && (filesize != stat_buf.st_size))) { (void)printf("%-39s |%10d | %s", dirp->d_name, (int)stat_buf.st_size, ctime(&stat_buf.st_mtime)); (void)strcpy(filename, dirp->d_name); filesize = stat_buf.st_size; gotcha = 1; } } } rewinddir(dp); if (gotcha) { (void)printf("----------------------------------------+-----------+-------------------------\n"); } (void)my_usleep(10000L); } exit(0); }
/*++++++++++++++++++++++++++++ eval_input() +++++++++++++++++++++++++++++*/ static void eval_input(int argc, char *argv[]) { int correct = YES, /* Was input/syntax correct? */ need_afdname = NO; char progname[128]; (void)my_strncpy(progname, argv[0], 128); /**********************************************************/ /* The following while loop checks for the parameters: */ /* */ /* -e : enable AFD */ /* -E : disable AFD */ /* -r : retry */ /* -s : switch AFD */ /* -X : toggle enable/disable AFD */ /* */ /**********************************************************/ while ((--argc > 0) && ((*++argv)[0] == '-')) { if (*(argv[0] + 2) == '\0') { switch (*(argv[0] + 1)) { case 'e': /* enable AFD */ options ^= ENABLE_AFD_OPTION; need_afdname = YES; break; case 'E': /* disable AFD */ options ^= DISABLE_AFD_OPTION; need_afdname = YES; break; case 'r': /* Retry */ options ^= RETRY_OPTION; need_afdname = YES; break; case 'X': /* Toggle enable/disable AFD */ options ^= TOGGLE_AFD_OPTION; break; default : /* Unknown parameter */ (void)fprintf(stderr, "ERROR : Unknown parameter %c. (%s %d)\n", *(argv[0] + 1), __FILE__, __LINE__); correct = NO; break; } /* switch (*(argv[0] + 1)) */ } else { (void)fprintf(stderr, "ERROR : Unknown option %s. (%s %d)\n", argv[0], __FILE__, __LINE__); correct = NO; } } if (correct != NO) { no_of_afd_names = argc; if (no_of_afd_names > 0) { int i = 0; RT_ARRAY(afds, no_of_afd_names, (MAX_AFD_NAME_LENGTH + 1), char); while (argc > 0) { (void)my_strncpy(afds[i], argv[0], MAX_AFD_NAME_LENGTH + 1); argc--; argv++; i++; } }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$ msa_view() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { int i, j, last = 0, position = -1; char afdname[MAX_AFDNAME_LENGTH + 1], *ptr, work_dir[MAX_PATH_LENGTH]; CHECK_FOR_VERSION(argc, argv); if (get_mon_path(&argc, argv, work_dir) < 0) { exit(INCORRECT); } p_work_dir = work_dir; if (argc == 2) { if (isdigit((int)(argv[1][0])) != 0) { position = atoi(argv[1]); last = position + 1; } else { (void)my_strncpy(afdname, argv[1], MAX_AFDNAME_LENGTH + 1); } } else if (argc == 1) { position = -2; } else { usage(); exit(INCORRECT); } if ((i = msa_attach_passive()) < 0) { if (i == INCORRECT_VERSION) { (void)fprintf(stderr, "ERROR : This program is not able to attach to the MSA due to incorrect version. (%s %d)\n", __FILE__, __LINE__); } else { (void)fprintf(stderr, "ERROR : Failed to attach to MSA. (%s %d)\n", __FILE__, __LINE__); } exit(INCORRECT); } if (position == -1) { for (i = 0; i < no_of_afds; i++) { if (strcmp(msa[i].afd_alias, afdname) == 0) { position = i; break; } } if (position < 0) { (void)fprintf(stderr, "WARNING : Could not find AFD `%s' in MSA. (%s %d)\n", afdname, __FILE__, __LINE__); exit(INCORRECT); } last = position + 1; } else if (position == -2) { last = no_of_afds; position = 0; } else if (position >= no_of_afds) { (void)fprintf(stderr, "WARNING : There are only %d AFD's in the MSA. (%s %d)\n", no_of_afds, __FILE__, __LINE__); exit(INCORRECT); } ptr = (char *)msa; ptr -= AFD_WORD_OFFSET; (void)fprintf(stdout, " Number of hosts: %d MSA ID: %d Struct Version: %d\n\n", no_of_afds, msa_id, (int)(*(ptr + SIZEOF_INT + 1 + 1 + 1))); for (j = position; j < last; j++) { (void)fprintf(stdout, "=============================> %s (%d) <=============================\n", msa[j].afd_alias, j); #ifdef NEW_MSA (void)fprintf(stdout, "AFD alias CRC : %x\n", msa[j].afd_id); #endif (void)fprintf(stdout, "Remote work dir : %s\n", msa[j].r_work_dir); (void)fprintf(stdout, "Remote AFD version : %s\n", msa[j].afd_version); (void)fprintf(stdout, "Remote command : %s\n", msa[j].rcmd); (void)fprintf(stdout, "Remote options : %d =>", msa[j].options); if (msa[j].options == 0) { (void)fprintf(stdout, " None"); } else { if (msa[j].options & COMPRESS_FLAG) { (void)fprintf(stdout, " COMPRESS"); } if (msa[j].options & MINUS_Y_FLAG) { (void)fprintf(stdout, " MINUS_Y"); } if (msa[j].options & DONT_USE_FULL_PATH_FLAG) { (void)fprintf(stdout, " DONT_USE_FULL_PATH"); } if (msa[j].options & ENABLE_SSL_ENCRYPTION) { (void)fprintf(stdout, " ENABLE_SSL_ENCRYPTION"); } if (msa[j].options & AFDD_SYSTEM_LOG) { (void)fprintf(stdout, " System"); } if (msa[j].options & AFDD_RECEIVE_LOG) { (void)fprintf(stdout, " Receive"); } if (msa[j].options & AFDD_TRANSFER_LOG) { (void)fprintf(stdout, " Transfer"); } if (msa[j].options & AFDD_TRANSFER_DEBUG_LOG) { (void)fprintf(stdout, " Trans_db"); } #ifdef _INPUT_LOG if (msa[j].options & AFDD_INPUT_LOG) { (void)fprintf(stdout, " Input"); } #endif #ifdef _DISTRIBUTION_LOG if (msa[j].options & AFDD_DISTRIBUTION_LOG) { (void)fprintf(stdout, " Distribution"); } #endif #ifdef _PRODUCTION_LOG if (msa[j].options & AFDD_PRODUCTION_LOG) { (void)fprintf(stdout, " Production"); } #endif #ifdef _OUTPUT_LOG if (msa[j].options & AFDD_OUTPUT_LOG) { (void)fprintf(stdout, " Output"); } #endif #ifdef _DELETE_LOG if (msa[j].options & AFDD_DELETE_LOG) { (void)fprintf(stdout, " Delete"); } #endif if (msa[j].options & AFDD_JOB_DATA) { (void)fprintf(stdout, " Job_data"); } if (msa[j].options & AFDD_COMPRESSION_1) { (void)fprintf(stdout, " Compression1"); } } (void)fprintf(stdout, "\n"); (void)fprintf(stdout, "Log capabilities : %d =>", msa[j].log_capabilities); if (msa[j].log_capabilities == 0) { (void)fprintf(stdout, " None"); } else { if (msa[j].log_capabilities & AFDD_SYSTEM_LOG) { (void)fprintf(stdout, " System"); } if (msa[j].log_capabilities & AFDD_EVENT_LOG) { (void)fprintf(stdout, " Event"); } if (msa[j].log_capabilities & AFDD_RECEIVE_LOG) { (void)fprintf(stdout, " Receive"); } if (msa[j].log_capabilities & AFDD_TRANSFER_LOG) { (void)fprintf(stdout, " Transfer"); } if (msa[j].log_capabilities & AFDD_TRANSFER_DEBUG_LOG) { (void)fprintf(stdout, " Trans_db"); } #ifdef _INPUT_LOG if (msa[j].log_capabilities & AFDD_INPUT_LOG) { (void)fprintf(stdout, " Input"); } #endif #ifdef _DISTRIBUTION_LOG if (msa[j].log_capabilities & AFDD_DISTRIBUTION_LOG) { (void)fprintf(stdout, " Distribution"); } #endif #ifdef _PRODUCTION_LOG if (msa[j].log_capabilities & AFDD_PRODUCTION_LOG) { (void)fprintf(stdout, " Production"); } #endif #ifdef _OUTPUT_LOG if (msa[j].log_capabilities & AFDD_OUTPUT_LOG) { (void)fprintf(stdout, " Output"); } #endif #ifdef _DELETE_LOG if (msa[j].log_capabilities & AFDD_DELETE_LOG) { (void)fprintf(stdout, " Delete"); } #endif if (msa[j].log_capabilities & AFDD_JOB_DATA) { (void)fprintf(stdout, " Job_data"); } if (msa[j].log_capabilities & AFDD_COMPRESSION_1) { (void)fprintf(stdout, " Compression1"); } } (void)fprintf(stdout, "\n"); if (msa[j].afd_switching != NO_SWITCHING) { (void)fprintf(stdout, "Real hostname 0 : %s\n", msa[j].hostname[0]); (void)fprintf(stdout, "TCP port 0 : %d\n", msa[j].port[0]); (void)fprintf(stdout, "Real hostname 1 : %s\n", msa[j].hostname[1]); (void)fprintf(stdout, "TCP port 1 : %d\n", msa[j].port[1]); (void)fprintf(stdout, "Current host : AFD %d\n", msa[j].afd_toggle); (void)fprintf(stdout, "Switch type : %s\n", (msa[j].afd_switching == AUTO_SWITCHING) ? "Auto" : "User"); } else { (void)fprintf(stdout, "Real hostname : %s\n", msa[j].hostname[0]); (void)fprintf(stdout, "TCP port : %d\n", msa[j].port[0]); (void)fprintf(stdout, "Switch type : No switching.\n"); } (void)fprintf(stdout, "Poll interval : %d\n", msa[j].poll_interval); (void)fprintf(stdout, "Connect time : %d\n", msa[j].connect_time); (void)fprintf(stdout, "Disconnect time : %d\n", msa[j].disconnect_time); (void)fprintf(stdout, "Status of AMG : %d\n", (int)msa[j].amg); (void)fprintf(stdout, "Status of FD : %d\n", (int)msa[j].fd); (void)fprintf(stdout, "Status of AW : %d\n", (int)msa[j].archive_watch); (void)fprintf(stdout, "Jobs in queue : %d\n", msa[j].jobs_in_queue); (void)fprintf(stdout, "Active transfers : %d\n", msa[j].no_of_transfers); (void)fprintf(stdout, "TOP no. process : %d", msa[j].top_no_of_transfers[0]); for (i = 1; i < STORAGE_TIME; i++) { (void)fprintf(stdout, " %d", msa[j].top_no_of_transfers[i]); } (void)fprintf(stdout, "\n"); (void)fprintf(stdout, "Last TOP no process: %s", ctime(&msa[j].top_not_time)); (void)fprintf(stdout, "Maximum connections: %d\n", msa[j].max_connections); (void)fprintf(stdout, "Sys log EC : %u |", msa[j].sys_log_ec); for (i = 0; i < LOG_FIFO_SIZE; i++) { switch (msa[j].sys_log_fifo[i]) { case INFO_ID : (void)fprintf(stdout, " I"); break; case ERROR_ID : (void)fprintf(stdout, " E"); break; case WARNING_ID : (void)fprintf(stdout, " W"); break; case CONFIG_ID : (void)fprintf(stdout, " C"); break; case FAULTY_ID : (void)fprintf(stdout, " F"); break; default : (void)fprintf(stdout, " ?"); break; } } (void)fprintf(stdout, " |\n"); (void)fprintf(stdout, "Receive History :"); for (i = 0; i < MAX_LOG_HISTORY; i++) { switch (msa[j].log_history[RECEIVE_HISTORY][i]) { case INFO_ID : (void)fprintf(stdout, " I"); break; case ERROR_ID : (void)fprintf(stdout, " E"); break; case WARNING_ID : (void)fprintf(stdout, " W"); break; case FAULTY_ID : (void)fprintf(stdout, " F"); break; default : (void)fprintf(stdout, " ?"); break; } } (void)fprintf(stdout, "\n"); (void)fprintf(stdout, "System History :"); for (i = 0; i < MAX_LOG_HISTORY; i++) { switch (msa[j].log_history[SYSTEM_HISTORY][i]) { case INFO_ID : (void)fprintf(stdout, " I"); break; case ERROR_ID : (void)fprintf(stdout, " E"); break; case WARNING_ID : (void)fprintf(stdout, " W"); break; case CONFIG_ID : (void)fprintf(stdout, " C"); break; case FAULTY_ID : (void)fprintf(stdout, " F"); break; default : (void)fprintf(stdout, " ?"); break; } } (void)fprintf(stdout, "\n"); (void)fprintf(stdout, "Transfer History :"); for (i = 0; i < MAX_LOG_HISTORY; i++) { switch (msa[j].log_history[TRANSFER_HISTORY][i]) { case INFO_ID : (void)fprintf(stdout, " I"); break; case ERROR_ID : (void)fprintf(stdout, " E"); break; case WARNING_ID : (void)fprintf(stdout, " W"); break; case ERROR_OFFLINE_ID : (void)fprintf(stdout, " O"); break; case FAULTY_ID : (void)fprintf(stdout, " F"); break; default : (void)fprintf(stdout, " ?"); break; } } (void)fprintf(stdout, "\n"); (void)fprintf(stdout, "Host error counter : %d\n", msa[j].host_error_counter); (void)fprintf(stdout, "Number of hosts : %d\n", msa[j].no_of_hosts); (void)fprintf(stdout, "Number of dirs : %d\n", msa[j].no_of_dirs); (void)fprintf(stdout, "Number of jobs : %d\n", msa[j].no_of_jobs); (void)fprintf(stdout, "fc : %u\n", msa[j].fc); #if SIZEOF_OFF_T == 4 (void)fprintf(stdout, "fs : %lu\n", msa[j].fs); (void)fprintf(stdout, "tr : %lu\n", msa[j].tr); (void)fprintf(stdout, "TOP tr : %lu", msa[j].top_tr[0]); #else (void)fprintf(stdout, "fs : %llu\n", msa[j].fs); (void)fprintf(stdout, "tr : %llu\n", msa[j].tr); (void)fprintf(stdout, "TOP tr : %llu", msa[j].top_tr[0]); #endif for (i = 1; i < STORAGE_TIME; i++) { #if SIZEOF_OFF_T == 4 (void)fprintf(stdout, " %lu", msa[j].top_tr[i]); #else (void)fprintf(stdout, " %llu", msa[j].top_tr[i]); #endif } (void)fprintf(stdout, "\n"); (void)fprintf(stdout, "Last TOP tr time : %s", ctime(&msa[j].top_tr_time)); (void)fprintf(stdout, "fr : %u\n", msa[j].fr); (void)fprintf(stdout, "TOP fr : %u", msa[j].top_fr[0]); for (i = 1; i < STORAGE_TIME; i++) { (void)fprintf(stdout, " %u", msa[j].top_fr[i]); } (void)fprintf(stdout, "\n"); (void)fprintf(stdout, "Last TOP fr time : %s", ctime(&msa[j].top_fr_time)); (void)fprintf(stdout, "ec : %u\n", msa[j].ec); (void)fprintf(stdout, "Last data time : %s", ctime(&msa[j].last_data_time)); for (i = 0; i < SUM_STORAGE; i++) { (void)fprintf(stdout, " : --- %s sum values ---\n", sum_stat_type[i]); (void)fprintf(stdout, "files_received : %u\n", msa[j].files_received[i]); #if SIZEOF_OFF_T == 4 (void)fprintf(stdout, "bytes_received : %lu\n", msa[j].bytes_received[i]); #else (void)fprintf(stdout, "bytes_received : %llu\n", msa[j].bytes_received[i]); #endif (void)fprintf(stdout, "files_send : %u\n", msa[j].files_send[i]); #if SIZEOF_OFF_T == 4 (void)fprintf(stdout, "bytes_send : %lu\n", msa[j].bytes_send[i]); #else (void)fprintf(stdout, "bytes_send : %llu\n", msa[j].bytes_send[i]); #endif (void)fprintf(stdout, "connections : %u\n", msa[j].connections[i]); (void)fprintf(stdout, "total_errors : %u\n", msa[j].total_errors[i]); #if SIZEOF_OFF_T == 4 (void)fprintf(stdout, "log_bytes_received : %lu\n", msa[j].log_bytes_received[i]); #else (void)fprintf(stdout, "log_bytes_received : %llu\n", msa[j].log_bytes_received[i]); #endif } (void)fprintf(stdout, " : ---------------------\n"); switch (msa[j].connect_status) { case CONNECTION_ESTABLISHED : (void)fprintf(stdout, "Connect status : CONNECTION_ESTABLISHED\n"); break; case CONNECTION_DEFUNCT : (void)fprintf(stdout, "Connect status : CONNECTION_DEFUNCT\n"); break; case DISCONNECTED : (void)fprintf(stdout, "Connect status : DISCONNECTED\n"); break; case DISABLED : /* This AFD is disabled, ie should not be monitored. */ (void)fprintf(stdout, "Connect status : DISABLED\n"); break; default : /* Should not get here. */ (void)fprintf(stdout, "Connect status : Unknown\n"); } (void)fprintf(stdout, "Special flag (%3d) :", msa[j].special_flag); if (msa[j].special_flag & SUM_VAL_INITIALIZED) { (void)fprintf(stdout, " SUM_VAL_INITIALIZED"); } (void)fprintf(stdout, "\n"); if (msa[j].convert_username[0][0][0] != '\0') { (void)fprintf(stdout, "Convert user name : %s -> %s\n", msa[j].convert_username[0][0], msa[j].convert_username[0][1]); for (i = 1; i < MAX_CONVERT_USERNAME; i++) { (void)fprintf(stdout, " : %s -> %s\n", msa[j].convert_username[i][0], msa[j].convert_username[i][1]); } } } exit(SUCCESS); }