예제 #1
0
void test_wlan_add(int argc, char **argv)
{
	struct wlan_network network;
	int ret = 0;
	int arg = 1;
	struct {
		unsigned ssid:1;
		unsigned bssid:1;
		unsigned channel:1;
		unsigned address:2;
		unsigned security:1;
		unsigned role:1;
	} info;

	memset(&info, 0, sizeof(info));
	memset(&network, 0, sizeof(struct wlan_network));

	if (argc < 4) {
		dump_wlan_add_usage();
		wmprintf("Error: invalid number of arguments\r\n");
		return;
	}

	if (strlen(argv[arg]) >= WLAN_NETWORK_NAME_MAX_LENGTH) {
		wmprintf("Error: network name too long\r\n");
		return;
	}

	memcpy(network.name, argv[arg], strlen(argv[arg]));
	arg++;
	info.address = ADDR_TYPE_DHCP;
	do {
		if (!info.ssid && string_equal("ssid", argv[arg])) {
			if (strlen(argv[arg + 1]) > IEEEtypes_SSID_SIZE) {
				wmprintf("Error: SSID is too long\r\n");
				return;
			}
			memcpy(network.ssid, argv[arg + 1],
			       strlen(argv[arg + 1]));
			arg += 2;
			info.ssid = 1;
		} else if (!info.bssid && string_equal("bssid", argv[arg])) {
			ret = get_mac(argv[arg + 1], network.bssid, ':');
			if (ret) {
				wmprintf("Error: invalid BSSID argument"
					"\r\n");
				return;
			}
			arg += 2;
			info.bssid = 1;
		} else if (!info.channel && string_equal("channel", argv[arg])) {
			if (arg + 1 >= argc ||
			    get_uint(argv[arg + 1], &network.channel,
				     strlen(argv[arg + 1]))) {
				wmprintf("Error: invalid channel"
					" argument\n");
				return;
			}
			arg += 2;
			info.channel = 1;
		} else if (!strncmp(argv[arg], "ip:", 3)) {
			ret = get_address(argv[arg], &network.address);
			if (ret) {
				wmprintf("Error: invalid address"
					" argument\n");
				return;
			}
			arg++;
			info.address = ADDR_TYPE_STATIC;
		} else if (!info.security && string_equal("wep", argv[arg])) {
			ret =
				get_security(argc - arg - 1,
					     (char **)(argv + arg + 1),
					     WLAN_SECURITY_WEP_OPEN,
					     &network.security);
			if (ret) {
				wmprintf("Error: invalid WEP security"
					" argument\r\n");
				return;
			}
			arg += 3;
			info.security++;
		} else if (!info.security && string_equal("wpa", argv[arg])) {
			ret =
			    get_security(argc - arg - 1, argv + arg + 1,
					 WLAN_SECURITY_WPA, &network.security);
			if (ret) {
				wmprintf("Error: invalid WPA security"
					" argument\r\n");
				return;
			}
			arg += 2;
			info.security++;
		} else if (!info.security && string_equal("wpa2", argv[arg])) {
			ret =
			    get_security(argc - arg - 1, argv + arg + 1,
					 WLAN_SECURITY_WPA2, &network.security);
			if (ret) {
				wmprintf("Error: invalid WPA2 security"
					" argument\r\n");
				return;
			}
			arg += 2;
			info.security++;
		} else if (!info.role && string_equal("role", argv[arg])) {
			if (arg + 1 >= argc ||
			    get_role(argv[arg + 1], &network.role)) {
				wmprintf("Error: invalid wireless"
					" network role\r\n");
				return;
			}
			arg += 2;
			info.role++;
		} else if (!strncmp(argv[arg], "autoip", 6)) {
			info.address = ADDR_TYPE_LLA;
			arg++;
		} else {
			dump_wlan_add_usage();
			wmprintf("Error: argument %d is invalid\r\n", arg);
			return;
		}
	} while (arg < argc);

	if (!info.ssid && !info.bssid) {
		dump_wlan_add_usage();
		wmprintf("Error: specify at least the SSID or BSSID\r\n");
		return;
	}

	network.address.addr_type = info.address;

	ret = wlan_add_network(&network);
	switch (ret) {
	case WLAN_ERROR_NONE:
		wmprintf("Added \"%s\"\r\n", network.name);
		break;
	case WLAN_ERROR_PARAM:
		wmprintf("Error: that network already exists\r\n");
		break;
	case WLAN_ERROR_NOMEM:
		wmprintf("Error: network list is full\r\n");
		break;
	case WLAN_ERROR_STATE:
		wmprintf("Error: can't add networks in this state\r\n");
		break;
	default:
		wmprintf("Error: unable to add network for unknown"
			" reason\r\n");
		break;
	}
}
예제 #2
0
int
main(
    int		argc,
    char **	argv)
{
    in_port_t my_port;
    struct servent *sp;
    int i;
    time_t timer;
    char *lineread = NULL;
    struct sigaction act, oact;
    extern char *optarg;
    extern int optind;
    char cwd[STR_SIZE], *dn_guess = NULL, *mpt_guess = NULL;
    char *service_name;
    char *line = NULL;
    struct tm *tm;

    /*
     * Configure program for internationalization:
     *   1) Only set the message locale for now.
     *   2) Set textdomain for all amanda related programs to "amanda"
     *      We don't want to be forced to support dozens of message catalogs.
     */  
    setlocale(LC_MESSAGES, "C");
    textdomain("amanda"); 

    safe_fd(-1, 0);

    set_pname("amoldrecover");

    /* Don't die when child closes pipe */
    signal(SIGPIPE, SIG_IGN);

    dbopen(DBG_SUBDIR_CLIENT);

    localhost = g_malloc(MAX_HOSTNAME_LENGTH+1);
    if (gethostname(localhost, MAX_HOSTNAME_LENGTH) != 0) {
	error(_("cannot determine local host name\n"));
	/*NOTREACHED*/
    }
    localhost[MAX_HOSTNAME_LENGTH] = '\0';

    g_free(config);
    config = g_strdup(DEFAULT_CONFIG);

    dbrename(config, DBG_SUBDIR_CLIENT);

    check_running_as(RUNNING_AS_ROOT);

    amfree(server_name);
    server_name = getenv("AMANDA_SERVER");
    if(!server_name) server_name = DEFAULT_SERVER;
    server_name = g_strdup(server_name);

    amfree(tape_server_name);
    tape_server_name = getenv("AMANDA_TAPESERVER");
    if(!tape_server_name) tape_server_name = DEFAULT_TAPE_SERVER;
    tape_server_name = g_strdup(tape_server_name);

    config_init(CONFIG_INIT_CLIENT, NULL);

    if (config_errors(NULL) >= CFGERR_WARNINGS) {
	config_print_errors();
	if (config_errors(NULL) >= CFGERR_ERRORS) {
	    g_critical(_("errors processing config file"));
	}
    }

    if (argc > 1 && argv[1][0] != '-')
    {
	/*
	 * If the first argument is not an option flag, then we assume
	 * it is a configuration name to match the syntax of the other
	 * Amanda utilities.
	 */
	char **new_argv;

	new_argv = (char **) g_malloc((size_t)((argc + 1 + 1) * sizeof(*new_argv)));
	new_argv[0] = argv[0];
	new_argv[1] = "-C";
	for (i = 1; i < argc; i++)
	{
	    new_argv[i + 1] = argv[i];
	}
	new_argv[i + 1] = NULL;
	argc++;
	argv = new_argv;
    }
    while ((i = getopt(argc, argv, "C:s:t:d:U")) != EOF)
    {
	switch (i)
	{
	    case 'C':
		g_free(config);
		config = g_strdup(optarg);
		break;

	    case 's':
		g_free(server_name);
		server_name = g_strdup(optarg);
		break;

	    case 't':
		g_free(tape_server_name);
		tape_server_name = g_strdup(optarg);
		break;

	    case 'd':
		g_free(tape_device_name);
		tape_device_name = g_strdup(optarg);
		break;

	    case 'U':
	    case '?':
		(void)g_printf(USAGE);
		return 0;
	}
    }
    if (optind != argc)
    {
	(void)g_fprintf(stderr, USAGE);
	exit(1);
    }

    amfree(disk_name);
    amfree(mount_point);
    amfree(disk_path);
    dump_date[0] = '\0';

    /* Don't die when child closes pipe */
    signal(SIGPIPE, SIG_IGN);

    /* set up signal handler */
    act.sa_handler = sigint_handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
#ifdef SA_RESTORER
    act.sa_restorer = NULL;
#endif
    if (sigaction(SIGINT, &act, &oact) != 0) {
	error(_("error setting signal handler: %s"), strerror(errno));
	/*NOTREACHED*/
    }

    service_name = "amandaidx";

    g_printf(_("AMRECOVER Version %s. Contacting server on %s ...\n"),
	   VERSION, server_name);
    if ((sp = getservbyname(service_name, "tcp")) == NULL) {
	error(_("%s/tcp unknown protocol"), service_name);
	/*NOTREACHED*/
    }
    server_socket = stream_client_privileged(server_name,
					     (in_port_t)ntohs((in_port_t)sp->s_port),
					     0,
					     0,
					     &my_port,
					     0);
    if (server_socket < 0) {
	error(_("cannot connect to %s: %s"), server_name, strerror(errno));
	/*NOTREACHED*/
    }
    if (my_port >= IPPORT_RESERVED) {
        aclose(server_socket);
	error(_("did not get a reserved port: %d"), my_port);
	/*NOTREACHED*/
    }

    /* get server's banner */
    if (grab_reply(1) == -1) {
        aclose(server_socket);
	exit(1);
    }
    if (!server_happy())
    {
	dbclose();
	aclose(server_socket);
	exit(1);
    }

    /* do the security thing */
    line = get_security();
    if (converse(line) == -1) {
        aclose(server_socket);
	exit(1);
    }
    if (!server_happy()) {
        aclose(server_socket);
	exit(1);
    }
    memset(line, '\0', strlen(line));
    amfree(line);

    /* try to get the features from the server */
    {
	char *our_feature_string = NULL;
	char *their_feature_string = NULL;

	our_features = am_init_feature_set();
	our_feature_string = am_feature_to_string(our_features);
	line = g_strconcat("FEATURES ", our_feature_string, NULL);
	if(exchange(line) == 0) {
	    their_feature_string = g_strdup(server_line+13);
	    indexsrv_features = am_string_to_feature(their_feature_string);
	}
	else {
	    indexsrv_features = am_set_default_feature_set();
        }
	amfree(our_feature_string);
	amfree(their_feature_string);
	amfree(line);
    }

    /* set the date of extraction to be today */
    (void)time(&timer);
    tm = localtime(&timer);
    if (tm)
	strftime(dump_date, sizeof(dump_date), "%Y-%m-%d", tm);
    else
	error(_("BAD DATE"));

    g_printf(_("Setting restore date to today (%s)\n"), dump_date);
    line = g_strconcat("DATE ", dump_date, NULL);
    if (converse(line) == -1) {
        aclose(server_socket);
	exit(1);
    }
    amfree(line);

    line = g_strconcat("SCNF ", config, NULL);
    if (converse(line) == -1) {
        aclose(server_socket);
	exit(1);
    }
    amfree(line);

    if (server_happy())
    {
	/* set host we are restoring to this host by default */
	amfree(dump_hostname);
	set_host(localhost);
	if (dump_hostname)
	{
            /* get a starting disk and directory based on where
	       we currently are */
	    switch (guess_disk(cwd, sizeof(cwd), &dn_guess, &mpt_guess))
	    {
		case 1:
		    /* okay, got a guess. Set disk accordingly */
		    g_printf(_("$CWD '%s' is on disk '%s' mounted at '%s'.\n"),
			   cwd, dn_guess, mpt_guess);
		    set_disk(dn_guess, mpt_guess);
		    set_directory(cwd);
		    if (server_happy() && !g_str_equal(cwd, mpt_guess))
		        g_printf(_("WARNING: not on root of selected filesystem, check man-page!\n"));
		    amfree(dn_guess);
		    amfree(mpt_guess);
		    break;

		case 0:
		    g_printf(_("$CWD '%s' is on a network mounted disk\n"),
			   cwd);
		    g_printf(_("so you must 'sethost' to the server\n"));
		    /* fake an unhappy server */
		    server_line[0] = '5';
		    break;

		case 2:
		case -1:
		default:
		    g_printf(_("Use the setdisk command to choose dump disk to recover\n"));
		    /* fake an unhappy server */
		    server_line[0] = '5';
		    break;
	    }
	}
    }

    quit_prog = 0;
    do
    {
	if ((lineread = readline("amrecover> ")) == NULL) {
	    clearerr(stdin);
	    putchar('\n');
	    break;
	}
	if (lineread[0] != '\0') 
	{
	    add_history(lineread);
	    process_line(lineread);	/* act on line's content */
	}
	amfree(lineread);
    } while (!quit_prog);

    dbclose();

    aclose(server_socket);
    return 0;
}
예제 #3
0
파일: acl.c 프로젝트: Rick33/freevms
asmlinkage int exe$get_security_wrap(struct struct_args * s) {
  return exe$get_security(s->s1, s->s2, s->s3, s->s4, s->s5, s->s6, s->s7);
}