示例#1
0
static netfsError
GetServerInfo9P(CFURLRef url, void *v, CFDictionaryRef opts,
                CFDictionaryRef * params)
{
#pragma unused(v)
#pragma unused(opts)

        CFMutableDictionaryRef dict;
        CFStringRef host;

        TRACE();
        if (url == NULL || params == NULL || !CFURLCanBeDecomposed(url))
                return EINVAL;

        *params = dict = CreateDict9P();
        if (dict == NULL)
                return ENOMEM;

        host = CFURLCopyHostName(url);
        if (host != NULL) {
                CFDictionarySetValue(dict, kNetFSServerDisplayNameKey, host);
                CFRelease(host);
        }

        CFDictionarySetValue(dict, kNetFSSupportsChangePasswordKey,
                             kCFBooleanFalse);
        CFDictionarySetValue(dict, kNetFSSupportsGuestKey, kCFBooleanTrue);
        CFDictionarySetValue(dict, kNetFSSupportsKerberosKey, kCFBooleanFalse);
        CFDictionarySetValue(dict, kNetFSGuestOnlyKey, kCFBooleanFalse);
        return 0;
}
示例#2
0
文件: parse_url.c 项目: aosm/smb
/* 
 * Get the server name out of the URL. CFURLCopyHostName will escape out the 
 * server name for us. So just convert it to the correct code page encoding.
 *
 * Note: Currently we put the server name into a c-style string. In the future 
 * it would be nice to keep this as a CFString.
 */
static int SetServerFromURL(struct smb_ctx *ctx, CFURLRef url)
{
	CFIndex maxlen;
	CFStringRef serverNameRef = CFURLCopyHostName(url);
	char *ipV6Name = NULL;

	ipV6Name = CStringCreateWithCFString(serverNameRef);
	if (ipV6Name && isIPv6NumericName(ipV6Name)) {
        /* CFURLCopyHostName removed the [] so put them back in */
        CFMutableStringRef newServer = CFStringCreateMutableCopy(NULL, 1024, CFSTR("["));
        if (newServer) {
            CFStringAppend(newServer, serverNameRef);
            CFStringAppend(newServer, CFSTR("]"));
            CFRelease(serverNameRef);
            serverNameRef = newServer;
        }
    }

	/* Free up the buffer we allocated */
	if (ipV6Name) {
		free(ipV6Name);
    }
    
    /*
	 * Every time we parse the URL we end up replacing the server name. In the 
	 * future we should skip replacing the server name if we already have one and
	 * the one return CFURLCopyHostName matches it.
	 *
	 * Not going to make that big of a change in an update, so lets limit to the
	 * case were we are dealing with using a domain controller.
	 */
	if (serverNameRef && ctx->serverNameRef && ctx->serverName &&
		(ctx->serverIsDomainController) &&	
		(ctx->ct_flags & SMBCF_CONNECTED) && 
		(CFStringCompare(serverNameRef, ctx->serverNameRef, 0) == kCFCompareEqualTo)) {
		CFRelease(serverNameRef);
		return 0; /* Same name nothing to do here */
	}
	if (ctx->serverNameRef) {
		CFRelease(ctx->serverNameRef);
	}
		/* The serverNameRef should always contain the URL host name or the Bonjour Name */
	ctx->serverNameRef = serverNameRef;
	if (ctx->serverNameRef == NULL)
		return EINVAL;
	DebugLogCFString(ctx->serverNameRef, "Server", __FUNCTION__, __LINE__);
	
	maxlen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(ctx->serverNameRef), kCFStringEncodingUTF8) + 1;
	if (ctx->serverName)
		free(ctx->serverName);
	ctx->serverName = malloc(maxlen);
	if (!ctx->serverName) {
		CFRelease(ctx->serverNameRef);
		ctx->serverNameRef = NULL;
		return ENOMEM;
	}
	CFStringGetCString(ctx->serverNameRef, ctx->serverName, maxlen, kCFStringEncodingUTF8);
	return 0;
}
示例#3
0
CFNetDiagnosticRef CFNetDiagnosticCreateWithURL(CFAllocatorRef allocator, CFURLRef url) {
	CFMutableDictionaryRef retval;
	SInt32 port = 0;
	
	retval = CFDictionaryCreateMutable(allocator, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
	
	if(retval != NULL && CFURLCanBeDecomposed(url)) {
		port = CFURLGetPortNumber(url);
		
		_CFNetDiagnosticSetDictionaryKeyIfNotNull(_CFNetDiagnosticNameKey, CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleNameKey), retval);		
		_CFNetDiagnosticSetDictionaryKeyIfNotNull(_CFNetDiagnosticBundleKey, CFBundleGetIdentifier( CFBundleGetMainBundle() ), retval);
		_CFNetDiagnosticSetDictionaryKeyAndReleaseIfNotNull(_CFNetDiagnosticRemoteHostKey, CFURLCopyHostName(url), retval);
		_CFNetDiagnosticSetDictionaryKeyAndReleaseIfNotNull(_CFNetDiagnosticProtocolKey, CFURLCopyScheme(url), retval);
		_CFNetDiagnosticSetDictionaryKeyAndReleaseIfNotNull(_CFNetDiagnosticPortKey, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &port), retval);
		
		_CFNetDiagnosticSetDictionaryKeyIfNotNull(_CFNetDiagnosticMethodKey, CFSTR("CFNetDiagnosticCreateWithURL"), retval);
	}
	
	return (CFNetDiagnosticRef)retval;
}
示例#4
0
文件: CFPP-URL.cpp 项目: siraj/CFPP
 CF::String URL::GetHostName( void )
 {
     CF::String  str;
     CFStringRef cfStr;
     
     if( this->_cfObject == NULL )
     {
         return str;
     }
     
     cfStr = CFURLCopyHostName( this->_cfObject );
     
     if( cfStr != NULL )
     {
         str = cfStr;
         
         CFRelease( cfStr );
     }
     
     return str;
 }
示例#5
0
static netfsError ParseURL9P(CFURLRef url, CFDictionaryRef * params)
{
        CFMutableDictionaryRef dict;
        CFStringRef str;
        SInt32 port;
        int e;

        TRACE();
        if (url == NULL || params == NULL || !CFURLCanBeDecomposed(url))
                return EINVAL;

        DEBUG("url=%s", NetFSCFStringtoCString(CFURLGetString(url)));
        *params = dict = CreateDict9P();
        if (dict == NULL)
                return ENOMEM;

        /* mandatory */
        str = CFURLCopyScheme(url);
        if (str == NULL)
                goto error;
        CFDictionarySetValue(dict, kNetFSSchemeKey, str);
        CFRelease(str);

        str = CFURLCopyHostName(url);
        if (str == NULL)
                goto error;
        CFDictionarySetValue(dict, kNetFSHostKey, str);
        CFRelease(str);

        /* optional */
        port = CFURLGetPortNumber(url);
        if (port != -1) {
                str =
                    CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
                                             CFSTR("%d"), (int)port);
                if (str == NULL)
                        goto error;
                CFDictionarySetValue(dict, kNetFSAlternatePortKey, str);
                CFRelease(str);
        }

        str = CFURLCopyUserName(url);
        if (str != NULL) {
                CFDictionarySetValue(dict, kNetFSUserNameKey, str);
                CFRelease(str);
        }

        str = CFURLCopyPassword(url);
        if (str != NULL) {
                CFDictionarySetValue(dict, kNetFSPasswordKey, str);
                CFRelease(str);
        }
/*
	str = CFURLCopyPath(url);
	if (str != NULL) {
		CFDictionarySetValue(dict, kNetFSPathKey, str);
		CFRelease(str);
	}
*/
        return 0;

 error:
        e = errno;
        *params = NULL;
        CFRelease(dict);
        return e;
}
示例#6
0
static netfsError
Mount9P(void *v, CFURLRef url, CFStringRef mntpointstr, CFDictionaryRef opts,
        CFDictionaryRef * info)
{
        CFMutableDictionaryRef dict;
        CFMutableStringRef mntoptsstr;
        CFStringRef str;
        CFNumberRef num;
        Context9P *ctx;
        char *host, *mntpoint, *mntopts;
        int32_t mntflags;
        int e;

        TRACE();
        ctx = v;
        if (ctx == NULL || url == NULL || mntpointstr == NULL || info == NULL
            || !CFURLCanBeDecomposed(url))
                return EINVAL;

        DEBUG("url=%s opts=%s", NetFSCFStringtoCString(CFURLGetString(url)),
              NetFSCFStringtoCString(CFCopyDescription(opts)));
        mntoptsstr = NULL;
        host = mntpoint = mntopts = NULL;
        *info = dict = CreateDict9P();
        if (dict == NULL)
                return ENOMEM;

        str = CFURLCopyHostName(url);
        if (str == NULL)
                goto error;

        host = NetFSCFStringtoCString(str);
        CFRelease(str);
        if (host == NULL)
                goto error;

        mntpoint = NetFSCFStringtoCString(mntpointstr);
        if (mntpoint == NULL)
                goto error;

        mntflags = 0;
        if (opts != NULL) {
                num =
                    (CFNumberRef) CFDictionaryGetValue(opts,
                                                       kNetFSMountFlagsKey);
                CFNumberGetValue(num, kCFNumberSInt32Type, &mntflags);
        }

        mntoptsstr =
            CFStringCreateMutableCopy(kCFAllocatorDefault, 0, CFSTR("-o"));
        if (mntoptsstr == NULL)
                goto error;

        if (ctx->user && ctx->pass)
                CFStringAppendFormat(mntoptsstr, NULL,
                                     CFSTR("uname=%@,pass=%@"), ctx->user,
                                     ctx->pass);
        else
                CFStringAppend(mntoptsstr, CFSTR("noauth"));

        /* query if there's any */
        str = CFURLCopyQueryString(url, CFSTR(""));
        if (str && CFStringGetLength(str) > 0) {
                CFStringAppend(mntoptsstr, CFSTR(","));
                CFStringAppend(mntoptsstr, str);
                CFRelease(str);
        }

        mntopts = NetFSCFStringtoCString(mntoptsstr);
        if (mntopts == NULL)
                goto error;

        DEBUG("host=%s mntpoint=%s mntopts=%s", host, mntpoint, mntopts);
        if (DoMount9P(host, mntpoint, mntopts, mntflags) < 0)
                goto error;

        CFDictionarySetValue(dict, kNetFSMountPathKey, mntpointstr);
        if (ctx->user)
                CFDictionarySetValue(dict, kNetFSMountedByUserKey, ctx->user);
        else
                CFDictionarySetValue(dict, kNetFSMountedByGuestKey,
                                     kCFBooleanTrue);

        if (mntoptsstr)
                CFRelease(mntoptsstr);
        free(host);
        free(mntpoint);
        free(mntopts);
        return 0;

 error:
        e = errno;
        *info = NULL;
        CFRelease(dict);
        if (mntoptsstr)
                CFRelease(mntoptsstr);
        free(host);
        free(mntpoint);
        free(mntopts);
        return e;
}
示例#7
0
string URL::host() const
{
    return mkstr(CFURLCopyHostName(ref));
}