Example #1
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;
}
Example #2
0
 CF::String URL::GetPassword( void )
 {
     CF::String  str;
     CFStringRef cfStr;
     
     if( this->_cfObject == NULL )
     {
         return str;
     }
     
     cfStr = CFURLCopyPassword( this->_cfObject );
     
     if( cfStr != NULL )
     {
         str = cfStr;
         
         CFRelease( cfStr );
     }
     
     return str;
 }
Example #3
0
File: parse_url.c Project: aosm/smb
/* 
 * The URL may contain no password, an empty password, or a password. An empty password is a passowrd
 * and should be treated the same as a password. This is need to make guest access work.
 *
 *	URL "smb://*****:*****@server/share" should set the password.
 *	URL "smb://username:@server/" should set the password.
 *	URL "smb://username@server/share" should not set the password.
 *	URL "smb://server/share/path" should not set the password.
 *
 */
static int SetPasswordFromURL(struct smb_ctx *ctx, CFURLRef url)
{
	CFStringRef passwd = CFURLCopyPassword(url);
		
	/*  URL =" //[email protected]" or URL =" //smb-win2003.apple.com" */
	if (! passwd)
		return 0;
	
	/* Password is too long return an error */	
	if (CFStringGetLength(passwd) >= SMB_MAXPASSWORDLEN) {
		CFRelease(passwd);
		return ENAMETOOLONG;
	}
	/* 
	 * Works for password and empty password
	 *
	 * URL = "//username:[email protected]"
	 * URL = "//username:@smb-win2003.apple.com"
	 */
	CFStringGetCString(passwd, ctx->ct_setup.ioc_password, SMB_MAXPASSWORDLEN, kCFStringEncodingUTF8);
	ctx->ct_flags |= SMBCF_EXPLICITPWD;
	CFRelease(passwd);
	return 0;
}
Example #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;
}
Example #5
0
File: parse_url.c Project: aosm/smb
/* 
 * Given a url parse it and place the component in a dictionary we create.
 */
int smb_url_to_dictionary(CFURLRef url, CFDictionaryRef *dict)
{
	CFMutableDictionaryRef mutableDict = NULL;
	int error  = 0;
	CFStringRef Server = NULL;
	CFStringRef Username = NULL;
	CFStringRef DomainWrkgrp = NULL;
	CFStringRef Password = NULL;
	CFStringRef Share = NULL;
	CFStringRef Path = NULL;
	CFStringRef Port = NULL;
	
	/* Make sure its a good URL, better be at this point */
	if ((!CFURLCanBeDecomposed(url)) || (SMBSchemeLength(url) < 0)) {
		smb_log_info("%s: Invalid URL, syserr = %s", ASL_LEVEL_ERR, 
					 __FUNCTION__, strerror(EINVAL));	
		goto ErrorOut;
	}
	
	/* create and return the server parameters dictionary */
	mutableDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, 
												&kCFTypeDictionaryValueCallBacks);
	if (mutableDict == NULL) {
		error = errno;
		smb_log_info("%s: CFDictionaryCreateMutable failed, syserr = %s", 
					 ASL_LEVEL_ERR, __FUNCTION__, strerror(error));	
		goto ErrorOut;
	}
	
	/*
	 * SMB can have two different scheme's cifs or smb. When we made SMBSchemeLength call at the
	 * start of this routine it made sure we had one or the other scheme. Always default here to
	 * the SMB scheme.
	 */
	CFDictionarySetValue (mutableDict, kNetFSSchemeKey, CFSTR(SMB_SCHEME_STRING));

    error = NetFSCopyHostAndPort(url, &Server, &Port);
	if ((Server == NULL) || (error != noErr)) {
        if (Port != NULL) {
            CFRelease(Port);
        }
		goto ErrorOut; /* Server name is required */
    }
	
	LogCFString(Server, "Server String", __FUNCTION__, __LINE__);
	CFDictionarySetValue (mutableDict, kNetFSHostKey, Server);
	CFRelease(Server);
	Server = NULL;
	
    if (Port != NULL) {
        CFDictionarySetValue (mutableDict, kNetFSAlternatePortKey, Port);
        CFRelease(Port);
        Port = NULL;
    }

	Username = CopyUserAndWorkgroupFromURL(&DomainWrkgrp, url);
	LogCFString(Username, "Username String", __FUNCTION__, __LINE__);
	LogCFString(DomainWrkgrp, "DomainWrkgrp String", __FUNCTION__, __LINE__);
	error = 0;
	if ((Username) && (CFStringGetLength(Username) >= SMB_MAXUSERNAMELEN))
		error = ENAMETOOLONG;

	if ((DomainWrkgrp) && (CFStringGetLength(DomainWrkgrp) > SMB_MAXNetBIOSNAMELEN))
		error = ENAMETOOLONG;
	
	if (error) {
		if (Username)
			CFRelease(Username);
		if (DomainWrkgrp)
			CFRelease(DomainWrkgrp);
		goto ErrorOut; /* Username or Domain name is too long */
	}
	
	/* 
	 * We have a domain name so combined it with the user name so we can it 
	 * display to the user. We now test to make sure we have a username. Having
	 * a domain without a username makes no sense, so don't return either.
	 */
	if (DomainWrkgrp && Username && CFStringGetLength(Username)) {
		CFMutableStringRef tempString = CFStringCreateMutableCopy(NULL, 0, DomainWrkgrp);
		
		if (tempString) {
			CFStringAppend(tempString, CFSTR("\\"));
			CFStringAppend(tempString, Username);
			CFRelease(Username);
			Username = tempString;
		}
	}

	if (Username)
	{
		CFDictionarySetValue (mutableDict, kNetFSUserNameKey, Username);
		CFRelease(Username);				
	}	

    if (DomainWrkgrp) {
		CFRelease(DomainWrkgrp);
    }
    
	Password = CFURLCopyPassword(url);
	if (Password) {
		if (CFStringGetLength(Password) >= SMB_MAXPASSWORDLEN) {
			error = ENAMETOOLONG;
			CFRelease(Password);		
			goto ErrorOut; /* Password is too long */
		}
		CFDictionarySetValue (mutableDict, kNetFSPasswordKey, Password);
		CFRelease(Password);		
	}
	
	/*
	 * We used to keep the share and path as two different elements in the dictionary. This was
	 * changed to satisfy NetFS and other plugins. We still need to check and make sure the
	 * share and path are correct. So now split them apart and then put them put them back together.
	 */
	error = GetShareAndPathFromURL(url, &Share, &Path);
	if (error)
		goto ErrorOut; /* Share name is too long */
	
	LogCFString(Share, "Share String", __FUNCTION__, __LINE__);
	LogCFString(Path, "Path String", __FUNCTION__, __LINE__);

	if (Share && Path) {
		/* 
		 * We have a share and path, but there is nothing in the 
		 * share, then return an error 
		 */
	    if (CFStringGetLength(Share) == 0) {
			CFRelease(Path);
			CFRelease(Share);
			Share = Path = NULL;
			error = EINVAL;
			smb_log_info("%s: No share name found, syserr = %s", 
						 ASL_LEVEL_ERR, __FUNCTION__, strerror(error));	
			goto ErrorOut;
		}
		if (CFStringGetLength(Path)) {
			CFMutableStringRef tempString = CFStringCreateMutableCopy(NULL, 0, Share);
			if (tempString) {
				CFStringAppend(tempString, CFSTR("/"));
				CFStringAppend(tempString, Path);
				CFDictionarySetValue (mutableDict, kNetFSPathKey, tempString);
				CFRelease(tempString);		
				CFRelease(Share);		
				Share = NULL;
			} 
		}
	}
	/* Ignore any empty share at this point */
	if (Share && CFStringGetLength(Share))
		CFDictionarySetValue (mutableDict, kNetFSPathKey, Share);

	if (Share)
		CFRelease(Share);		
	
	if (Path) 
		CFRelease(Path);		

	*dict = mutableDict;
	return 0;
		
ErrorOut:
		
	*dict = NULL;
	if (mutableDict)
		CFRelease(mutableDict);
	if (!error)	/* No error set it to the default error */
		error = EINVAL;
	return error;
	
}
Example #6
0
string URL::password() const
{
    return mkstr(CFURLCopyPassword(ref));
}