int checkVista() { char *m_uname; isVista = 0; m_uname = getuname(); if(!m_uname) { merror(MEM_ERROR, __local_name); return(0); } /* We check if the system is vista (most be called during the startup. */ if(strstr(m_uname, "Windows Server 2008") || strstr(m_uname, "Vista")) { isVista = 1; verbose("%s: INFO: System is Vista or Windows Server 2008.", __local_name); } free(m_uname); return(isVista); }
/* Insert server info to the db * Returns server ID or 0 on error */ int OS_Server_ReadInsertDB(const DBConfig *db_config) { int server_id = 0; char *info; debug1("%s: DEBUG: entering OS_Server_ReadInsertDB()", ARGV0); /* Get server hostname */ memset(__shost, '\0', 512); if (gethostname(__shost, 512 - 1) != 0) { merror("%s: Error: gethostname() failed", ARGV0); return (0); } /* Get system uname */ info = getuname(); if (!info) { merror(MEM_ERROR, ARGV0, errno, strerror(errno)); return (0); } /* Escape strings */ osdb_escapestr(info); osdb_escapestr(__shost); /* Insert server */ __DBInsertServer(__shost, info, db_config); /* Get server id */ server_id = __DBSelectServer(__shost, db_config); free(info); return (server_id); }
int checkVista() { char *m_uname; isVista = 0; m_uname = getuname(); if (!m_uname) { merror(MEM_ERROR, __local_name, errno, strerror(errno)); return (0); } /* Check if the system is Vista (must be called during the startup) */ if (strstr(m_uname, "Windows Server 2008") || strstr(m_uname, "Vista") || strstr(m_uname, "Windows 7") || strstr(m_uname, "Windows 8") || strstr(m_uname, "Windows Server 2012")) { isVista = 1; verbose("%s: INFO: System is Vista or newer (%s).", __local_name, m_uname); } else { verbose("%s: INFO: System is older than Vista (%s).", __local_name, m_uname); } free(m_uname); return (isVista); }
int Cnt_flds(Lextok *m) { Lextok *fp, *tl, *n; int cnt = 0; if (m->ntyp == ',') { n = m; goto is_lst; } if (!m->sym || m->ntyp != STRUCT) return 1; n = getuname(m->sym); is_lst: for (fp = n; fp; fp = fp->rgt) for (tl = fp->lft; tl; tl = tl->rgt) { if (tl->sym->type == STRUCT) { if (tl->sym->nel != 1) fatal("array of structures in param list, %s", tl->sym->name); cnt += Cnt_flds(tl->sym->Slst); } else cnt += tl->sym->nel; } return cnt; }
int main(int argc,char **argv) { if(argc!=2) { printf("Usage:%s file \n",argv[0]); exit(EXIT_FAILURE); } struct stat statbuf; printf("file name:%s \n",argv[1]); if(lstat(argv[1],&statbuf)<0) ERR_EXIT("stat"); printf("主设备号(块号):%d,次设备号:%d\n",MAJOR(statbuf.st_dev),MINOR(statbuf.st_dev)); printf("i节点号:%d\n",(int)statbuf.st_ino); printf("硬链接数:%d\n",(int)statbuf.st_nlink); printf("用户名:%s,(%d)\n",getuname(&statbuf),(int)statbuf.st_uid); printf("组名:%s,(%d)\n",getgname(&statbuf),(int)statbuf.st_gid); printf("磁盘id:%d\n",(int)statbuf.st_rdev); printf("文件大小:%d\n",(int)statbuf.st_size); filetype(&statbuf); printf("文件的权限:%o ",statbuf.st_mode & 00777); char permission[11]="----------"; filepermission(&statbuf,permission); printf("%s\n",permission); return 0; }
char *OS_AddNewAgent(const char *name, const char *ip, const char *id) { FILE *fp; os_md5 md1; os_md5 md2; char str1[STR_SIZE + 1]; char str2[STR_SIZE + 1]; char *muname; char *finals; char nid[9]; srandom_init(); muname = getuname(); snprintf(str1, STR_SIZE, "%d%s%d%s", (int)time(0), name, (int)random(), muname); snprintf(str2, STR_SIZE, "%s%s%ld", ip, id, (long int)random()); OS_MD5_Str(str1, md1); OS_MD5_Str(str2, md2); free(muname); nid[8] = '\0'; if (id == NULL) { int i = 1024; snprintf(nid, 6, "%d", i); while (IDExist(nid)) { i++; snprintf(nid, 6, "%d", i); if (i >= (MAX_AGENTS + 1024)) { return (NULL); } } id = nid; } fp = fopen(KEYSFILE_PATH, "a"); if (!fp) { return (NULL); } os_calloc(2048, sizeof(char), finals); if (ip == NULL) { snprintf(finals, 2048, "%s %s any %s%s", id, name, md1, md2); } else { snprintf(finals, 2048, "%s %s %s %s%s", id, name, ip, md1, md2); } fprintf(fp, "%s\n", finals); fclose(fp); return (finals); }
int qmake(Symbol *s) { Lextok *m; Queue *q; int i; if (!s->ini) return 0; if (nqs >= MAXQ) { lineno = s->ini->ln; Fname = s->ini->fn; fatal("too many queues (%s)", s->name); } if (analyze && nqs >= 255) { fatal("too many channel types", (char *)0); } if (s->ini->ntyp != CHAN) return eval(s->ini); q = (Queue *) emalloc(sizeof(Queue)); q->qid = ++nqs; q->nslots = s->ini->val; q->nflds = cnt_mpars(s->ini->rgt); q->setat = depth; i = max(1, q->nslots); /* 0-slot qs get 1 slot minimum */ q->contents = (int *) emalloc(q->nflds*i*sizeof(int)); q->fld_width = (int *) emalloc(q->nflds*sizeof(int)); q->stepnr = (int *) emalloc(i*sizeof(int)); for (m = s->ini->rgt, i = 0; m; m = m->rgt) { if (m->sym && m->ntyp == STRUCT) i = Width_set(q->fld_width, i, getuname(m->sym)); else q->fld_width[i++] = m->ntyp; } q->nxt = qtab; qtab = q; ltab[q->qid-1] = q; return q->qid; }
void setutype(Lextok *p, Symbol *t, Lextok *vis) /* user-defined types */ { int oln = lineno; Symbol *ofn = Fname; Lextok *m, *n; m = getuname(t); for (n = p; n; n = n->rgt) { lineno = n->ln; Fname = n->fn; if (n->sym->type) non_fatal("redeclaration of '%s'", n->sym->name); if (n->sym->nbits > 0) non_fatal("(%s) only an unsigned can have width-field", n->sym->name); if (Expand_Ok) n->sym->hidden |= (4|8|16); /* formal par */ if (vis) { if (strncmp(vis->sym->name, ":hide:", 6) == 0) n->sym->hidden |= 1; else if (strncmp(vis->sym->name, ":show:", 6) == 0) n->sym->hidden |= 2; else if (strncmp(vis->sym->name, ":local:", 7) == 0) n->sym->hidden |= 64; } n->sym->type = STRUCT; /* classification */ n->sym->Slst = m; /* structure itself */ n->sym->Snm = t; /* name of typedef */ n->sym->Nid = 0; /* this is no chan */ n->sym->hidden |= 4; if (n->sym->nel <= 0) non_fatal("bad array size for '%s'", n->sym->name); } lineno = oln; Fname = ofn; }
/* Generates a random and temporary shared pass to be used by the agents. */ char *__generatetmppass() { int rand1; int rand2; char *rand3; char *rand4; os_md5 md1; os_md5 md3; os_md5 md4; char *fstring = NULL; char str1[STR_SIZE +1]; char *muname = NULL; #ifndef WIN32 #ifdef __OpenBSD__ srandomdev(); #else srandom(time(0) + getpid() + getppid()); #endif #else srandom(time(0) + getpid()); #endif rand1 = random(); rand2 = random(); rand3 = GetRandomNoise(); rand4 = GetRandomNoise(); OS_MD5_Str(rand3, md3); OS_MD5_Str(rand4, md4); muname = getuname(); snprintf(str1, STR_SIZE, "%d%d%s%d%s%s",(int)time(0), rand1, muname, rand2, md3, md4); OS_MD5_Str(str1, md1); fstring = strdup(md1); return(fstring); }
/* Send win32 info to server */ void send_win32_info(time_t curr_time) { int msg_size; char tmp_msg[OS_MAXSTR +2]; char crypt_msg[OS_MAXSTR +2]; tmp_msg[OS_MAXSTR +1] = '\0'; crypt_msg[OS_MAXSTR +1] = '\0'; debug1("%s: DEBUG: Sending keep alive message.", ARGV0); verbose("%s Sending keep alive message....", ARGV0); /* fixing time */ __win32_curr_time = curr_time; /* Getting uname. */ if(!__win32_uname) { __win32_uname = getuname(); if(!__win32_uname) { merror("%s: Error generating system information.", ARGV0); os_strdup("Microsoft Windows - Unknown (unable to get system info)", __win32_uname); } } /* Getting shared files list -- every 30 seconds only. */ if((__win32_curr_time - __win32_shared_time) > 30) { if(__win32_shared) { free(__win32_shared); __win32_shared = NULL; } __win32_shared_time = __win32_curr_time; } /* get shared files */ if(!__win32_shared) { __win32_shared = getsharedfiles(); if(!__win32_shared) { __win32_shared = strdup("\0"); if(!__win32_shared) { merror(MEM_ERROR, ARGV0); return; } } } /* creating message */ if(File_DateofChange(AGENTCONFIGINT) > 0) { os_md5 md5sum; if(OS_MD5_File(AGENTCONFIGINT, md5sum) != 0) { snprintf(tmp_msg, OS_SIZE_1024, "#!-%s\n%s", __win32_uname, __win32_shared); } else { snprintf(tmp_msg, OS_SIZE_1024, "#!-%s / %s\n%s", __win32_uname, md5sum, __win32_shared); } } else { snprintf(tmp_msg, OS_SIZE_1024, "#!-%s\n%s", __win32_uname, __win32_shared); } /* creating message */ debug1("%s: DEBUG: Sending keep alive: %s", ARGV0, tmp_msg); msg_size = CreateSecMSG(&keys, tmp_msg, crypt_msg, 0); if(msg_size == 0) { merror(SEC_ERROR, ARGV0); return; } /* Sending UDP message */ if(OS_SendUDPbySize(logr->sock, msg_size, crypt_msg) < 0) { merror(SEND_ERROR, ARGV0, "server"); sleep(1); } return; }
static int print_acl(char *path, acl_type_t type, int hflag, int iflag, int nflag, int qflag, int vflag) { struct stat sb; acl_t acl; char *acl_text; int error, flags = 0, ret; if (hflag) error = lstat(path, &sb); else error = stat(path, &sb); if (error == -1) { warn("%s: stat() failed", path); return(-1); } if (hflag) ret = lpathconf(path, _PC_ACL_NFS4); else ret = pathconf(path, _PC_ACL_NFS4); if (ret > 0) { if (type == ACL_TYPE_DEFAULT) { warnx("%s: there are no default entries in NFSv4 ACLs", path); return (-1); } type = ACL_TYPE_NFS4; } else if (ret < 0 && errno != EINVAL) { warn("%s: pathconf(..., _PC_ACL_NFS4) failed", path); return (-1); } if (more_than_one) printf("\n"); else more_than_one++; if (!qflag) printf("# file: %s\n# owner: %s\n# group: %s\n", path, getuname(sb.st_uid), getgname(sb.st_gid)); if (hflag) acl = acl_get_link_np(path, type); else acl = acl_get_file(path, type); if (!acl) { if (errno != EOPNOTSUPP) { warn("%s", path); return(-1); } errno = 0; if (type == ACL_TYPE_DEFAULT) return(0); acl = acl_from_stat(sb); if (!acl) { warn("%s: acl_from_stat() failed", path); return(-1); } } if (iflag) flags |= ACL_TEXT_APPEND_ID; if (nflag) flags |= ACL_TEXT_NUMERIC_IDS; if (vflag) flags |= ACL_TEXT_VERBOSE; acl_text = acl_to_text_np(acl, 0, flags); if (!acl_text) { warn("%s: acl_to_text_np() failed", path); return(-1); } printf("%s", acl_text); (void)acl_free(acl); (void)acl_free(acl_text); return(0); }
/* run_notify: Send periodically notification to server */ void run_notify() { char keep_alive_random[1024]; char tmp_msg[OS_SIZE_1024 +1]; char *uname; char *shared_files; os_md5 md5sum; keep_alive_random[0] = '\0'; time_t curr_time; curr_time = time(0); #ifndef ONEWAY /* Check if the server has responded */ if((curr_time - available_server) > (3*NOTIFY_TIME)) { /* If response is not available, set lock and * wait for it. */ verbose(SERVER_UNAV, ARGV0); os_setwait(); /* Send sync message */ start_agent(0); verbose(SERVER_UP, ARGV0); os_delwait(); } #endif /* Check if time has elapsed */ if((curr_time - g_saved_time) < (NOTIFY_TIME - 120)) { return; } g_saved_time = curr_time; debug1("%s: DEBUG: Sending agent notification.", ARGV0); /* Send the message. * Message is going to be the * uname\n checksum file\n checksum file\n */ /* Getting uname */ uname = getuname(); if(!uname) { merror(MEM_ERROR,ARGV0); return; } /* get shared files */ shared_files = getsharedfiles(); if(!shared_files) { shared_files = strdup("\0"); if(!shared_files) { free(uname); merror(MEM_ERROR,ARGV0); return; } } rand_keepalive_str2(keep_alive_random, 700); /* creating message */ if((File_DateofChange(AGENTCONFIGINT) > 0 ) && (OS_MD5_File(AGENTCONFIGINT, md5sum) == 0)) { snprintf(tmp_msg, OS_SIZE_1024, "#!-%s / %s\n%s\n%s", uname, md5sum, shared_files, keep_alive_random); } else { snprintf(tmp_msg, OS_SIZE_1024, "#!-%s\n%s\n%s", uname, shared_files, keep_alive_random); } /* Sending status message */ send_msg(0, tmp_msg); free(uname); free(shared_files); return; }
static int sm_parse_file(FILE*fp,const char* fname) { FR_TOKEN tok; VALUE_PAIR *vp = NULL; sm_parse_state_t parse_state = SMP_USER; unsigned long lino = 0; char *p; char buff[MAX_BUFF_SIZE]; char username[256]; while( parse_state != SMP_INVALID && fgets(buff, sizeof(buff), fp) != NULL ) { lino ++; st_lines++; if ( strchr(buff, '\n') == NULL) { fprintf(stderr,"%s: %s[%lu]:Warning: line too long or not closed by \\n character. Skiped\n",progname,fname,lino); st_warns++; st_skiped++; /* _LINE_ skiped */ continue; } DOUT2("Parseline: %s",buff); for ( p = buff; isspace((int) *p); p++); if ( *p == '#' || *p == 0 ) continue; /* userparse hack */ if ( *p == ';' ) *p = '\n'; p = buff; /* try to decide is this line new user or new pattern */ if ( parse_state == SMP_PATTERN_OR_USER ) { if ( isspace((int) buff[0]) ) parse_state = SMP_PATTERN; else { parse_state = SMP_USER; storecontent(username); st_users++; } } if ( parse_state == SMP_USER ) { tok = getuname(&p,username,sizeof(username)); /* check: is it include. not implemented */ if ( tok ) { fprintf(stderr ,"%s: %s[%lu]: error while expecting user name\n",progname,fname,lino); parse_state = SMP_INVALID; st_errors++; } else { parse_state = SMP_PATTERN; DOUT1("Found user: %s\n",username); } } if ( parse_state == SMP_PATTERN || parse_state == SMP_ACTION ) { /* check for empty line */ while( *p && isspace((int) *p) ) p++; if ( *p && ( *p != ';' ) ) tok = userparse(p,&vp); else tok = T_EOL; /* ';' - signs empty line */ switch(tok) { case T_EOL: /* add to content */ addlinetocontent(vp); pairfree(&vp); if ( parse_state == SMP_PATTERN ) parse_state = SMP_ACTION; else parse_state = SMP_PATTERN_OR_USER; case T_COMMA: break; /* parse next line */ default: /* error: we do not expect anything else */ fprintf(stderr ,"%s: %s[%lu]: syntax error\n",progname,fname,lino); fr_perror("Error"); parse_state = SMP_INVALID; st_errors++; } } } if ( feof(fp) ) switch (parse_state ) { case SMP_USER: /* file is empty, last line is comment */ break; case SMP_PATTERN: /* only username ?*/ fprintf(stderr ,"%s: %s[%lu]: EOF while pattern line are expecting\n",progname,fname,lino); st_errors++; parse_state = SMP_INVALID; break; case SMP_ACTION: /* looking for reply line */ fprintf(stderr ,"%s: %s[%lu]: EOF while reply line are expecting\n",progname,fname,lino); st_errors++; parse_state = SMP_INVALID; break; case SMP_PATTERN_OR_USER: storecontent(username); st_users++; break; default:break; } else if ( parse_state != SMP_INVALID ) { /* file read error */ fprintf(stderr ,"%s: error file reading from file\n",progname); } pairfree(&vp); return (parse_state == SMP_INVALID)?-1:0; }
char * ns_os_uname(void) { if (unamep == NULL) getuname(); return (unamep); }
/* ReadConfig(int modules, char *cfgfile) * Read the config files */ int ReadConfig(int modules, char *cfgfile, void *d1, void *d2) { int i; OS_XML xml; XML_NODE node; /** XML definitions **/ /* Global */ char *xml_start_ossec = "ossec_config"; char *xml_start_ospatrol = "ospatrol_config"; char *xml_start_agent = "agent_config"; /* Attributes of the <agent_config> tag */ char *xml_agent_name = "name"; char *xml_agent_os = "os"; char *xml_agent_overwrite = "overwrite"; /* cmoraes */ char *xml_agent_profile = "profile"; if(OS_ReadXML(cfgfile,&xml) < 0) { if(modules & CAGENT_CONFIG) { #ifndef CLIENT merror(XML_ERROR, ARGV0, cfgfile, xml.err, xml.err_line); #endif } else { merror(XML_ERROR, ARGV0, cfgfile, xml.err, xml.err_line); } return(OS_INVALID); } node = OS_GetElementsbyNode(&xml, NULL); if(!node) { return(0); } /* Reading the main configuration */ i = 0; while(node[i]) { if(!node[i]->element) { merror(XML_ELEMNULL, ARGV0); return(OS_INVALID); } else if(!(modules & CAGENT_CONFIG) && ( (strcmp(node[i]->element, xml_start_ossec) == 0) || (strcmp(node[i]->element, xml_start_ospatrol) == 0) ) ) { XML_NODE chld_node = NULL; chld_node = OS_GetElementsbyNode(&xml,node[i]); /* Main element does not need to have any child */ if(chld_node) { if(read_main_elements(xml, modules, chld_node, d1, d2) < 0) { merror(CONFIG_ERROR, ARGV0, cfgfile); return(OS_INVALID); } OS_ClearNode(chld_node); } } else if((modules & CAGENT_CONFIG) && (strcmp(node[i]->element, xml_start_agent) == 0)) { int passed_agent_test = 1; int attrs = 0; XML_NODE chld_node = NULL; chld_node = OS_GetElementsbyNode(&xml,node[i]); /* Checking if this is specific to any agent. */ if(node[i]->attributes && node[i]->values) { while(node[i]->attributes[attrs] && node[i]->values[attrs]) { /* Checking if there is an "name=" attribute */ if(strcmp(xml_agent_name, node[i]->attributes[attrs]) == 0) { #ifdef CLIENT char *agentname = os_read_agent_name(); if(!agentname) { passed_agent_test = 0; } else { if(!OS_Match2(node[i]->values[attrs], agentname)) { passed_agent_test = 0; } free(agentname); } #endif } else if(strcmp(xml_agent_os, node[i]->attributes[attrs]) == 0) { #ifdef CLIENT char *agentos = getuname(); if(agentos) { if(!OS_Match2(node[i]->values[attrs], agentos)) { passed_agent_test = 0; } free(agentos); } else { passed_agent_test = 0; merror("%s: ERROR: Unable to retrieve uname.", ARGV0); } #endif } else if(strcmp(xml_agent_profile, node[i]->attributes[attrs]) == 0) { #ifdef CLIENT char *agentprofile = os_read_agent_profile(); debug2("Read agent config profile name [%s]", agentprofile); if(!agentprofile) { passed_agent_test = 0; } else { /* match the profile name of this <agent_config> section * with a comma separated list of values in agent's * <config-profile> tag. */ if(!OS_Match2(node[i]->values[attrs], agentprofile)) { passed_agent_test = 0; debug2("[%s] did not match agent config profile name [%s]", node[i]->values[attrs], agentprofile); } else { debug2("Matched agent config profile name [%s]", agentprofile); } free(agentprofile); } #endif } /* cmoraes: end add */ else if(strcmp(xml_agent_overwrite, node[i]->attributes[attrs]) == 0) { } else { merror(XML_INVATTR, ARGV0, node[i]->attributes[attrs], cfgfile); } attrs++; } } #ifdef CLIENT else { debug2("agent_config element does not have any attributes."); /* if node does not have any attributes, it is a generic config block. * check if agent has a profile name * if agent does not have profile name, then only read this generic * agent_config block */ if (!os_read_agent_profile()) { debug2("but agent has a profile name."); passed_agent_test = 0; } } #endif /* Main element does not need to have any child */ if(chld_node) { if(passed_agent_test && read_main_elements(xml, modules, chld_node, d1, d2) < 0) { merror(CONFIG_ERROR, ARGV0, cfgfile); return(OS_INVALID); } OS_ClearNode(chld_node); } } else { merror(XML_INVELEM, ARGV0, node[i]->element); return(OS_INVALID); } i++; } /* Clearing node and xml */ OS_ClearNode(node); OS_ClearXML(&xml); return(0); }
char *OS_AddNewAgent(const char *name, const char *ip, const char *id) { FILE *fp; os_md5 md1; os_md5 md2; char str1[STR_SIZE + 1]; char str2[STR_SIZE + 1]; char *muname; char *finals; char nid[9] = { '\0' }; srandom_init(); muname = getuname(); snprintf(str1, STR_SIZE, "%d%s%d%s", (int)time(0), name, (int)random(), muname); snprintf(str2, STR_SIZE, "%s%s%ld", ip, id, (long int)random()); OS_MD5_Str(str1, md1); OS_MD5_Str(str2, md2); free(muname); if (id == NULL) { #ifdef REUSE_ID int i = 1024; snprintf(nid, 6, "%d", i); while (IDExist(nid)) { i++; snprintf(nid, 6, "%d", i); if (i >= (MAX_AGENTS + 1024)) return (NULL); } #else char nid_p[9] = { '\0' }; int i = AUTHD_FIRST_ID; int j = MAX_AGENTS + AUTHD_FIRST_ID; int m = (i + j) / 2; snprintf(nid, 8, "%d", m); snprintf(nid_p, 8, "%d", m - 1); /* Dichotomic search */ while (1) { if (IDExist(nid)) { if (m == i) return NULL; i = m; } else if (!IDExist(nid_p) && m > i ) j = m; else break; m = (i + j) / 2; snprintf(nid, 8, "%d", m); snprintf(nid_p, 8, "%d", m - 1); } #endif id = nid; } fp = fopen(AUTH_FILE, "a"); if (!fp) { return (NULL); } os_calloc(2048, sizeof(char), finals); if (ip == NULL) { snprintf(finals, 2048, "%s %s any %s%s", id, name, md1, md2); } else { snprintf(finals, 2048, "%s %s %s %s%s", id, name, ip, md1, md2); } fprintf(fp, "%s\n", finals); fclose(fp); OS_AddAgentTimestamp(id, name, ip, time(0)); return (finals); }
char *OS_AddNewAgent(char *name, char *ip, char *id, char *key) { int i = 0; FILE *fp; int rand1; os_md5 md1; os_md5 md2; char str1[STR_SIZE +1]; char str2[STR_SIZE +1]; char *muname = NULL; char *finals = NULL; char nid[9]; #ifndef WIN32 #ifdef __OpenBSD__ srandomdev(); #else srandom(time(0) + getpid() + getppid()); #endif #else srandom(time(0) + getpid()); #endif rand1 = random(); muname = getuname(); snprintf(str1, STR_SIZE, "%d%s%d%s",(int)time(0), name, rand1, muname); snprintf(str2, STR_SIZE, "%s%s%ld", ip, id, (long int)random()); OS_MD5_Str(str1, md1); OS_MD5_Str(str2, md2); free(muname); nid[8] = '\0'; if(id == NULL) { i = 1024; snprintf(nid, 6, "%d", i); while(IDExist(nid)) { i++; snprintf(nid, 6, "%d", i); if(i >= 4000) { return(NULL); } } id = nid; } fp = fopen(KEYSFILE_PATH,"a"); if(!fp) { return(NULL); } os_calloc(2048, sizeof(char), finals); if (ip == NULL){ snprintf(finals, 2048, "%s %s any %s%s",id, name, md1,md2); } else { snprintf(finals, 2048, "%s %s %s %s%s",id, name, ip, md1,md2); } fprintf(fp, "%s\n",finals); fclose(fp); return(finals); }