Beispiel #1
0
/* 
 * Get the user and workgroup names and return them in CFStringRef. 
 * First get the CFURLCopyNetLocation because it will not escape out the string.
 */
static CFStringRef CopyUserAndWorkgroupFromURL(CFStringRef *outWorkGroup, CFURLRef url)
{
	CFURLRef net_url = NULL;
	CFArrayRef	userArray = NULL;
	CFStringRef userString = NULL;
	CFMutableStringRef urlString = NULL;
	CFStringRef wrkgrpString = NULL;
	
	*outWorkGroup = NULL;	/* Always start like we didn't get one. */
	/* This will return null if no workgroup in the URL */
	userArray = CreateWrkgrpUserArray(url);
	if (!userArray)	/* We just have a username name  */
		return(CFURLCopyUserName(url));	/* This will escape out the character for us. */
	
	/* Now for the hard part; netlocation contains one of the following:
	 *
	 * URL = "//workgroup;username:[email protected]"
	 * URL = "//workgroup;username:@smb-win2003.apple.com"
	 * URL = "//workgroup;[email protected]"
	 * URL = "//workgroup;@smb-win2003.apple.com"
	 */
	/* Get the username first */
	urlString = CFStringCreateMutableCopy(NULL, 1024, CFSTR("smb://"));
	if (!urlString) {
		CFRelease(userArray);
		return(CFURLCopyUserName(url));	/* This will escape out the character for us. */
	}
	CFStringAppend(urlString, (CFStringRef)CFArrayGetValueAtIndex(userArray, 1));
	net_url = CFURLCreateWithString(NULL, urlString, NULL);
	CFRelease(urlString);
	urlString = NULL;
	/* Not sure what to do if we fail here */
	if (!net_url) {
		CFRelease(userArray);
		return(CFURLCopyUserName(url));	/* This will escape out the character for us. */		
	}
	/* We now have a URL without the workgroup name, just copy out the username. */
	userString = CFURLCopyUserName(net_url);
	CFRelease(net_url);
	
	/* Now get the workgroup */
	wrkgrpString = CFStringCreateCopy(NULL, (CFStringRef)CFArrayGetValueAtIndex(userArray, 0));
	CreateStringByReplacingPercentEscapesUTF8(&wrkgrpString, CFSTR(""));
	if (wrkgrpString)
		*outWorkGroup = wrkgrpString;	/* We have the workgroup return it to the calling routine */
	CFRelease(userArray);
	return(userString);
}
Beispiel #2
0
static netfsError
OpenSession9P(CFURLRef url, void *v, CFDictionaryRef opts,
              CFDictionaryRef * info)
{
        CFMutableDictionaryRef dict;
        Context9P *ctx;
        int useGuest, e;

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

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

        useGuest = FALSE;
        if (opts != NULL) {
                CFBooleanRef boolean =
                    CFDictionaryGetValue(opts, kNetFSUseGuestKey);
                if (boolean != NULL)
                        useGuest = CFBooleanGetValue(boolean);
        }

        if (useGuest)
                CFDictionarySetValue(dict, kNetFSMountedByGuestKey,
                                     kCFBooleanTrue);
        else {
                ctx->user = CFURLCopyUserName(url);
                ctx->pass = CFURLCopyPassword(url);
                if (ctx->user == NULL || ctx->pass == NULL) {
                        if (ctx->user)
                                CFRelease(ctx->user);
                        if (ctx->pass)
                                CFRelease(ctx->pass);
                        ctx->user = ctx->pass = NULL;
                        goto error;
                }
                DEBUG("user=%s pass=%s", NetFSCFStringtoCString(ctx->user),
                      NetFSCFStringtoCString(ctx->pass));
                CFDictionarySetValue(dict, kNetFSMountedByUserKey, ctx->user);
        }
        return 0;

 error:
        e = errno;
        *info = NULL;
        CFRelease(dict);
        return e;
}
Beispiel #3
0
 CF::String URL::GetUserName( void )
 {
     CF::String  str;
     CFStringRef cfStr;
     
     if( this->_cfObject == NULL )
     {
         return str;
     }
     
     cfStr = CFURLCopyUserName( this->_cfObject );
     
     if( cfStr != NULL )
     {
         str = cfStr;
         
         CFRelease( cfStr );
     }
     
     return str;
 }
Beispiel #4
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;
}
Beispiel #5
0
string URL::username() const
{
    return mkstr(CFURLCopyUserName(ref));
}