Exemple #1
0
// Execution of registration
UINT DCRegister(DDNS_CLIENT *c, bool ipv6, DDNS_REGISTER_PARAM *p, char *replace_v6)
{
	char *url;
	char url2[MAX_SIZE];
	char url3[MAX_SIZE];
	PACK *req, *ret;
	char key_str[MAX_SIZE];
	UCHAR machine_key[SHA1_SIZE];
	char machine_key_str[MAX_SIZE];
	char machine_name[MAX_SIZE];
	BUF *cert_hash = NULL;
	UINT err = ERR_INTERNAL_ERROR;
	UCHAR key_hash[SHA1_SIZE];
	char key_hash_str[MAX_SIZE];
	bool use_azure = false;
	char current_azure_ip[MAX_SIZE];
	INTERNET_SETTING t;
	UINT build = 0;
	bool use_https = false;
	bool use_vgs = false;
	bool no_cert_verify = false;
	char add_header_name[64];
	char add_header_value[64];
	// Validate arguments
	if (c == NULL)
	{
		return ERR_INTERNAL_ERROR;
	}

	Zero(add_header_name, sizeof(add_header_name));
	Zero(add_header_value, sizeof(add_header_value));

	Zero(current_azure_ip, sizeof(current_azure_ip));

	GetCurrentMachineIpProcessHash(machine_key);
	BinToStr(machine_key_str, sizeof(machine_key_str), machine_key, sizeof(machine_key));

	GetMachineHostName(machine_name, sizeof(machine_name));
	StrLower(machine_name);

	if (ipv6 == false)
	{
		url = DDNS_URL_V4_GLOBAL;

		if (IsUseAlternativeHostname())
		{
			url = DDNS_URL_V4_ALT;
		}
	}
	else
	{
		url = DDNS_URL_V6_GLOBAL;

		if (IsUseAlternativeHostname())
		{
			url = DDNS_URL_V6_ALT;
		}

		if (replace_v6)
		{
			url = replace_v6;
		}
	}

	Zero(&t, sizeof(t));
	if (ipv6 == false)
	{
		// Proxy Setting
		Copy(&t, &c->InternetSetting, sizeof(INTERNET_SETTING));
	}

	if (ipv6 == false)
	{
		// Get the current status of the VPN Azure Client
		if (c->Cedar->Server != NULL)
		{
			AZURE_CLIENT *ac = c->Cedar->Server->AzureClient;

			if (ac != NULL)
			{
				use_azure = SiIsAzureEnabled(c->Cedar->Server);

				if (use_azure)
				{
					Lock(ac->Lock);
					{
						StrCpy(current_azure_ip, sizeof(current_azure_ip), ac->ConnectingAzureIp);
					}
					Unlock(ac->Lock);
				}
			}
		}
	}

	req = NewPack();
	BinToStr(key_str, sizeof(key_str), c->Key, sizeof(c->Key));
	StrUpper(key_str);
	PackAddStr(req, "key", key_str);

	// Build Number
	build = c->Cedar->Build;


	PackAddInt(req, "build", build);
	PackAddInt(req, "osinfo", GetOsInfo()->OsType);
	PackAddInt(req, "is_64bit", Is64());
#ifdef	OS_WIN32
	PackAddInt(req, "is_windows_64bit", MsIs64BitWindows());
#endif	// OS_WIN32
	PackAddBool(req, "is_softether", true);
	PackAddBool(req, "is_packetix", false);
	PackAddStr(req, "machine_key", machine_key_str);
	PackAddStr(req, "machine_name", machine_name);
	PackAddInt(req, "lasterror_ipv4", c->Err_IPv4_GetMyIp);
	PackAddInt(req, "lasterror_ipv6", c->Err_IPv6_GetMyIp);
	PackAddBool(req, "use_azure", use_azure);
	PackAddStr(req, "product_str", CEDAR_PRODUCT_STR);
	PackAddInt(req, "ddns_protocol_version", DDNS_VERSION);


	if (use_azure)
	{
		Debug("current_azure_ip = %s\n", current_azure_ip);
		PackAddStr(req, "current_azure_ip", current_azure_ip);
	}

	HashSha1(key_hash, key_str, StrLen(key_str));
	BinToStr(key_hash_str, sizeof(key_hash_str), key_hash, sizeof(key_hash));
	StrLower(key_hash_str);

	if (p != NULL)
	{
		if (IsEmptyStr(p->NewHostname) == false)
		{
			PackAddStr(req, "new_hostname", p->NewHostname);
		}
	}



	Format(url2, sizeof(url2), "%s?v=%I64u", url, Rand64());
	Format(url3, sizeof(url3), url2, key_hash_str[2], key_hash_str[3]);

	if (use_https == false)
	{
		ReplaceStr(url3, sizeof(url3), url3, "https://", "http://");
	}

	ReplaceStr(url3, sizeof(url3), url3, ".servers", ".open.servers");


	if (no_cert_verify == false)
	{
		cert_hash = StrToBin(DDNS_CERT_HASH);
	}

	ret = NULL;


	if (ret == NULL)
	{
		Debug("WpcCall: %s\n", url3);
		ret = WpcCallEx2(url3, &t, DDNS_CONNECT_TIMEOUT, DDNS_COMM_TIMEOUT, "register", req,
			NULL, NULL, ((cert_hash != NULL && ((cert_hash->Size % SHA1_SIZE) == 0)) ? cert_hash->Buf : NULL),
			(cert_hash != NULL ? cert_hash->Size / SHA1_SIZE : 0),
			NULL, DDNS_RPC_MAX_RECV_SIZE,
			add_header_name, add_header_value,
			DDNS_SNI_VER_STRING);
		Debug("WpcCall Ret: %u\n", ret);
	}

	FreeBuf(cert_hash);

	FreePack(req);

	err = GetErrorFromPack(ret);

	ExtractAndApplyDynList(ret);

	// Status update
	Lock(c->Lock);
	{
		if (err == ERR_NO_ERROR)
		{
			char snat_t[MAX_SIZE];
			char current_region[128];

			// Current host name
			PackGetStr(ret, "current_hostname", c->CurrentHostName, sizeof(c->CurrentHostName));
			PackGetStr(ret, "current_fqdn", c->CurrentFqdn, sizeof(c->CurrentFqdn));
			PackGetStr(ret, "current_ipv4", c->CurrentIPv4, sizeof(c->CurrentIPv4));
			PackGetStr(ret, "current_ipv6", c->CurrentIPv6, sizeof(c->CurrentIPv6));
			PackGetStr(ret, "dns_suffix", c->DnsSuffix, sizeof(c->DnsSuffix));
			PackGetStr(ret, "current_region", current_region, sizeof(current_region));

			// SecureNAT connectivity check parameters
			Zero(snat_t, sizeof(snat_t));
			PackGetStr(ret, "snat_t", snat_t, sizeof(snat_t));
			NnSetSecureNatTargetHostname(snat_t);

			if (ipv6 == false)
			{
				char cert_hash[MAX_SIZE];

				PackGetStr(ret, "current_azure_ip", c->CurrentAzureIp, sizeof(c->CurrentAzureIp));
				c->CurrentAzureTimestamp = PackGetInt64(ret, "current_azure_timestamp");
				PackGetStr(ret, "current_azure_signature", c->CurrentAzureSignature, sizeof(c->CurrentAzureSignature));

				Zero(cert_hash, sizeof(cert_hash));
				PackGetStr(ret, "azure_cert_hash", cert_hash, sizeof(cert_hash));

				if (IsEmptyStr(cert_hash) == false)
				{
					StrCpy(c->AzureCertHash, sizeof(c->AzureCertHash), cert_hash);
				}
			}

			StrCpy(c->Cedar->CurrentDDnsFqdn, sizeof(c->Cedar->CurrentDDnsFqdn), c->CurrentFqdn);

			Debug("current_hostname=%s, current_fqdn=%s, current_ipv4=%s, current_ipv6=%s, current_azure_ip=%s, CurrentAzureTimestamp=%I64u, CurrentAzureSignature=%s, CertHash=%s\n",
				c->CurrentHostName, c->CurrentFqdn,
				c->CurrentIPv4, c->CurrentIPv6,
				c->CurrentAzureIp, c->CurrentAzureTimestamp, c->CurrentAzureSignature, c->AzureCertHash);

			if (IsEmptyStr(current_region) == false)
			{
				// Update the current region
				SiUpdateCurrentRegion(c->Cedar, current_region, false);
			}
		}
	}
	Unlock(c->Lock);

	if (IsEmptyStr(c->CurrentFqdn) == false)
	{
		SetCurrentDDnsFqdn(c->CurrentFqdn);
	}


	FreePack(ret);

	UniDebug(L"DCRegister Error: %s\n", _E(err));

	if (err == ERR_DUPLICATE_DDNS_KEY)
	{
		// Key duplication
		DCGenNewKey(c->Key);
		c->KeyChanged = true;
	}

	if (err == ERR_DISCONNECTED)
	{
		err = ERR_DDNS_DISCONNECTED;
	}

	if (IsUseAlternativeHostname() == false)
	{
		if (err == ERR_CONNECT_FAILED)
		{
			if (ipv6 && replace_v6 == NULL)
			{
				UINT type = DetectFletsType();

				if (type & FLETS_DETECT_TYPE_EAST_BFLETS_PRIVATE && err != ERR_NO_ERROR)
				{
					err = DCRegister(c, ipv6, p, DDNS_REPLACE_URL_FOR_EAST_BFLETS);
				}

				if (type & FLETS_DETECT_TYPE_EAST_NGN_PRIVATE && err != ERR_NO_ERROR)
				{
					err = DCRegister(c, ipv6, p, DDNS_REPLACE_URL_FOR_EAST_NGN);
				}

				if (type & FLETS_DETECT_TYPE_WEST_NGN_PRIVATE && err != ERR_NO_ERROR)
				{
					err = DCRegister(c, ipv6, p, DDNS_REPLACE_URL_FOR_WEST_NGN);
				}
			}
		}
	}

	return err;
}
/*----------------------------------------------------------------------
            Parameters:

           Description:
----------------------------------------------------------------------*/
static int
get_option(int argc, char *argv[]) {
  int  nargs = 0 ;
  char *option ;

  option = argv[1] + 1 ;            /* past '-' */
  StrUpper(option) ;
  if (!stricmp(option, "DIST") || !stricmp(option, "DISTANCE")) {
    parms.l_dist = atof(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "l_dist = %2.2f\n", parms.l_dist) ;
  } else if (!stricmp(option, "DT")) {
    parms.dt = atof(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "dt = %2.2e\n", parms.dt) ;
  } else if (!stricmp(option, "INVERT")) {
    invert_flag = 1 ;
    fprintf(stderr, "inverting transform before writing...\n") ;
  } else if (!stricmp(option, "crop")) {
    check_crop_flag = 1 ;
    nargs = 1 ;
    fprintf(stderr, "checking for cropping....\n") ;
  } else if (!stricmp(option, "nlevels")) {
    parms.max_levels = atoi(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "nlevels = %d\n", parms.max_levels) ;
  } else if (!stricmp(option, "image_size")) {
    IMAGE_SIZE = atoi(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "setting default image size to %d\n", IMAGE_SIZE) ;
  } else if (!stricmp(option, "TOL")) {
    parms.tol = atof(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "tol = %2.2e\n", parms.tol) ;
  } else if (!stricmp(option, "NUM")) {
    num_xforms = atoi(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "finding a total of %d linear transforms\n", num_xforms) ;
  } else if (!stricmp(option, "SCOUT")) {
    parms.scout_flag = 1 ;
    printf("limitting domain of integration to central slices...\n") ;
  } else if (!stricmp(option, "AREA")) {
    parms.l_area = atof(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "l_area = %2.2f\n", parms.l_area) ;
  } else if (!stricmp(option, "WINDOW")) {
    window_size = atof(argv[2]) ;
    fprintf(stderr, "applying Hanning window (R=%2.1f) to images...\n",
            window_size) ;
    nargs = 1 ;
  } else if (!stricmp(option, "NLAREA")) {
    parms.l_nlarea = atof(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "l_nlarea = %2.2f\n", parms.l_nlarea) ;
  } else if (!stricmp(option, "LEVELS")) {
    parms.levels = atoi(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "levels = %d\n", parms.levels) ;
  } else if (!stricmp(option, "INTENSITY") || !stricmp(option, "CORR")) {
    parms.l_intensity = atof(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "l_intensity = %2.2f\n", parms.l_intensity) ;
  } else if (!stricmp(option, "thresh")) {
    thresh_low = atoi(argv[2]) ;
#if 1
    fprintf(stderr, "setting threshold to %d\n", thresh_low) ;
    nargs = 1 ;
#else
    thresh_hi = atoi(argv[3]) ;
    fprintf(stderr, "thresholds set to %d --> %d\n", thresh_low, thresh_hi) ;
    nargs = 2 ;
#endif
  } else if (!stricmp(option, "reduce")) {
    nreductions = atoi(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "reducing input images %d times before aligning...\n",
            nreductions) ;
  } else if (!stricmp(option, "priors")) {
    l_priors = atof(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "using %2.2f as weight for prior term\n", l_priors) ;
  } else if (!stricmp(option, "voxel")) {
    voxel_coords = 1 ;
    fprintf(stderr, "outputting transform in voxel coordinates\n") ;
  } else if (!stricmp(option, "full_res")) {
    full_res = 1 ;
    fprintf(stderr, "outputting full resolution images\n") ;
  } else if (!stricmp(option, "nopca")) {
    nopca = 1 ;
    fprintf(stderr, "disabling pca\n") ;
  } else if (!stricmp(option, "factor")) {
    parms.factor = atof(argv[2]) ;
    nargs = 1 ;
    fprintf(stderr, "using time step factor of %2.2f\n",parms.factor) ;
  } else switch (*option) {
    case 'X':
      xform_mean_fname = argv[2] ;
      xform_covariance_fname = argv[3] ;
      printf("reading means (%s) and covariances (%s) of xforms\n",
             xform_mean_fname, xform_covariance_fname) ;
      nargs = 2 ;
      break ;
    case 'D':
      tx = atof(argv[2]) ;
      ty = atof(argv[3]) ;
      tz = atof(argv[4]) ;
      nargs = 3 ;
      break ;
    case 'R':
      rxrot = RADIANS(atof(argv[2])) ;
      ryrot = RADIANS(atof(argv[3])) ;
      rzrot = RADIANS(atof(argv[4])) ;
      nargs = 3 ;
      break ;
    case 'T':
      parms.lta = LTAread(argv[2]) ;
      if (!parms.lta)
        ErrorExit(ERROR_BADFILE, "%s: could not read transform file %s",
                  Progname, argv[2]) ;
      nargs = 1 ;
      fprintf(stderr, "using previously computed transform %s\n", argv[2]) ;
      transform_loaded = 1 ;
      break ;
    case 'B':
      blur_sigma = atof(argv[2]) ;
      nargs = 1 ;
      fprintf(stderr, "blurring input image with sigma=%2.3f\n", blur_sigma);
      break ;
    case 'S':
      parms.sigma = atof(argv[2]) ;
      fprintf(stderr, "using sigma=%2.3f as upper bound on blurring.\n",
              parms.sigma) ;
      nargs = 1 ;
      break ;
    case '?':
    case 'U':
      printf("usage: %s <in volume> <template volume> <output transform>\n",
             argv[0]) ;
      exit(1) ;
      break ;
    case 'V':
      var_fname = argv[2] ;
      fprintf(stderr, "reading variance image from %s...\n", var_fname) ;
      nargs = 1 ;
      break ;
    case 'N':
      parms.niterations = atoi(argv[2]) ;
      nargs = 1 ;
      fprintf(stderr, "niterations = %d\n", parms.niterations) ;
      break ;
    case 'W':
      parms.write_iterations = atoi(argv[2]) ;
      nargs = 1 ;
      fprintf(stderr, "write iterations = %d\n", parms.write_iterations) ;
      Gdiag |= DIAG_WRITE ;
      break ;
    case 'M':
      parms.momentum = atof(argv[2]) ;
      nargs = 1 ;
      fprintf(stderr, "momentum = %2.2f\n", parms.momentum) ;
      break ;
    default:
      fprintf(stderr, "unknown option %s\n", argv[1]) ;
      exit(1) ;
      break ;
    }

  return(nargs) ;
}
Exemple #3
0
// Create a VLAN object
VLAN *NewVLan(char *instance_name, VLAN_PARAM *param)
{
	VLAN *v;
	HANDLE h = INVALID_HANDLE_VALUE;
	HANDLE e = INVALID_HANDLE_VALUE;
	char tmp[MAX_SIZE];
	char name_upper[MAX_SIZE];
	// Validate arguments
	if (instance_name == NULL)
	{
		return NULL;
	}

	v = ZeroMalloc(sizeof(VLAN));

	if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType))
	{
		v->Win9xMode = true;
	}

	// Initialize the name
	Format(name_upper, sizeof(name_upper), "%s", instance_name);
	StrUpper(name_upper);
	v->InstanceName = CopyStr(name_upper);
	Format(tmp, sizeof(tmp), NDIS_NEO_DEVICE_FILE_NAME, v->InstanceName);
	v->DeviceNameWin32 = CopyStr(tmp);

	if (v->Win9xMode == false)
	{
		Format(tmp, sizeof(tmp), NDIS_NEO_EVENT_NAME_WIN32, v->InstanceName);
		v->EventNameWin32 = CopyStr(tmp);
	}

	// Connect to the device
	h = CreateFile(v->DeviceNameWin32,
		GENERIC_READ | GENERIC_WRITE,
		0,
		NULL,
		OPEN_EXISTING,
		0,
		NULL);
	if (h == INVALID_HANDLE_VALUE)
	{
		// Connection failure
		goto CLEANUP;
	}

	if (v->Win9xMode == false)
	{
		// Connect to the event
		e = OpenEvent(SYNCHRONIZE, FALSE, v->EventNameWin32);
		if (e == INVALID_HANDLE_VALUE)
		{
			// Connection failure
			goto CLEANUP;
		}
	}
	else
	{
		OPENVXDHANDLE OpenVxDHandle;
		DWORD vxd_handle;
		UINT bytes_returned;

		OpenVxDHandle = (OPENVXDHANDLE)GetProcAddress(GetModuleHandle("KERNEL32"),
			"OpenVxDHandle");

		// Deliver to the driver by creating an event
		e = CreateEvent(NULL, FALSE, FALSE, NULL);
		vxd_handle = (DWORD)OpenVxDHandle(e);

		DeviceIoControl(h, NEO_IOCTL_SET_EVENT, &vxd_handle, sizeof(DWORD),
			NULL, 0, &bytes_returned, NULL);
	}

	v->Event = e;
	v->Handle = h;

	v->GetBuffer = ZeroMalloc(NEO_EXCHANGE_BUFFER_SIZE);
	v->PutBuffer = ZeroMalloc(NEO_EXCHANGE_BUFFER_SIZE);

	return v;

CLEANUP:
	if (h != INVALID_HANDLE_VALUE)
	{
		CloseHandle(h);
	}
	if (e != INVALID_HANDLE_VALUE)
	{
		CloseHandle(e);
	}

	Free(v->InstanceName);
	Free(v->EventNameWin32);
	Free(v->DeviceNameWin32);
	Free(v);

	return NULL;
}
Exemple #4
0
int Parse_HTTP_Header(char * buffer, struct ReqInfo * reqinfo)
{
    
    static int first_header = 1;
    char      *temp;
    char      *endptr;
    int        len;
    
    
    if ( first_header == 1 )
    {
        
        /*  If first_header is 0, this is the first line of
        the HTTP request, so this should be the request line.  */
        
        
        /*  Get the request method, which is case-sensitive. This
        version of the server only supports the GET and HEAD
        request methods.                                        */
        
        if ( !strncmp(buffer, "GET ", 4) )
        {
            reqinfo->method = GET;
            buffer += 4;
        }
        else if ( !strncmp(buffer, "HEAD ", 5) )
        {
            reqinfo->method = HEAD;
            buffer += 5;
        }
        else
        {
            reqinfo->method = UNSUPPORTED;
            reqinfo->status = 501;
            return -1;
        }
        
        
        /*  Skip to start of resource  */
        
        while ( *buffer && isspace(*buffer) )
			buffer++;
        
        
        /*  Calculate string length of resource...  */
        
        endptr = strchr(buffer, ' ');
        if ( endptr == NULL )
			len = strlen(buffer);
        else
			len = endptr - buffer;
			
        if ( len == 0 )
        {
            reqinfo->status = 400;
            return -1;
        }
        
        /*  ...and store it in the request information structure.  */
        
        reqinfo->resource = calloc(len + 1, sizeof(char));
        strncpy(reqinfo->resource, buffer, len);
        
        
        /*  Test to see if we have any HTTP version information.
        If there isn't, this is a simple HTTP request, and we
        should not try to read any more headers. For simplicity,
        we don't bother checking the validity of the HTTP version
        information supplied - we just assume that if it is
        supplied, then it's a full request.                        */
        
        if ( strstr(buffer, "HTTP/") )
			reqinfo->type = FULL;
        else
			reqinfo->type = SIMPLE;
        
        first_header = 0;
        return 0;
    }
    
    
    /*  If we get here, we have further headers aside from the
    request line to parse, so this is a "full" HTTP request.  */
    
    /*  HTTP field names are case-insensitive, so make an
    upper-case copy of the field name to aid comparison.
    We need to make a copy of the header up until the colon.
    If there is no colon, we return a status code of 400
    (bad request) and terminate the connection. Note that
    HTTP/1.0 allows (but discourages) headers to span multiple
    lines if the following lines start with a space or a
    tab. For simplicity, we do not allow this here.              */
    
    endptr = strchr(buffer, ':');
    if ( endptr == NULL )
    {
        reqinfo->status = 400;
        return -1;
    }
    
    temp = calloc( (endptr - buffer) + 1, sizeof(char) );
    strncpy(temp, buffer, (endptr - buffer));
    StrUpper(temp);
    
    
    /*  Increment buffer so that it now points to the value.
    If there is no value, just return.                    */
    
    buffer = endptr + 1;
    while ( *buffer && isspace(*buffer) )
		++buffer;
    if ( *buffer == '\0' )
		return 0;
    
    
    /*  Now update the request information structure with the
    appropriate field value. This version only supports the
    "Referer:" and "User-Agent:" headers, ignoring all others.  */
    
    if ( !strcmp(temp, "USER-AGENT") )
    {
        reqinfo->useragent = malloc( strlen(buffer) + 1 );
        strcpy(reqinfo->useragent, buffer);
    }
    else if ( !strcmp(temp, "REFERER") )
    {
        reqinfo->referer = malloc( strlen(buffer) + 1 );
        strcpy(reqinfo->referer, buffer);
    }
    
    free(temp);
    return 0;
}