コード例 #1
0
ファイル: verify-agent-conf.c プロジェクト: wazuh/ossec-wazuh
int main(int argc, char **argv)
{
    const char *ar = AGENTCONFIG;
    int c = 0;
    int modules = 0;
    logreader_config log_config;

    /* Set the name */
    OS_SetName(ARGV0);

    /* User arguments */
    if (argc > 1) {
        while ((c = getopt(argc, argv, "Vdhf:")) != -1) {
            switch (c) {
                case 'V':
                    print_version();
                    break;
                case 'h':
                    helpmsg();
                    break;
                case 'd':
                    nowDebug();
                    break;
                case 'f':
                    if (!optarg) {
                        merror("%s: -f needs an argument", ARGV0);
                        helpmsg();
                    }
                    ar = optarg;
                    break;
                default:
                    helpmsg();
                    break;
            }
        }
    }

    printf("\n%s: Verifying [%s].\n\n", ARGV0, ar);

    modules |= CLOCALFILE;
    modules |= CAGENT_CONFIG;
    log_config.config = NULL;
    if (ReadConfig(modules, ar, &log_config, NULL) < 0) {
        return (OS_INVALID);
    }

    return (0);
}
コード例 #2
0
ファイル: proj2.c プロジェクト: dhlavac/IZP-projekt-2
int main(int argc, char * argv[])
{
    
 if (argc == 1)
    {
     fprintf(stderr, "ERROR neboli zadane ziade argumenty\n"); // ak nieje zadany argument tak vypisem chybu
     return EXIT_FAILURE;
    } 
 if (argc > 6)
    {
     fprintf(stderr, "ERROR bolo zadanych vela argumentov\n");
     return EXIT_FAILURE;
    } 
 if ((strcmp(argv[1],"--help")==0))// ak je zadany argumet --help vypise napovedu 
    {
     helpmsg();
     return EXIT_SUCCESS;
    }
    else if ((strcmp(argv[1],"--tan")==0) && argc == 5) //ak je zadany argument --tan prebehne vypocet tangensu
    {  
     tang(argc,argv);
     return EXIT_SUCCESS;
    }
 else if ((strcmp(argv[1],"-m")==0) || (strcmp(argv[1],"-c")==0) ) // ak je zadany argument -m prebehne vypoccet vzdialenosti
    {
     range(argc,argv);
     return EXIT_SUCCESS;
    }
 return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: tbfinfo.c プロジェクト: jkeiren/muCRL
static void help(void)
    {
    Pr("");
    helpmsg();
    Pr("");
    Pr("");
    }
コード例 #4
0
ファイル: rewr.c プロジェクト: jkeiren/muCRL
static void help(char *s) {
    if (strcmp(s,"-help") && strcmp(s,"-help-all")) return;
    Pr("This filter reads from input an LPO in tbf format and reduces");
    Pr("it to an LPO which is equivalent to it by rewriting");  
    Pr("all terms of the input LPO."); 
    Pr("");
    helpmsg(!strcmp(s,"-help-all"));
    Pr("");
    exit(1);
    }
コード例 #5
0
ファイル: 167.C プロジェクト: 13436120/Cgames
int main(int argc,char * argv[])
{
  int result;
  char buffer[512];
  FILE *fp;
  if (argc == 1) helpmsg();
  if (* argv[1] == 's' || *argv[1] == 'S')		/*保存分区表功能*/
  {
    result = biosdisk(2,0x80,0,0,0,1,buffer);   /*调用biosdisk,将错误类型返回给result,内容存在buffer中*/
	if (!result){								/*如果成功读取分区表*/
		printf(" Read partition table successfully!\n");
		if (( fp == fopen("c:part.doc","wb+"))==NULL)     /*将结果写到C:\part.doc文件中*/
		{
			fprintf(stderr," Can't creat file:c:\\part.doc \n"); /*如果写文件失败*/
			exit(1);
		}
		fwrite(buffer,1,512,fp);
		fclose(fp);
		printf(" Partition table save successfully!\n");
		return 0;
	}
	else {										/*如果读取失败*/
		fprintf(stderr," Fail to read partition table!");
		exit(1);
	}
  }
  if ( * argv[1] == 'r' || * argv[1] == 'S')	/*恢复分区表功能,顺序相反,操作与上面类似*/
  {
	  if ((fp == fopen("c:part.doc","rb+"))==NULL)
	  {
		  fprintf(stderr," Can't open file!");
		  exit(1);
	  }
	  fread (buffer,1,512,fp);
	  result = biosdisk(3,0x80,0,0,1,1,buffer);
	  if (! result){
		  printf(" Partition table restore successfully!\n");
		  fclose(fp);
		  return 0;
	  }
	  else{
		  fprintf(stderr," Failt to restore partition table!");
		  fclose(fp);
		  exit(1);
	  }
  }
  printf("\n Press any key to quit...");
  getch();
  return 0;
}
コード例 #6
0
ファイル: agt2agx.c プロジェクト: BPaden/garglk
int parse_options(char *opt,char *next)
{
  if (opt[0]=='-' && opt[1]==0)   /* -- */
    {end_cmd_options=1;return 0;}
  for(;*opt!=0;opt++)
    switch(tolower(*opt))
      {
      case '?': case 'h':
	helpmsg();
	exit(EXIT_SUCCESS);
      case 'i': 
	if (opt[1]=='-') {DIAG=0;opt++;}
	else if (opt[1]=='+') {DIAG=1;opt++;}
	else DIAG=1;
      break;
#ifdef OPEN_FILE_AS_TEXT
      case 'b': 
	if (opt[1]=='-') {open_as_binary=0;opt++;}
	else if (opt[1]=='+') {open_as_binary=1;opt++;}
	else open_as_binary=1;
	break;
#endif
      case 'o':
	if (opt[1]!=0 || next!=NULL) {
	  if (opt[1]!=0) outname=opt+1;
	  else outname=next;
	  return (opt[1]==0); /* Skip next argument if opt[1]==0 */
	} else {
	  printf("-o requires a file name\n");
	  exit(EXIT_FAILURE);
	} 
      default:printf("Do not recognize option %c\n",*opt);
	helpmsg();
	exit(EXIT_FAILURE);
      }
  return 0;
}
コード例 #7
0
/** main **/
int main(int argc, char **argv)
{
    char *dir = DEFAULTDIR;
    char *group = GROUPGLOBAL;
    char *user = USER;
    char *agent_id = NULL;
    char *ip_address = NULL;
    char *ar = NULL;

    int arq = 0;
    int gid = 0;
    int uid = 0;
    int c = 0, restart_syscheck = 0, restart_all_agents = 0, list_agents = 0;
    int info_agent = 0, agt_id = 0, active_only = 0, csv_output = 0;
    int list_responses = 0, end_time = 0, restart_agent = 0;

    char shost[512];

    keystore keys;



    /* Setting the name */
    OS_SetName(ARGV0);


    /* user arguments */
    if(argc < 2)
    {
        helpmsg();
    }


    while((c = getopt(argc, argv, "VehdlLcsaru:i:b:f:R:")) != -1)
    {
        switch(c){
            case 'V':
                print_version();
                break;
            case 'h':
                helpmsg();
                break;
            case 'd':
                nowDebug();
                break;
            case 'L':
                list_responses = 1;
                break;
            case 'e':
                end_time = 1;
                break;
            case 'r':
                restart_syscheck = 1;
                break;
            case 'l':
                list_agents++;
                break;
            case 's':
                csv_output = 1;
                break;
            case 'c':
                active_only++;
                break;
            case 'i':
                info_agent++;
            case 'u':
                if(!optarg)
                {
                    merror("%s: -u needs an argument",ARGV0);
                    helpmsg();
                }
                agent_id = optarg;
                break;
            case 'b':
                if(!optarg)
                {
                    merror("%s: -b needs an argument",ARGV0);
                    helpmsg();
                }
                ip_address = optarg;
                break;
            case 'f':
                if(!optarg)
                {
                    merror("%s: -e needs an argument",ARGV0);
                    helpmsg();
                }
                ar = optarg;
                break;
            case 'R':
                if(!optarg)
                {
                    merror("%s: -R needs an argument",ARGV0);
                    helpmsg();
                }
                agent_id = optarg;
                restart_agent = 1;
            case 'a':
                restart_all_agents = 1;
                break;
            default:
                helpmsg();
                break;
        }

    }


    /* Getting the group name */
    gid = Privsep_GetGroup(group);
    uid = Privsep_GetUser(user);
    if(gid < 0)
    {
	    ErrorExit(USER_ERROR, ARGV0, user, group);
    }
	

    /* Setting the group */
    if(Privsep_SetGroup(gid) < 0)
    {
	    ErrorExit(SETGID_ERROR,ARGV0, group);
    }


    /* Chrooting to the default directory */
    if(Privsep_Chroot(dir) < 0)
    {
        ErrorExit(CHROOT_ERROR, ARGV0, dir);
    }


    /* Inside chroot now */
    nowChroot();


    /* Setting the user */
    if(Privsep_SetUser(uid) < 0)
    {
        ErrorExit(SETUID_ERROR, ARGV0, user);
    }



    /* Getting servers hostname */
    memset(shost, '\0', 512);
    if(gethostname(shost, 512 -1) != 0)
    {
        strncpy(shost, "localhost", 32);
        return(0);
    }


    /* Listing responses. */
    if(list_responses)
    {
        FILE *fp;
        if(!csv_output)
        {
            printf("\nOSSEC HIDS %s. Available active responses:\n", ARGV0);
        }

        fp = fopen(DEFAULTAR, "r");
        if(fp)
        {
            char buffer[256];

            while(fgets(buffer, 255, fp) != NULL)
            {
                char *r_name;
                char *r_cmd;
                char *r_timeout;

                r_name = buffer;
                r_cmd = strchr(buffer, ' ');
                if(!r_cmd)
                    continue;

                *r_cmd = '\0';
                r_cmd++;
                if(*r_cmd == '-')
                    r_cmd++;
                if(*r_cmd == ' ')
                    r_cmd++;

                r_timeout = strchr(r_cmd, ' ');
                if(!r_timeout)
                    continue;
                *r_timeout = '\0';

                if(strcmp(r_name, "restart-ossec0") == 0)
                {
                    continue;
                }
                printf("\n   Response name: %s, command: %s", r_name, r_cmd);
            }

            printf("\n\n");
            fclose(fp);
        }
        else
        {
            printf("\n   No active response available.\n\n");
        }

        exit(0);
    }


    /* Listing available agents. */
    if(list_agents)
    {
        if(!csv_output)
        {
            printf("\nOSSEC HIDS %s. List of available agents:",
                    ARGV0);
            printf("\n   ID: 000, Name: %s (server), IP: 127.0.0.1, Active/Local\n",
                    shost);
        }
        else
        {
            printf("000,%s (server),127.0.0.1,Active/Local,\n", shost);
        }
        print_agents(1, active_only, csv_output);
        printf("\n");
        exit(0);
    }



    /* Checking if the provided ID is valid. */
    if(agent_id != NULL)
    {
        if(strcmp(agent_id, "000") != 0)
        {
            OS_ReadKeys(&keys);

            agt_id = OS_IsAllowedID(&keys, agent_id);
            if(agt_id < 0)
            {
                printf("\n** Invalid agent id '%s'.\n", agent_id);
                helpmsg();
            }
        }
        else
        {
            /* server. */
            agt_id = -1;
        }
    }



    /* Printing information from an agent. */
    if(info_agent)
    {
        int agt_status = 0;
        char final_ip[IPSIZE + 4];
        agent_info *agt_info;

        final_ip[(sizeof final_ip) - 1] = '\0';


        if(!csv_output)
            printf("\nOSSEC HIDS %s. Agent information:", ARGV0);

        if(agt_id != -1)
        {
            agt_status = get_agent_status(keys.keyentries[agt_id]->name,
                                          keys.keyentries[agt_id]->ip->ip);

            agt_info = get_agent_info(keys.keyentries[agt_id]->name,
                                      keys.keyentries[agt_id]->ip->ip);

            /* Getting full address/prefix length from ip. */
            snprintf(final_ip, sizeof final_ip, "%s/%u",
                     keys.keyentries[agt_id]->ip->ip,
                     keys.keyentries[agt_id]->ip->prefixlength);


            if(!csv_output)
            {
                printf("\n   Agent ID:   %s\n", keys.keyentries[agt_id]->id);
                printf("   Agent Name: %s\n", keys.keyentries[agt_id]->name);
                printf("   IP address: %s\n", final_ip);
                printf("   Status:     %s\n\n",print_agent_status(agt_status));
            }
            else
            {
                printf("%s,%s,%s,%s,",
                       keys.keyentries[agt_id]->id,
                       keys.keyentries[agt_id]->name,
                       final_ip,
                       print_agent_status(agt_status));
            }
        }
        else
        {
            agt_status = get_agent_status(NULL, NULL);
            agt_info = get_agent_info(NULL, "127.0.0.1");

            if(!csv_output)
            {
            printf("\n   Agent ID:   000 (local instance)\n");
            printf("   Agent Name: %s\n", shost);
            printf("   IP address: 127.0.0.1\n");
            printf("   Status:     %s/Local\n\n",print_agent_status(agt_status));
            }

            else
            {
                printf("000,%s,127.0.0.1,%s/Local,",
                        shost,
                        print_agent_status(agt_status));

            }
        }


        if(!csv_output)
        {
        printf("   Operating system:    %s\n", agt_info->os);
        printf("   Client version:      %s\n", agt_info->version);
        printf("   Last keep alive:     %s\n\n", agt_info->last_keepalive);


        if(end_time)
        {
        printf("   Syscheck last started at:  %s\n", agt_info->syscheck_time);
        printf("   Syscheck last ended   at:  %s\n", agt_info->syscheck_endtime);
        printf("   Rootcheck last started at: %s\n", agt_info->rootcheck_time);
        printf("   Rootcheck last ended   at: %s\n\n", agt_info->rootcheck_endtime);
        }
        else
        {
        printf("   Syscheck last started  at: %s\n", agt_info->syscheck_time);
        printf("   Rootcheck last started at: %s\n", agt_info->rootcheck_time);
        }
        }
        else
        {
            printf("%s,%s,%s,%s,%s,\n",
                   agt_info->os,
                   agt_info->version,
                   agt_info->last_keepalive,
                   agt_info->syscheck_time,
                   agt_info->rootcheck_time);
        }

        exit(0);
    }



    /* Restarting syscheck every where. */
    if(restart_all_agents && restart_syscheck)
    {

        /* Connecting to remoted. */
        debug1("%s: DEBUG: Connecting to remoted...", ARGV0);
        arq = connect_to_remoted();
        if(arq < 0)
        {
            printf("\n** Unable to connect to remoted.\n");
            exit(1);
        }
        debug1("%s: DEBUG: Connected...", ARGV0);


        /* Sending restart message to all agents. */
        if(send_msg_to_agent(arq, HC_SK_RESTART, NULL, NULL) == 0)
        {
            printf("\nOSSEC HIDS %s: Restarting Syscheck/Rootcheck on all agents.",
                    ARGV0);
        }
        else
        {
            printf("\n** Unable to restart syscheck on all agents.\n");
            exit(1);
        }

        exit(0);
    }



    if(restart_syscheck && agent_id)
    {

        /* Restart on the server. */
        if(strcmp(agent_id, "000") == 0)
        {
            os_set_restart_syscheck();

            printf("\nOSSEC HIDS %s: Restarting Syscheck/Rootcheck "
                   "locally.\n", ARGV0);

            exit(0);
        }



        /* Connecting to remoted. */
        debug1("%s: DEBUG: Connecting to remoted...", ARGV0);
        arq = connect_to_remoted();
        if(arq < 0)
        {
            printf("\n** Unable to connect to remoted.\n");
            exit(1);
        }
        debug1("%s: DEBUG: Connected...", ARGV0);


        if(send_msg_to_agent(arq, HC_SK_RESTART, agent_id, NULL) == 0)
        {
            printf("\nOSSEC HIDS %s: Restarting Syscheck/Rootcheck on agent: %s\n",
                    ARGV0, agent_id);
        }
        else
        {
            printf("\n** Unable to restart syscheck on agent: %s\n", agent_id);
            exit(1);
        }

        exit(0);
    }


    if(restart_agent && agent_id)
    {
        /* Connecting to remoted. */
        debug1("%s: DEBUG: Connecting to remoted...", ARGV0);
        arq = connect_to_remoted();
        if(arq < 0)
        {
            printf("\n** Unable to connect to remoted.\n");
            exit(1);
        }
        debug1("%s: DEBUG: Connected...", ARGV0);


        if(send_msg_to_agent(arq, "restart-ossec0", agent_id, "null") == 0)
        {
            printf("\nOSSEC HIDS %s: Restarting agent: %s\n",
                    ARGV0, agent_id);
        }
        else
        {
            printf("\n** Unable to restart agent: %s\n", agent_id);
            exit(1);
        }

        exit(0);
    }


    /* running active response on the specified agent id. */
    if(ip_address && ar && agent_id)
    {
        /* Connecting to remoted. */
        debug1("%s: DEBUG: Connecting to remoted...", ARGV0);
        arq = connect_to_remoted();
        if(arq < 0)
        {
            printf("\n** Unable to connect to remoted.\n");
            exit(1);
        }
        debug1("%s: DEBUG: Connected...", ARGV0);


        if(send_msg_to_agent(arq, ar, agent_id, ip_address) == 0)
        {
            printf("\nOSSEC HIDS %s: Running active response '%s' on: %s\n",
                    ARGV0, ar, agent_id);
        }
        else
        {
            printf("\n** Unable to restart syscheck on agent: %s\n", agent_id);
            exit(1);
        }

        exit(0);
    }


    printf("\n** Invalid argument combination.\n");
    helpmsg();


    return(0);
}
コード例 #8
0
/** main **/
int main(int argc, char **argv)
{
    char *dir = DEFAULTDIR;
    char *group = GROUPGLOBAL;
    char *user = USER;
    char *agent_id = NULL;

    int gid = 0;
    int uid = 0;
    int c = 0, info_agent = 0, update_rootcheck = 0,
               list_agents = 0, show_last = 0,
               resolved_only = 0;
    int active_only = 0, csv_output = 0;

    char shost[512];
    
    
    
    /* Setting the name */
    OS_SetName(ARGV0);
        
    
    /* user arguments */
    if(argc < 2)
    {
        helpmsg();
    }


    while((c = getopt(argc, argv, "VhqrDdLlcsu:i:")) != -1)
    {
        switch(c){
            case 'V':
                print_version();
                break;
            case 'h':
                helpmsg();
                break;
            case 'D':
                nowDebug();
                break;
            case 'l':
                list_agents++;
                break;
            case 's':
                csv_output = 1;    
                break;
            case 'c':
                active_only++;
                break;    
            case 'r':
                resolved_only = 1;
                break;    
            case 'q':
                resolved_only = 2;
                break;    
            case 'L':
                show_last = 1;
                break;
            case 'i':
                info_agent++;
                if(!optarg)
                {
                    merror("%s: -u needs an argument",ARGV0);
                    helpmsg();
                }
                agent_id = optarg;
                break;
            case 'u':
                if(!optarg)
                {
                    merror("%s: -u needs an argument",ARGV0);
                    helpmsg();
                }
                agent_id = optarg;
                update_rootcheck = 1;
                break;
            default:
                helpmsg();
                break;
        }

    }
    
    
    /* Getting the group name */
    gid = Privsep_GetGroup(group);
    uid = Privsep_GetUser(user);
    if(gid < 0)
    {
	    ErrorExit(USER_ERROR, ARGV0, user, group);
    }
	
    
    /* Setting the group */
    if(Privsep_SetGroup(gid) < 0)
    {
	    ErrorExit(SETGID_ERROR,ARGV0, group);
    }
    
    
    /* Chrooting to the default directory */
    if(Privsep_Chroot(dir) < 0)
    {
        ErrorExit(CHROOT_ERROR, ARGV0, dir);
    }


    /* Inside chroot now */
    nowChroot();
 

    /* Setting the user */
    if(Privsep_SetUser(uid) < 0)
    {
        ErrorExit(SETUID_ERROR, ARGV0, user);
    }



    /* Getting servers hostname */
    memset(shost, '\0', 512);
    if(gethostname(shost, 512 -1) != 0)
    {
        strncpy(shost, "localhost", 32);
        return(0);
    }


    
    /* Listing available agents. */
    if(list_agents)
    {
        if(!csv_output)
        {
            printf("\nOSSEC HIDS %s. List of available agents:", 
                    ARGV0);
            printf("\n   ID: 000, Name: %s (server), IP: 127.0.0.1, "
                   "Active/Local\n", shost);
        }
        else
        {
            printf("000,%s (server),127.0.0.1,Active/Local,\n", shost);
        }
        print_agents(1, active_only, csv_output);
        printf("\n");
        exit(0);
    }
    


    /* Update rootcheck database. */
    if(update_rootcheck)
    {
        /* Cleaning all agents (and server) db. */
        if(strcmp(agent_id, "all") == 0)
        {
            DIR *sys_dir;
            struct dirent *entry;

            sys_dir = opendir(ROOTCHECK_DIR);
            if(!sys_dir)
            {
                ErrorExit("%s: Unable to open: '%s'", ARGV0, ROOTCHECK_DIR);
            }

            while((entry = readdir(sys_dir)) != NULL)
            {
                FILE *fp;
                char full_path[OS_MAXSTR +1];

                /* Do not even attempt to delete . and .. :) */
                if((strcmp(entry->d_name,".") == 0)||
                   (strcmp(entry->d_name,"..") == 0))
                {
                    continue;
                }

                snprintf(full_path, OS_MAXSTR,"%s/%s", ROOTCHECK_DIR, 
                         entry->d_name);

                fp = fopen(full_path, "w");
                if(fp)
                {
                    fclose(fp);
                }
                if(entry->d_name[0] == '.')
                {
                    unlink(full_path);
                }
            }

            closedir(sys_dir);
            printf("\n** Policy and auditing database updated.\n\n");
            exit(0);
        }

        else if((strcmp(agent_id, "000") == 0) || 
                (strcmp(agent_id, "local") == 0))
        {
            char final_dir[1024];
            FILE *fp;
            snprintf(final_dir, 1020, "/%s/rootcheck", ROOTCHECK_DIR);

            fp = fopen(final_dir, "w");
            if(fp)
            {
                fclose(fp);
            }
            unlink(final_dir);
            printf("\n** Policy and auditing database updated.\n\n");
            exit(0);
        }

        /* Database from remote agents. */
        else
        {
            int i;
            keystore keys;

            OS_ReadKeys(&keys);

            i = OS_IsAllowedID(&keys, agent_id);
            if(i < 0)
            {
                printf("\n** Invalid agent id '%s'.\n", agent_id);
                helpmsg();
            }

            /* Deleting syscheck */
            delete_rootcheck(keys.keyentries[i]->name,
                             keys.keyentries[i]->ip->ip, 0);

            printf("\n** Policy and auditing database updated.\n\n");
            exit(0);
        }
    }

    
    /* Printing information from an agent. */
    if(info_agent)
    {
        int i;
        char final_ip[128 +1];
        char final_mask[128 +1];
        keystore keys;


        if((strcmp(agent_id, "000") == 0) ||
           (strcmp(agent_id, "local") == 0))
        {
            if(!csv_output)
            printf("\nPolicy and auditing events for local system '%s - %s':\n",
                    shost, "127.0.0.1");
            
            print_rootcheck(NULL,
                            NULL, NULL, resolved_only, csv_output, show_last); 
        }
        else
        {

            OS_ReadKeys(&keys);

            i = OS_IsAllowedID(&keys, agent_id);
            if(i < 0)
            {
                printf("\n** Invalid agent id '%s'.\n", agent_id);
                helpmsg();
            }

            /* Getting netmask from ip. */
            final_ip[128] = '\0';
            final_mask[128] = '\0';
            getNetmask(keys.keyentries[i]->ip->netmask, 
                       final_mask, 128);
            snprintf(final_ip, 128, "%s%s",keys.keyentries[i]->ip->ip,
                     final_mask);

            if(!csv_output)
            printf("\nPolicy and auditing events for agent "
                       "'%s (%s) - %s':\n",
                       keys.keyentries[i]->name, keys.keyentries[i]->id, 
                       final_ip);

            print_rootcheck(keys.keyentries[i]->name,
                            keys.keyentries[i]->ip->ip, NULL, 
                            resolved_only, csv_output, show_last);

        }
        
        exit(0);
    }


    
    printf("\n** Invalid argument combination.\n");
    helpmsg();


    return(0);
}
コード例 #9
0
ファイル: num_gen.c プロジェクト: fatso83/Code-Snippets
int main(int argc, char *argv[])
{
  int mode, range, total;
  int ran_num[ BUFFER ];
  int num_buf, remainder = 0;

  /*Process input from user:
    Should be in the form:
    argv[1]="--mode=XX"
    argv[2]="--range=XX"
    argv[3]="--total=XX"
    
    Note: atoi (stdlib) converts string to integer
    PS DRAFT VERSION WILL ONLY USE NUMBERS!
  */

  if( argc < 4 ){
    helpmsg();
    return 1; /* Change to some ERR return code in final version */
  }
   
  mode = input( argv[1] );
  range = input( argv[2] );
  total = input( argv[3] );
  

#if (DEBUG == TRUE)
  printf("\n\nDEBUGMESSGE:\nmode=%d range=%d total=%d\n\n", mode,range,total);
#endif
 
  /* Initialize variables */
  num_buf = 0;  
  remainder = total % BUFFER;
  

  /* Seed rand() */
  srand( time(NULL) );

  if( remainder != 0){
    generate( ran_num, remainder, range );
    print( ran_num, remainder, mode );
    puts("\n\n");
  }
  
  if( total >= BUFFER)
    num_buf = (total - remainder)/BUFFER;
  else
    /* total < BUFFER means total equals remainder.
       The remainder has already been printed!
       Setting num_buf to null will thus exit the program.*/
    num_buf = 0;
  
  while( num_buf-- > 0){
    
#if DEBUG == TRUE
    printf("\n\n\nNUM_BUF=%d\n", num_buf);
#endif

    generate( ran_num, BUFFER, range );
    print( ran_num, BUFFER, mode );    
  }
  
  return 0;
  
}
コード例 #10
0
ファイル: n3mc.c プロジェクト: BWHCNI/scope2MIMS
main(int argc, char **argv)
{
	char instr[80], *xs, *ys ;
	int i, j, reading = 1 ;
	double atof();
	int nx[3], ny[3], mx[3], my[3] ;
	int tnx[2], tny[2], tmx[2], tmy[2] ;
	int dx1, dy1, dx2, dy2 ;
	int n = 0 ;

	while(reading){
		printf("> ");
		fgets(instr,79,stdin);
		switch(instr[0]){
			default: helpmsg(); break ;
			case 'q': reading = 0 ; break ;
			break ;

			case 'a':
				if(n < 3) {
					printf("Enter Nikon TiePoint[%d] X,Y> ", n+1 );
					fgets(instr,79,stdin);
					xs = strtok(instr," ,\t\n");
					ys = strtok(NULL," ,\t\n");
					if(xs && ys){
						dx1 = atoi(xs) ;
						dy1 = atoi(ys) ;
					}else break ;
					printf("Enter MIM's X,Y> ");
					fgets(instr,79,stdin);
					xs = strtok(instr," ,\t\n");
					ys = strtok(NULL," ,\t\n");
					if(xs && ys){
						dx2 = atoi(xs) ;
						dy2 = atoi(ys) ;
					}else break ;
					nx[n] = dx1 ;
					ny[n] = dy1 ;
					mx[n] = dx2 ;
					my[n] = dy2 ;
					n++ ;
					printf("Point[%d] Nikon %d,%d Mims %d,%d\n",
						n, dx1,dy1, dx2,dy2);
				}else fprintf(stderr,"You have 3 points. Use 'd' to delete one first\n");
			break ;

			case 't':
				if(n < 3) {
					fprintf(stderr,"You have %d Tiepoints points.\n"
						"Use 'a' to append new points or\n"
						"    'r' to read a Tiepoints file.\n", n);
				}else{
					printf("Enter Nikon test point X,Y> ");
					fgets(instr,79,stdin);
					xs = strtok(instr," ,\t\n");
					ys = strtok(NULL," ,\t\n");
					if(xs && ys){
						dx1 = atoi(xs) ;
						dy1 = atoi(ys) ;
					}else break ;

					tnx[0] = dx1 ;
					tny[0] = dy1 ;
					compute_tr_points ( nx, ny, mx, my, tnx, tny, tmx, tmy, 1) ;
					printf("Point Nikon X,Y = %d, %d   Mims X,Y = %d,%d\n",
						dx1,dy1, tmx[0],tmy[0]);
				}
			break ;

			case 'r':
				printf("Enter a filename to read a set of Tiepoints > ");

				fgets(instr,79,stdin);

				if(strlen(instr) > 2) {
					instr[strlen(instr)-1] = '\0';

					if ( read_mims_tiepoints(instr,nx,ny,mx,my ) ){
						fprintf(stderr,"Reading %s Failed\n", instr);

					}else{
						printf("1: Nikon %d,%d - MIMS %d,%d\n", nx[0],ny[0], mx[0],my[0]);
						printf("2: Nikon %d,%d - MIMS %d,%d\n", nx[1],ny[1], mx[1],my[1]);
						printf("3: Nikon %d,%d - MIMS %d,%d\n", nx[2],ny[2], mx[2],my[2]);
					}
				}
			break;

			case 'w':
				if(n < 3){
					fprintf(stderr,"Need 3 tiepoints to write!\n");
					break ;
				}
				printf("Enter a filename to save the coefficients > ");
				fgets(instr,79,stdin);
				if(strlen(instr) > 2){
					instr[strlen(instr)-1] = '\0';
					if( write_mims_tiepoints(instr,nx,ny,mx,my) ) {
						fprintf(stderr,"Writing %s Failed\n", instr);
					}
				}
			break ;
				
			case 'l':
				for(i=0;i<n;i++){
					printf("Point[%d] Nikon %d,%d Mims %d,%d\n",
						i+1, nx[i],ny[i], mx[i],my[i]);
				}
			break ;

			case 'd':
				if(n == 0) break ;
				for(i=0;i<n;i++){
					printf("Point[%d] Nikon %d,%d Mims %d,%d\n",
					i+1, nx[i],ny[i], mx[i],my[i]);
				}
				printf("\nEnter point to delete [a for all]> ");
				fgets(instr,79,stdin);
				if(instr[0] == 'a'){
					n = 0 ;
				}else{
					i = atoi(instr);
					if( i > 0 && i <= n){
						int j,k;
						for(j=i;j<n;j++){
							nx[j-1] = nx[j];
							ny[j-1] = ny[j];
							mx[j-1] = mx[j];
							my[j-1] = my[j];
						}
						n-- ;
					}
					for(i=0;i<n;i++){
						printf("Point[%d] Nikon %d,%d Mims %d,%d\n",
						i+1, nx[i],ny[i], mx[i],my[i]);
					}
				}
			break ;
		}
	}
	return 0 ;
}
コード例 #11
0
ファイル: main.c プロジェクト: eckeman/ossec-hids
/** main **/
int main(int argc, char **argv)
{
    char *user_msg;

    int c = 0, cmdlist = 0;
    char *cmdexport = NULL;
    char *cmdimport = NULL;
    char *cmdbulk = NULL;

    #ifndef WIN32
    char *dir = DEFAULTDIR;
    char *group = GROUPGLOBAL;
    int gid;
    #endif


    /* Setting the name */
    OS_SetName(ARGV0);


    while((c = getopt(argc, argv, "Vhle:r:i:f:")) != -1){
        switch(c){
	        case 'V':
		        print_version();
		        break;
            case 'h':
                helpmsg();
                break;
            case 'd':
                nowDebug();
                break;
            case 'e':
                #ifdef CLIENT
                ErrorExit("%s: You can't export keys on an agent", ARGV0);
                #endif
                if(!optarg)
                    ErrorExit("%s: -e needs an argument",ARGV0);
                cmdexport = optarg;
                break;
            case 'r':
                #ifdef CLIENT
                ErrorExit("%s: You can't remove keys on an agent", ARGV0);
                #endif
                if(!optarg)
                    ErrorExit("%s: -r needs an argument",ARGV0);
	            
                /* Use environment variables already available to remove_agent() */           	
                setenv("OSSEC_ACTION", "r", 1);
                setenv("OSSEC_AGENT_ID", optarg, 1);
                setenv("OSSEC_ACTION_CONFIRMED", "y", 1);
                break;
            case 'i':
                #ifndef CLIENT
                ErrorExit("%s: You can't import keys on the manager.", ARGV0);
                #endif
                if(!optarg)
                    ErrorExit("%s: -i needs an argument",ARGV0);
                cmdimport = optarg;
                break;
            case 'f':
                #ifdef CLIENT
                ErrorExit("%s: You can't bulk generate keys on an agent.", ARGV0);
                #endif
                if(!optarg)
                    ErrorExit("%s: -f needs an argument",ARGV0);
                cmdbulk = optarg;
                printf("Bulk load file: %s\n", cmdbulk);
                break;
            case 'l':
                cmdlist = 1;
                break;
            default:
                helpmsg();
                break;
        }

    }



    /* Getting currently time */
    time1 = time(0);
    restart_necessary = 0;


    #ifndef WIN32
    /* Getting the group name */
    gid = Privsep_GetGroup(group);
    if(gid < 0)
    {
	    ErrorExit(USER_ERROR, ARGV0, "", group);
    }


    /* Setting the group */
    if(Privsep_SetGroup(gid) < 0)
    {
	    ErrorExit(SETGID_ERROR, ARGV0, group);
    }


    /* Chrooting to the default directory */
    if(Privsep_Chroot(dir) < 0)
    {
        ErrorExit(CHROOT_ERROR, ARGV0, dir);
    }


    /* Inside chroot now */
    nowChroot();


    /* Starting signal handler */
    StartSIG2(ARGV0, manage_shutdown);
    #endif


    if(cmdlist == 1)
    {
        list_agents(cmdlist);
        exit(0);
    }
    else if(cmdimport)
    {
        k_import(cmdimport);
        exit(0);
    }
    else if(cmdexport)
    {
        k_extract(cmdexport);
        exit(0);
    }
    else if(cmdbulk)
    {
        k_bulkload(cmdbulk);
        exit(0);
    }



    /* Little shell */
    while(1)
    {
        int leave_s = 0;
        print_banner();

        /* Get ACTION from the environment. If ACTION is specified,
         * we must set leave_s = 1 to ensure that the loop will end */
        user_msg = getenv("OSSEC_ACTION");
        if (user_msg == NULL) {
          user_msg = read_from_user();
        }
        else{
          leave_s = 1;
        }

        /* All the allowed actions */
        switch(user_msg[0])
        {
            case 'A':
            case 'a':
                add_agent();
                break;
            case 'e':
            case 'E':
                k_extract(NULL);
                break;
            case 'i':
            case 'I':
                k_import(NULL);
                break;
            case 'l':
            case 'L':
                list_agents(0);
                break;
            case 'r':
            case 'R':
                remove_agent();
                break;
            case 'q':
            case 'Q':
                leave_s = 1;
                break;
	        case 'V':
		        print_version();
		        break;
            default:
                printf("\n ** Invalid Action ** \n\n");
                break;
        }

        if(leave_s)
        {
            break;
        }

        continue;

    }

    /* Checking if restart message is necessary */
    if(restart_necessary)
    {
        printf(MUST_RESTART);
    }
    else
    {
        printf("\n");
    }
    printf(EXIT);

    return(0);
}
コード例 #12
0
ファイル: clear_stats.c プロジェクト: ospatrol/ospatrol
/** main **/
int main(int argc, char **argv)
{
    int clear_daily = 0;
    int clear_weekly = 0;

    char *dir = DEFAULTDIR;
    char *group = GROUPGLOBAL;
    char *user = USER;
    int gid;
    int uid;


    /* Setting the name */
    OS_SetName(ARGV0);


    /* user arguments */
    if(argc != 2)
    {
        helpmsg();
    }

    /* Getting the group name */
    gid = Privsep_GetGroup(group);
    uid = Privsep_GetUser(user);
    if(gid < 0)
    {
	    ErrorExit(USER_ERROR, ARGV0, user, group);
    }
	

    /* Setting the group */
    if(Privsep_SetGroup(gid) < 0)
    {
	    ErrorExit(SETGID_ERROR,ARGV0, group);
    }


    /* Chrooting to the default directory */
    if(Privsep_Chroot(dir) < 0)
    {
        ErrorExit(CHROOT_ERROR, ARGV0, dir);
    }


    /* Inside chroot now */
    nowChroot();


    /* Setting the user */
    if(Privsep_SetUser(uid) < 0)
    {
        ErrorExit(SETUID_ERROR, ARGV0, user);
    }

    /* User options */
    if(strcmp(argv[1], "-h") == 0)
    {
        helpmsg();
    }
    else if(strcmp(argv[1], "-a") == 0)
    {
        clear_daily = 1;
        clear_weekly = 1;
    }
    else if(strcmp(argv[1], "-d") == 0)
    {
        clear_daily = 1;
    }
    else if(strcmp(argv[1], "-w") == 0)
    {
        clear_weekly = 1;
    }
    else
    {
        printf("\n** Invalid option '%s'.\n", argv[1]);
        helpmsg();
    }


    /* Clear daily files */
    if(clear_daily)
    {
        char *daily_dir = STATQUEUE;
        DIR *daily;
        struct dirent *entry;

        daily = opendir(daily_dir);
        if(!daily)
        {
            ErrorExit("%s: Unable to open: '%s'", ARGV0, daily_dir);
        }

        while((entry = readdir(daily)) != NULL)
        {
            char full_path[OS_MAXSTR +1];

            /* Do not even attempt to delete . and .. :) */
            if((strcmp(entry->d_name,".") == 0)||
               (strcmp(entry->d_name,"..") == 0))
            {
                continue;
            }

            /* Remove file */
            full_path[OS_MAXSTR] = '\0';
            snprintf(full_path, OS_MAXSTR, "%s/%s", daily_dir, entry->d_name);
            unlink(full_path);
        }

        closedir(daily);
    }


    /* Clear weekly averages */
    if(clear_weekly)
    {
        int i = 0;
        while(i <= 6)
        {
            char *daily_dir = STATWQUEUE;
            char dir_path[OS_MAXSTR +1];
            DIR *daily;
            struct dirent *entry;

            snprintf(dir_path, OS_MAXSTR, "%s/%d", daily_dir, i);
            daily = opendir(dir_path);
            if(!daily)
            {
                ErrorExit("%s: Unable to open: '%s' (no stats)",
                           ARGV0, dir_path);
            }

            while((entry = readdir(daily)) != NULL)
            {
                char full_path[OS_MAXSTR +1];

                /* Do not even attempt to delete . and .. :) */
                if((strcmp(entry->d_name,".") == 0)||
                        (strcmp(entry->d_name,"..") == 0))
                {
                    continue;
                }

                /* Remove file */
                full_path[OS_MAXSTR] = '\0';
                snprintf(full_path, OS_MAXSTR, "%s/%s", dir_path,
                                                        entry->d_name);
                unlink(full_path);
            }

            i++;
            closedir(daily);
        }
    }

    printf("\n** Internal stats clear.\n\n");
    return(0);
}
コード例 #13
0
/** main **/
int main(int argc, char **argv)
{
    char *dir = DEFAULTDIR;
    char *group = GROUPGLOBAL;
    char *user = USER;
    int gid;
    int uid;
    

    /* Setting the name */
    OS_SetName(ARGV0);
        
    
    /* user arguments */
    if(argc < 2)
    {
        helpmsg();
    }
    
    /* Getting the group name */
    gid = Privsep_GetGroup(group);
    uid = Privsep_GetUser(user);
    if(gid < 0)
    {
	    ErrorExit(USER_ERROR, ARGV0, user, group);
    }
	
    
    /* Setting the group */
    if(Privsep_SetGroup(gid) < 0)
    {
	    ErrorExit(SETGID_ERROR,ARGV0, group);
    }
    
    
    /* Chrooting to the default directory */
    if(Privsep_Chroot(dir) < 0)
    {
        ErrorExit(CHROOT_ERROR, ARGV0, dir);
    }


    /* Inside chroot now */
    nowChroot();
 

    /* Setting the user */
    if(Privsep_SetUser(uid) < 0)
    {
        ErrorExit(SETUID_ERROR, ARGV0, user);
    }
  
    /* User options */
    if(strcmp(argv[1], "-h") == 0)
    {
        helpmsg();
    }
    else if(strcmp(argv[1], "-l") == 0)
    {
        printf("\nOSSEC HIDS %s: Updates the integrity check database.", 
                                 ARGV0);
        print_agents(0, 0, 0);
        printf("\n");
        exit(0);
    }
    else if(strcmp(argv[1], "-u") == 0)
    {
        if(argc != 3)
        {
            printf("\n** Option -u requires an extra argument\n");
            helpmsg();
        }
    }
    else if(strcmp(argv[1], "-a") == 0)
    {
        DIR *sys_dir;
        struct dirent *entry;

        sys_dir = opendir(SYSCHECK_DIR);
        if(!sys_dir)
        {
            ErrorExit("%s: Unable to open: '%s'", ARGV0, SYSCHECK_DIR);
        }

        while((entry = readdir(sys_dir)) != NULL)
        {
            FILE *fp;
            char full_path[OS_MAXSTR +1];

            /* Do not even attempt to delete . and .. :) */
            if((strcmp(entry->d_name,".") == 0)||
               (strcmp(entry->d_name,"..") == 0))
            {
                continue;
            }

            snprintf(full_path, OS_MAXSTR,"%s/%s", SYSCHECK_DIR, entry->d_name);
            
            fp = fopen(full_path, "w");
            if(fp)
            {
                fclose(fp);
            }
            if(entry->d_name[0] == '.')
            {
                unlink(full_path);
            }
        }

        closedir(sys_dir);
        printf("\n** Integrity check database updated.\n\n"); 
        exit(0);
    }
    else
    {
        printf("\n** Invalid option '%s'.\n", argv[1]);
        helpmsg();
    }

    
    /* local */
    if(strcmp(argv[2],"local") == 0)
    {
        char final_dir[1024];
        FILE *fp;
        snprintf(final_dir, 1020, "/%s/syscheck", SYSCHECK_DIR);
        
        fp = fopen(final_dir, "w");
        if(fp)
        {
            fclose(fp);
        }
        unlink(final_dir);


        /* Deleting cpt file */
        snprintf(final_dir, 1020, "/%s/.syscheck.cpt", SYSCHECK_DIR);
        
        fp = fopen(final_dir, "w");
        if(fp)
        {
            fclose(fp);
        }
        /* unlink(final_dir); */
    }

    /* external agents */
    else
    {
        int i;
        keystore keys;

        OS_ReadKeys(&keys);

        i = OS_IsAllowedID(&keys, argv[2]);
        if(i < 0)
        {
            printf("\n** Invalid agent id '%s'.\n", argv[2]);
            helpmsg();
        }
        
        /* Deleting syscheck */
        delete_syscheck(keys.keyentries[i]->name,keys.keyentries[i]->ip->ip,0);
    }
   
    printf("\n** Integrity check database updated.\n\n"); 
    return(0);
}
コード例 #14
0
ファイル: list_agents.c プロジェクト: Ar0xA/ossec-hids
/** main **/
int main(int argc, char **argv)
{
    char *dir = DEFAULTDIR;
    char *group = GROUPGLOBAL;
    char *user = USER;

    char *msg;
    char **agent_list;
    int gid;
    int uid;
    int flag = 0;


    /* Setting the name */
    OS_SetName(ARGV0);


    /* user arguments */
    if(argc < 2)
    {
        helpmsg();
    }

    /* Getting the group name */
    gid = Privsep_GetGroup(group);
    uid = Privsep_GetUser(user);
    if(gid < 0)
    {
	    ErrorExit(USER_ERROR, ARGV0, user, group);
    }


    /* Setting the group */
    if(Privsep_SetGroup(gid) < 0)
    {
	    ErrorExit(SETGID_ERROR,ARGV0, group);
    }


    /* Chrooting to the default directory */
    if(Privsep_Chroot(dir) < 0)
    {
        ErrorExit(CHROOT_ERROR, ARGV0, dir);
    }


    /* Inside chroot now */
    nowChroot();


    /* Setting the user */
    if(Privsep_SetUser(uid) < 0)
    {
        ErrorExit(SETUID_ERROR, ARGV0, user);
    }

    /* User options */
    if(strcmp(argv[1], "-h") == 0)
    {
        helpmsg();
    }
    else if(strcmp(argv[1], "-a") == 0)
    {
        flag = GA_ALL;
        msg = "is available.";
    }
    else if(strcmp(argv[1], "-c") == 0)
    {
        flag = GA_ACTIVE;
        msg = "is active.";
    }
    else if(strcmp(argv[1], "-n") == 0)
    {
        flag = GA_NOTACTIVE;
        msg = "is not active.";
    }
    else
    {
        printf("\n** Invalid option '%s'.\n", argv[1]);
        helpmsg();
    }


    agent_list = get_agents(flag);
    if(agent_list)
    {
        char **agent_list_pt = agent_list;

        while(*agent_list)
        {
            printf("%s %s\n", *agent_list, msg);
            agent_list++;
        }

        free_agents(agent_list_pt);
    }
    else
    {
        printf("** No agent available.\n");
    }
    return(0);
}
コード例 #15
0
ファイル: agt2agx.c プロジェクト: BPaden/garglk
int main(int argc,char *argv[])
{
  int i;
  char *gamefile;
  fc_type fc, fc_out;

  end_cmd_options=0;

  init_flags();

  no_auxsyn=1;
  fix_ascii_flag=0;  /* We don't want to translate the character
			set when we're converting files */

  /* Mark all of the purity settings as "undecided" */
  PURE_ANSWER=PURE_TIME=PURE_ROOMTITLE=2;
  PURE_AND=PURE_METAVERB=PURE_SYN=PURE_NOUN=PURE_ADJ=2;
  PURE_DUMMY=PURE_SUBNAME=PURE_PROSUB=PURE_HOSTILE=2;
  PURE_GETHOSTILE=PURE_DISAMBIG=PURE_ALL=2;
  irun_mode=verboseflag=2;

  build_trans_ascii();

  printf("agt2agx: Convert AGT game files into AGX files\n");
  printf("%s\n",version_str);
  printf("  Copyright (C) 1996-1999,2001 Robert Masenten\n");
  printf("[%s]\n\n",portstr);

  outname=gamefile=NULL;
  for(i=1;i<argc;i++)
    if (argv[i][0]=='-' && !end_cmd_options)
      i+=parse_options(argv[i]+1,argv[i+1]);
    else if (gamefile==NULL)
      gamefile=argv[i];
    else {helpmsg();exit(EXIT_FAILURE);}
  if (gamefile==NULL)
    {helpmsg();exit(EXIT_FAILURE);}
  if (outname==NULL)
    outname=gamefile; /* By default use gamefile name for output name */

  fc=init_file_context(gamefile,fDA1);
  fc_out=init_file_context(outname,fAGX);
  text_file=1;
  read_config(openfile(fc,fCFG,NULL,0),0);
  text_file=0;
  printf("Reading AGT file...\n");
  if (!readagt(fc,0))
    fatal("Unable to open info (DA1) or AGX file.");
  text_file=1;
  read_config(openfile(fc,fCFG,NULL,0),1);
  text_file=0;

  sort_cmd();
  truncate_cmd();

  printf("Opening AGX file and copying description text...\n");
  agx_create(fc_out);
  descr_out(fc);
  printf("Writing AGX file...\n");
  agx_write();
  agx_wclose();

  free_all_agtread();

  return 0;
}
コード例 #16
0
int
main(int argc, char **argv)
{
    int i;
    char *device;
    char *rasname;
    int physport;
    int ptyiosize;
    int netiosize;
    int retrydelay;
    int retry, nretries;
    int opt;
    int retst;
    int devmodem;
    int closemode;
    int baseport;
    struct sockaddr_un control_addr;
    struct sigaction act;
    struct stat stat_buf;

    act.sa_handler = SIG_IGN;
    if (sigaction(SIGPIPE, &act, NULL))
        sysmessage(MSG_ERR, "Can't block SIGPIPE.\n");

    ptyiosize = DEV_DEFIOSZ;
    netiosize = SOCK_DEFIOSZ;
    retrydelay = RETRY_DELAY;
    nretries = NUM_RETRIES;
    Nvt.servertype = SRV_RTELNET;
    devmodem = DEV_MODEM;
    closemode = CLOSE_HANG;
    baseport = 0;

    Console = FALSE;
    Foreground = FALSE;
    LogFile = NULL;

    Pgname = argv[0];
    Debug = 0;

    while ((opt = getopt(argc, argv, "u:n:r:fi:st:m:c:p:d:xvhHl:")) != EOF) {
        switch (opt) {
        case 'u':
            ptyiosize = atoi(optarg);
            if (ptyiosize > DEV_MAXIOSZ) {
                ptyiosize = DEV_MAXIOSZ;
            }
            break;
        case 'n':
            netiosize = atoi(optarg);
            if (netiosize > SOCK_MAXIOSZ) {
                netiosize = SOCK_MAXIOSZ;
            }
            break;
        case 'r':
            nretries = atoi(optarg);
            break;
        case 'f':
            Foreground = TRUE;
            break;
        case 'i':
            retrydelay = atoi(optarg) * 1000;
            break;
        case 's':
            Nvt.servertype = SRV_SOCKET;
            if (!baseport)
                baseport = SOCKET_BASE;
            break;
        case 'm':
            devmodem = atoi(optarg);
            break;
        case 'c':
            closemode = atoi(optarg);
            break;
        case 'p':
            baseport = atoi(optarg);
            break;
        case 'd':
            Debug = atoi(optarg);
            break;
        case 'x':
            Console = TRUE;
            Foreground = TRUE;
            break;
        case 'v':
            printf("%s\n", Version);
            exit(E_NORMAL);
        case 'l':
            LogFile = strdup(optarg);
            break;
        case 'h':
        case 'H':
        default:
            helpmsg();
            exit(E_PARMINVAL);
        }
    }
    if (!baseport)
        baseport = RTELNET_BASE;

    argc -= optind;
    argv += optind;

    if (argc != 3) {
        helpmsg();
        exit(E_PARMINVAL);
    }

    device = argv[0];

    mkidmsg(Pgname, device);

    rasname = argv[1];

    physport = atoi(argv[2]);

    if (physport == 0) {
        if (Nvt.servertype == SRV_RTELNET) {
            baseport = RTELNET_STD;
        }
        else {
            fprintf(stderr,
                    "%s: Physical port must be > 0 for socket service\n",
                    Idmsg);
            exit(E_PARMINVAL);
        }
    }

    init_system();

    /* Get socket and device addresses */

    if ((retst = dev_getaddr(device)) != E_NORMAL) {
        exit(retst);
    }

    if (Nvt.servertype == SRV_RTELNET) {
        P_contr_listen = socket(PF_UNIX, SOCK_STREAM, 0);
        if (P_contr_listen == -1) {
            sysmessage(MSG_ERR, "Can't create Unix socket.\n");
            exit(1);
        }
        control_addr.sun_family = AF_UNIX;
        snprintf(P_contrname, sizeof(P_contrname), "%s.control", device);
        P_contrname[sizeof(P_contrname) - 1] = '\0';
        if (!stat(P_contrname, &stat_buf)) {
            sysmessage(MSG_WARNING, "Removing old control socket \"%s\".\n",
                       P_contrname);
            unlink(P_contrname);
        }
        strcpy(control_addr.sun_path, P_contrname);
        if (bind
                (P_contr_listen, (struct sockaddr *) &control_addr,
                 sizeof(control_addr)) || listen(P_contr_listen, 8)) {
            sysmessage(MSG_ERR, "Can't bind Unix socket.\n");
            exit(1);
        }
        for (i = 0; i < MAX_CONTROL_SOCKS; i++)
            P_contr[i] = -1;
    }

    if ((retst = sock_getaddr(rasname, baseport, physport)) != E_NORMAL)
        exit(retst);


    retry = 0;

    if (!Foreground)
        daemon(0, 0);

    while (retry < nretries) {

        if (retry) {
            if (retrydelay) {
                sysdelay(retrydelay);
            }
            sysmessage(MSG_WARNING, "Trying again ... \n");
        }


        if ((retst = sock_link(netiosize)) != E_NORMAL) {
            if (retst != E_CONNECT) {
                doexit(retst);
            }
            retry++;
            continue;
        }

        retry = 0;

        tsr_init(netiosize, ptyiosize, devmodem, closemode);

        /* Main scheduler */

        tsr_io();

        retry++;
    }

    sysmessage(MSG_ERR, "Exiting ...\n");

    doexit(E_RETRYEND);

    /* Not Reached */
    return 0;			/* gcc gives a warning otherwise */
}
コード例 #17
0
ファイル: main.c プロジェクト: folpindo/ossec-hids
/** main **/
int main(int argc, char **argv)
{
    char *user_msg;

    int c = 0, cmdlist = 0;
    char *cmdexport = NULL;
    char *cmdimport = NULL;
    char *cmdbulk = NULL;

    #ifndef WIN32
    char *dir = DEFAULTDIR;
    char *group = GROUPGLOBAL;
    int gid;
    #else
    FILE *fp;
    TCHAR path[2048];
    DWORD last_error;
    int ret;
    #endif


    /* Setting the name */
    OS_SetName(ARGV0);


    while((c = getopt(argc, argv, "Vhle:r:i:f:")) != -1){
        switch(c){
            case 'V':
                print_version();
                break;
            case 'h':
                helpmsg();
                break;
            case 'e':
                #ifdef CLIENT
                ErrorExit("%s: Key export only available on a master.", ARGV0);
                #endif
                if(!optarg)
                    ErrorExit("%s: -e needs an argument.", ARGV0);
                cmdexport = optarg;
                break;
            case 'r':
                #ifdef CLIENT
                ErrorExit("%s: Key removal only available on a master.", ARGV0);
                #endif
                if(!optarg)
                    ErrorExit("%s: -r needs an argument.", ARGV0);

                /* Use environment variables already available to remove_agent() */
                setenv("OSSEC_ACTION", "r", 1);
                setenv("OSSEC_AGENT_ID", optarg, 1);
                setenv("OSSEC_ACTION_CONFIRMED", "y", 1);
                break;
            case 'i':
                #ifndef CLIENT
                ErrorExit("%s: Key import only available on an agent.", ARGV0);
                #endif
                if(!optarg)
                    ErrorExit("%s: -i needs an argument.", ARGV0);
                cmdimport = optarg;
                break;
            case 'f':
                #ifdef CLIENT
                ErrorExit("%s: Bulk generate keys only available on a master.", ARGV0);
                #endif
                if(!optarg)
                    ErrorExit("%s: -f needs an argument.", ARGV0);
                cmdbulk = optarg;
                printf("Bulk load file: %s\n", cmdbulk);
                break;
            case 'l':
                cmdlist = 1;
                break;
            default:
                helpmsg();
                break;
        }

    }



    /* Get current time */
    time1 = time(0);
    restart_necessary = 0;


    #ifndef WIN32
    /* Getting the group name */
    gid = Privsep_GetGroup(group);
    if(gid < 0)
    {
        ErrorExit(USER_ERROR, ARGV0, "", group);
    }


    /* Setting the group */
    if(Privsep_SetGroup(gid) < 0)
    {
        ErrorExit(SETGID_ERROR, ARGV0, group);
    }


    /* Chrooting to the default directory */
    if(Privsep_Chroot(dir) < 0)
    {
        ErrorExit(CHROOT_ERROR, ARGV0, dir);
    }


    /* Inside chroot now */
    nowChroot();


    /* Starting signal handler */
    StartSIG2(ARGV0, manage_shutdown);

    #else

    /* Get full path to the directory this
     * executable lives in
     */
    ret = GetModuleFileName(NULL, path, sizeof(path));

    /* check for errors */
    if(!ret)
    {
        ErrorExit(GMF_ERROR);
    }

    /* Get last error */
    last_error = GetLastError();

    /* Look for errors */
    if(last_error != ERROR_SUCCESS)
    {
        if(last_error == ERROR_INSUFFICIENT_BUFFER)
        {
            ErrorExit(GMF_BUFF_ERROR, ret, sizeof(path));
        }
        else
        {
            ErrorExit(GMF_UNKN_ERROR, last_error);
        }
    }

    /* Remove file name from path */
    PathRemoveFileSpec(path);

    /* Move to correct directory */
    if(chdir(path))
    {
        ErrorExit(CHDIR_ERROR_2, path);
    }

    /* Check permissions */
    fp = fopen(OSSECCONF, "r");
    if(fp)
    {
        fclose(fp);
    }
    else
    {
        ErrorExit(CONF_ERROR, OSSECCONF);
    }

    #endif

    if(cmdlist == 1)
    {
        list_agents(cmdlist);
        exit(0);
    }
    else if(cmdimport)
    {
        k_import(cmdimport);
        exit(0);
    }
    else if(cmdexport)
    {
        k_extract(cmdexport);
        exit(0);
    }
    else if(cmdbulk)
    {
        k_bulkload(cmdbulk);
        exit(0);
    }



    /* Little shell */
    while(1)
    {
        int leave_s = 0;
        print_banner();

        /* Get ACTION from the environment. If ACTION is specified,
         * we must set leave_s = 1 to ensure that the loop will end */
        user_msg = getenv("OSSEC_ACTION");
        if (user_msg == NULL) {
          user_msg = read_from_user();
        }
        else{
          leave_s = 1;
        }

        /* All the allowed actions */
        switch(user_msg[0])
        {
            case 'A':
            case 'a':
                add_agent();
                break;
            case 'e':
            case 'E':
                k_extract(NULL);
                break;
            case 'i':
            case 'I':
                k_import(NULL);
                break;
            case 'l':
            case 'L':
                list_agents(0);
                break;
            case 'r':
            case 'R':
                remove_agent();
                break;
            case 'q':
            case 'Q':
                leave_s = 1;
                break;
	        case 'V':
		        print_version();
		        break;
            default:
                printf("\n ** Invalid Action ** \n\n");
                break;
        }

        if(leave_s)
        {
            break;
        }

        continue;

    }

    /* Checking if restart message is necessary */
    if(restart_necessary)
    {
        printf(MUST_RESTART);
    }
    else
    {
        printf("\n");
    }
    printf(EXIT);

    return(0);
}
コード例 #18
0
ファイル: absint.c プロジェクト: jkeiren/muCRL
/*--------------------------------------------------------------------------*/
static void parseCommandLine(int argc, char *argv[]){
	int i = 0, j;
	
	P("Abstract Interpreter for mCRL Specifications");
	for (i=1;i<argc;i++) {
	  if (!strcmp(argv[i - 1],"-P")){
	  		BUT_PAR = ATfalse;
			tokParameters(argv[i]);
	  		continue;
	  } 
	  if (!strcmp(argv[i],"-Pall")){	
	  		BUT_PAR = ATfalse;
			continue;
	  } 
	  if (!strcmp(argv[i-1],"-PallBut")){	
	  		BUT_PAR = ATtrue;
	  		tokParameters(argv[i]);
			continue;
	  } 
	  if (!strcmp(argv[i-1],"-VallBut")){	
	  		BUT_VAR = ATtrue;
	  		ALL_VAR = ATfalse;
	  		tokVars(argv[i]);
			continue;
	  } 
	  if (!strcmp(argv[i - 1],"-V")){
	  		BUT_VAR = ATfalse;
	  		ALL_VAR = ATfalse;
	  		tokVars(argv[i]);
	  		continue;
	  } 
	  if (!strcmp(argv[i],"-Vall")){	
	  		BUT_VAR = ATfalse;
	  		ALL_VAR = ATtrue;
			continue;
	  } 
	  if (!strcmp(argv[i-1],"-VallBut")){	
	  		BUT_VAR = ATtrue;
	  		ALL_VAR = ATfalse;
	  		tokVars(argv[i]);
			continue;
	  } 
	  if (!strcmp(argv[i - 1],"-S")){
	  		BUT_SORT = ATfalse;
	  		tokSorts(argv[i]);
	  		continue;
	  } 
	  if (!strcmp(argv[i - 1],"-SallBut")){
	  		BUT_SORT = ATtrue;
	  		tokSorts(argv[i]);
	  		continue;
	  } 
	  if (!strcmp(argv[i],"-H")){
	  		HOMOMORPHISM = ATtrue;
	  		GALOIS = ATfalse;
	  		LIFTEDHOMO = ATfalse;
         continue;
	  }
	  if (!strcmp(argv[i],"-lH")){
	  		HOMOMORPHISM = ATfalse;
	  		GALOIS = ATfalse;
	  		LIFTEDHOMO = ATtrue;
         continue;
	  }
	  if (!strcmp(argv[i],"-G")){
	  		HOMOMORPHISM = ATfalse; 
	  		GALOIS = ATtrue;
	  		LIFTEDHOMO = ATfalse; 
         continue;
		} 
	  if (!strcmp(argv[i],"-help")){
	  		helpmsg();
    		exit(0);
	  }
	  if (!strcmp(argv[i],"-May")){
	  	   MUST = ATfalse;
			continue;
		}
	  if (!strcmp(argv[i],"-Must")){
	  		MAY = ATfalse;
      	continue;
		}
	  if (!strcmp(argv[i],"-Debug")){
	  		DEBUG = ATtrue;
      	continue;
		}
	  if (!strcmp(argv[i],"-Order")){
	  		setOrder();
      	continue;
		}
	} 	
	if(HOMOMORPHISM)
		P("Abstraction Type: HOMOMORPHISM");
	if(LIFTEDHOMO)
		P("Abstraction Type: LIFTED HOMOMORPHISM");
	if(GALOIS){
		setGalois();
		P("Abstraction Type: GALOIS CONNECTION");
	}
}
コード例 #19
0
/** main **/
int main(int argc, char **argv)
{
    char *pattern;
    
    char msg[OS_MAXSTR +1];
    memset(msg, '\0', OS_MAXSTR +1);
    OSRegex regex; 
    OSMatch matcher; 

    OS_SetName(ARGV0);
        
    
    /* user arguments */
    if(argc != 2)
    {
        helpmsg();
        return(-1);
    }
    
    /* User options */
    if(strcmp(argv[1], "-h") == 0)
    {
        helpmsg();
        return(-1);
    }

    os_strdup(argv[1], pattern);
    if(!OSRegex_Compile(pattern, &regex, 0)) 
    { 
        printf("pattern does not compile with OSRegex_Compile\n");
        return(-1); 
    }
    if(!OSMatch_Compile(pattern, &matcher, 0))
    {
        printf("pattern does not compile with OSMatch_Compile\n");
        return(-1);
    }


    while((fgets(msg, OS_MAXSTR, stdin)) != NULL)
    {        
        /* Removing new line. */                                                                                                                                       
        if(msg[strlen(msg) -1] == '\n')
            msg[strlen(msg) -1] = '\0';

        /* Make sure we ignore blank lines. */                                                                                                                         
        if(strlen(msg) < 2) { continue; }                                                            

        if(OSRegex_Execute(msg, &regex))
            printf("+OSRegex_Execute: %s\n",msg); 
        /*
        else
            printf("-OSRegex_Execute: \n"); 
            */

        if(OS_Regex(pattern, msg)) 
            printf("+OS_Regex       : %s\n", msg);
        /*
        else
            printf("-OS_Regex: \n"); 
            */

        if(OSMatch_Execute(msg, strlen(msg), &matcher)) 
            printf("+OSMatch_Compile: %s\n", msg); 
        
        if(OS_Match2(pattern, msg)) 
            printf("+OS_Match2      : %s\n", msg); 
    }
    return(0);
}