コード例 #1
0
/*
 * Set prefix.  Copies the defined number of attributes.
 */
void
Dbtux::setNodePref(TuxCtx & ctx, NodeHandle& node)
{
  const Frag& frag = node.m_frag;
  const Index& index = *c_indexPool.getPtr(frag.m_indexId);
  /*
   * bug#12873640
   * Node prefix exists if it has non-zero number of attributes.  It is
   * then a partial instance of KeyData.  If the prefix does not exist
   * then set_buf() could overwrite m_pageId1 in first entry, causing
   * random crash in TUP via readKeyAttrs().
   */
  if (index.m_prefAttrs > 0) {
    KeyData prefKey(index.m_keySpec, false, 0);
    prefKey.set_buf(node.getPref(), index.m_prefBytes);
    thrjam(ctx.jamBuffer);
    readKeyAttrs(ctx, frag, node.getEnt(0), prefKey, index.m_prefAttrs);
#ifdef VM_TRACE
    if (debugFlags & DebugMaint) {
      debugOut << "setNodePref: " << node;
      debugOut << " " << prefKey.print(ctx.c_debugBuffer, DebugBufferBytes);
      debugOut << endl;
    }
#endif
  }
}
NS_IMETHODIMP
sbLocalDatabaseLibraryLoader::OnLibraryStartupModified(sbILibrary* aLibrary,
                                                       PRBool aLoadAtStartup)
{
  NS_ENSURE_ARG_POINTER(aLibrary);

  // See if we support this library type.
  nsCOMPtr<sbILibraryFactory> factory;
  nsresult rv = aLibrary->GetFactory(getter_AddRefs(factory));
  NS_ENSURE_SUCCESS(rv, rv);

  nsAutoString factoryType;
  rv = factory->GetType(factoryType);
  NS_ENSURE_SUCCESS(rv, rv);

  NS_ENSURE_TRUE(factoryType.EqualsLiteral(SB_LOCALDATABASE_LIBRARYFACTORY_TYPE),
                 NS_ERROR_NOT_AVAILABLE);

  // See if this library already exists in the hashtable.
  nsAutoString resourceGUID;
  rv = aLibrary->GetGuid(resourceGUID);
  NS_ENSURE_SUCCESS(rv, rv);

  sbLibraryExistsInfo existsInfo(resourceGUID);
  mLibraryInfoTable.EnumerateRead(LibraryExistsCallback, &existsInfo);

  sbLibraryLoaderInfo* libraryInfo;
  if ((existsInfo.index == -1) ||
      (!mLibraryInfoTable.Get(existsInfo.index, &libraryInfo))) {

    // The library wasn't in the hashtable so make sure that we can recreate
    // it.
    nsCOMPtr<nsIPropertyBag2> creationParameters;
    rv = aLibrary->GetCreationParameters(getter_AddRefs(creationParameters));
    NS_ENSURE_SUCCESS(rv, rv);

    NS_NAMED_LITERAL_STRING(fileKey, PROPERTY_KEY_DATABASEFILE);
    nsCOMPtr<nsILocalFile> databaseFile;
    rv = creationParameters->GetPropertyAsInterface(fileKey,
                                                    NS_GET_IID(nsILocalFile),
                                                    getter_AddRefs(databaseFile));
    NS_ENSURE_SUCCESS(rv, rv);

    NS_ASSERTION(databaseFile, "This can't be null!");

    // Make a new sbLibraryLoaderInfo object.
    PRUint32 index = GetNextLibraryIndex();

    nsCAutoString prefKey(PREFBRANCH_LOADER);
    prefKey.AppendInt(index);
    prefKey.AppendLiteral(".");

    nsAutoPtr<sbLibraryLoaderInfo>
      newLibraryInfo(CreateDefaultLibraryInfo(prefKey, EmptyString(),
                                              databaseFile));
    if (!newLibraryInfo || !mLibraryInfoTable.Put(index, newLibraryInfo)) {
      return NS_ERROR_FAILURE;
    }

    rv = newLibraryInfo->SetDatabaseLocation(databaseFile);
    NS_ENSURE_SUCCESS(rv, rv);

    libraryInfo = newLibraryInfo.forget();
  }

  rv = libraryInfo->SetLoadAtStartup(aLoadAtStartup);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}
コード例 #3
0
bool
sbSecurityMixin::GetPermission(nsIURI *aURI, const struct Scope *aScope )
{
    NS_ENSURE_TRUE( aURI, PR_FALSE );
    NS_ENSURE_TRUE( aScope, PR_FALSE );
    NS_ENSURE_TRUE( aScope->name, PR_FALSE );

#ifdef PR_LOGGING
    if (aURI) {
        nsCAutoString spec;
        aURI->GetSpec(spec);
        LOG(( "sbSecurityMixin::GetPermission( %s, %s)", spec.get(), aScope->name ));
    }
#endif

    nsresult rv;
    nsCOMPtr<nsIPrefBranch> prefService =
        do_GetService( "@mozilla.org/preferences-service;1", &rv );
    NS_ENSURE_SUCCESS( rv, PR_FALSE );

    // build the pref key to check
    bool prefBlocked = PR_TRUE;
    nsCString prefKey("songbird.rapi.");
    prefKey.Append(aScope->name);
    prefKey.AppendLiteral("_disable");

    // get the pref value
    LOG(( "sbSecurityMixin::GetPermission() - asking for pref: %s", prefKey.get() ));
    rv = prefService->GetBoolPref( prefKey.get(), &prefBlocked );
    NS_ENSURE_SUCCESS( rv, PR_FALSE );

    // get the permission for the domain
    nsCString permission_name("rapi.");
    permission_name.Append(aScope->name);
    nsCOMPtr<nsIPermissionManager> permMgr( do_GetService( NS_PERMISSIONMANAGER_CONTRACTID, &rv ) );
    NS_ENSURE_SUCCESS( rv, PR_FALSE );
    PRUint32 perms = nsIPermissionManager::UNKNOWN_ACTION;
    rv = permMgr->TestPermission( aURI, permission_name.get(), &perms );
    NS_ENSURE_SUCCESS( rv, PR_FALSE );

    // check to see if the action is allowed for the domain
    if (prefBlocked) {
        LOG(( "sbSecurityMixin::GetPermission() - action is blocked" ));
        // action is blocked, see if domain is cleared explicitly
        if ( perms == nsIPermissionManager::ALLOW_ACTION ) {
            LOG(("sbSecurityMixin::GetPermission - Permission GRANTED!!!"));
            return PR_TRUE;
        }
    } else {
        LOG(( "sbSecurityMixin::GetPermission() - action not blocked" ));
        // action not blocked, make sure domain isn't blocked explicitly
        if ( perms != nsIPermissionManager::DENY_ACTION ) {
            LOG(("sbSecurityMixin::GetPermission - Permission GRANTED!!!"));
            return PR_TRUE;
        }
    }

    // Negative Ghostrider, pattern is full.
    LOG(("sbSecurityMixin::GetPermission - Permission DENIED (looooooser)!!!"));
    return PR_FALSE;
}
nsresult
sbLocalDatabaseLibraryLoader::EnsureDefaultLibrary(const nsACString& aLibraryGUIDPref,
                                                   const nsAString& aDefaultDatabaseGUID,
                                                   const nsAString& aLibraryNameKey,
                                                   const nsAString& aCustomType,
                                                   const nsAString& aDefaultColumnSpec)
{
  nsCAutoString resourceGUIDPrefKey(aLibraryGUIDPref);

  // Figure out the GUID for this library.
  nsAutoString resourceGUID;
  PRInt32 libraryInfoIndex = -1;

  // The prefs here should point to a library resourceGUID.
  nsCOMPtr<nsISupportsString> supportsString;
  nsresult rv = mRootBranch->GetComplexValue(resourceGUIDPrefKey.get(),
                                             NS_GET_IID(nsISupportsString),
                                             getter_AddRefs(supportsString));
  if (NS_SUCCEEDED(rv)) {
    // Use the value stored in the prefs.
    rv = supportsString->GetData(resourceGUID);
    NS_ENSURE_SUCCESS(rv, rv);

    NS_ASSERTION(!resourceGUID.IsEmpty(), "Should have a resource GUID here!");

    // See if this library already exists in the hashtable.
    sbLibraryExistsInfo existsInfo(resourceGUID);
    mLibraryInfoTable.EnumerateRead(LibraryExistsCallback, &existsInfo);
    
    libraryInfoIndex = existsInfo.index;
  }

  sbLibraryLoaderInfo* libraryInfo;
  if ((libraryInfoIndex == -1) ||
      (!mLibraryInfoTable.Get(libraryInfoIndex, &libraryInfo))) {
    // The library wasn't in our hashtable, so make a new sbLibraryLoaderInfo
    // object. That will take care of setting the prefs up correctly.
    PRUint32 index = GetNextLibraryIndex();

    nsCAutoString prefKey(PREFBRANCH_LOADER);
    prefKey.AppendInt(index);
    prefKey.AppendLiteral(".");

    nsAutoPtr<sbLibraryLoaderInfo>
      newLibraryInfo(CreateDefaultLibraryInfo(prefKey, aDefaultDatabaseGUID,
                                              nsnull, aLibraryNameKey));
    if (!newLibraryInfo || !mLibraryInfoTable.Put(index, newLibraryInfo)) {
      return NS_ERROR_FAILURE;
    }

    // Set the resource GUID into the prefs.
    newLibraryInfo->GetResourceGUID(resourceGUID);
    NS_ENSURE_FALSE(resourceGUID.IsEmpty(), NS_ERROR_UNEXPECTED);

    supportsString = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = supportsString->SetData(resourceGUID);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = mRootBranch->SetComplexValue(resourceGUIDPrefKey.get(),
                                      NS_GET_IID(nsISupportsString),
                                      supportsString);
    NS_ENSURE_SUCCESS(rv, rv);

    libraryInfo = newLibraryInfo.forget();
  }

#ifdef DEBUG
  nsAutoString guid;
  libraryInfo->GetDatabaseGUID(guid);
  NS_ASSERTION(!guid.IsEmpty(), "Empty GUID!");
#endif

  // Make sure this library loads at startup.
  if (!libraryInfo->GetLoadAtStartup()) {
    rv = libraryInfo->SetLoadAtStartup(PR_TRUE);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  // And make sure that the database file actually exists and is accessible.
  nsCOMPtr<nsILocalFile> location = libraryInfo->GetDatabaseLocation();
  NS_ENSURE_TRUE(location, NS_ERROR_UNEXPECTED);

  nsCOMPtr<sbILibraryFactory> localDatabaseLibraryFactory =
    do_GetService(SB_LOCALDATABASE_LIBRARYFACTORY_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  sbLocalDatabaseLibraryFactory *libraryFactory = 
    reinterpret_cast<sbLocalDatabaseLibraryFactory *>(localDatabaseLibraryFactory.get());

  nsCOMPtr<sbILibrary> library;
  rv = libraryFactory->CreateLibraryFromDatabase(location,
                                                 getter_AddRefs(library),
                                                 nsnull,
                                                 resourceGUID);
  if (NS_FAILED(rv)) {
    // We can't access this required database file. For now we're going to
    // simply make a new blank database in the default location and switch 
    // the preferences to use it.
    location = libraryFactory->GetFileForGUID(aDefaultDatabaseGUID);
    NS_ENSURE_TRUE(location, NS_ERROR_FAILURE);

    // Make sure we can access this one.
    rv = libraryFactory->CreateLibraryFromDatabase(location,
                                                   getter_AddRefs(library));
    NS_ENSURE_SUCCESS(rv, rv);

    // And update the libraryInfo object.
    rv = libraryInfo->SetDatabaseGUID(aDefaultDatabaseGUID);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = libraryInfo->SetDatabaseLocation(location);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = library->GetGuid(resourceGUID);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = libraryInfo->SetResourceGUID(resourceGUID);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  // Set the name.
  rv = library->SetName(aLibraryNameKey);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = library->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_CUSTOMTYPE), 
                            aCustomType);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = library->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_ISSORTABLE), 
                            NS_LITERAL_STRING("1"));
  NS_ENSURE_SUCCESS(rv, rv);

  if (!aDefaultColumnSpec.IsEmpty()) {
    rv = library->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_DEFAULTCOLUMNSPEC),
                              aDefaultColumnSpec);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return NS_OK;
}
コード例 #5
0
bool
sbSecurityMixin::GetPermissionForScopedName(const nsAString &aScopedName,
        bool disableNotificationCheck)
{
    LOG(( "sbSecurityMixin::GetPermissionForScopedName()"));

    // If this instance was set to be privileged, skip the check
    if (mPrivileged) {
        return PR_TRUE;
    }

    bool allowed = PR_FALSE;

    nsCOMPtr<nsIURI> codebase;
    GetCodebase( getter_AddRefs(codebase) );

    if ( StringBeginsWith( aScopedName, NS_LITERAL_STRING("internal:") ) ) {
        if (!codebase) {
            // internal stuff always allowed, should never be called from insecure code.
            allowed = PR_TRUE;
        } else {
            // I think this is always a bad thing. It should represent calling of
            // methods flagged as internal only being called by insecure code (not
            // using system principal)
            NS_WARNING("sbSecurityMixin::GetPermissionForScopedName() -- AHHH!!! Asked for internal with codebase");
            return PR_FALSE;
        }
    }

    // without a codebase we're either calling internal stuff or wrong.
    if (!codebase)
        return allowed;

    // look up information about the scope
    const struct Scope* scope = GetScopeForScopedName( aScopedName );

    if (scope) {
        // if the current scope is in the table then use the values in the table
        // to get permission
        allowed = GetPermission( codebase, scope );
    }
    else if ( StringBeginsWith( aScopedName, NS_LITERAL_STRING("site:") ) ) {
        // site library methods are always cleared
        allowed = PR_TRUE;
    }
    else if ( StringBeginsWith( aScopedName, NS_LITERAL_STRING("helper:") ) ) {
        // helper classes always allowed
        allowed = PR_TRUE;
    }
    else if ( StringBeginsWith( aScopedName, NS_LITERAL_STRING("classinfo:") ) ) {
        // class info stuff always allowed - this might need to move above the codebase check.
        allowed = PR_TRUE;
    }

    // if we found additional info about the scope, work out if there's a
    // notification to fire
    if ( scope && !disableNotificationCheck ) {
        const char* notification =
            allowed ? scope->allowed_notification : scope->blocked_notification;
        LOG(( "sbSecurityMixin::GetPermissionsForScopedName() notification=%s",
              notification ));

        if ( strcmp(notification, sNotificationAlert) == 0 ) {
            LOG(( "sbSecurityMixin::GetPermissionsForScopedName() - ALERT" ));
            // Launch a prompt asking the user if they want to do this action.

            allowed =
                sbRemotePlayer::GetUserApprovalForHost( codebase,
                        NS_LITERAL_STRING("rapi.media_add.request.title"),
                        NS_LITERAL_STRING("rapi.media_add.request.message"),
                        scope->name );

        }
        else if ( strcmp(notification, sNotificationStatus) == 0 ) {
            LOG(( "sbSecurityMixin::GetPermissionsForScopedName() - STATUS" ));
        }
        else if ( strcmp(notification, sNotificationHat) == 0 ) {
            LOG(( "sbSecurityMixin::GetPermissionsForScopedName() - HAT" ));
            // notification is not "none"

            // we want to fire a notification, but does the user want a notification?

            // get the prefs service
            nsresult rv;
            nsCOMPtr<nsIPrefBranch> prefService =
                do_GetService( "@mozilla.org/preferences-service;1", &rv );
            NS_ENSURE_SUCCESS( rv, allowed );

            bool notify;
            // look up the pref
            nsCString prefKey("songbird.rapi.");
            prefKey.Append(scope->name);
            prefKey.AppendLiteral("_notify");
            rv = prefService->GetBoolPref( prefKey.get(), &notify );
            NS_ENSURE_SUCCESS( rv, allowed );

            LOG(( "sbSecurityMixin::GetPermissionsForScopedName() pref value: %s",
                  notify?"true":"false" ));

            // if the pref is true we should notify
            if (notify) {
                DispatchNotificationEvent(notification, scope, allowed);
            }
        }
    }

    return allowed;
}