~evarlast/ubuntu/utopic/mongodb/upstart-workaround-debian-bug-718702

« back to all changes in this revision

Viewing changes to src/mongo/db/dbeval.cpp

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Robie Basak
  • Date: 2013-05-29 17:44:42 UTC
  • mfrom: (44.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130529174442-z0a4qmoww4y0t458
Tags: 1:2.4.3-1ubuntu1
[ James Page ]
* Merge from Debian unstable, remaining changes:
  - Enable SSL support:
    + d/control: Add libssl-dev to BD's.
    + d/rules: Enabled --ssl option.
    + d/mongodb.conf: Add example SSL configuration options.
  - d/mongodb-server.mongodb.upstart: Add upstart configuration.
  - d/rules: Don't strip binaries during scons build for Ubuntu.
  - d/control: Add armhf to target archs.
  - d/p/SConscript.client.patch: fixup install of client libraries.
  - d/p/0010-install-libs-to-usr-lib-not-usr-lib64-Closes-588557.patch:
    Install libraries to lib not lib64.
* Dropped changes:
  - d/p/arm-support.patch: Included in Debian.
  - d/p/double-alignment.patch: Included in Debian.
  - d/rules,control: Debian also builds with avaliable system libraries
    now.
* Fix FTBFS due to gcc and boost upgrades in saucy:
  - d/p/0008-ignore-unused-local-typedefs.patch: Add -Wno-unused-typedefs
    to unbreak building with g++-4.8.
  - d/p/0009-boost-1.53.patch: Fixup signed/unsigned casting issue.

[ Robie Basak ]
* d/p/0011-Use-a-signed-char-to-store-BSONType-enumerations.patch: Fixup
  build failure on ARM due to missing signed'ness of char cast.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* commands.cpp
2
 
   db "commands" (sent via db.$cmd.findOne(...))
3
 
 */
 
1
// commands.cpp
4
2
 
5
3
/**
 
4
*    Copyright (C) 2012 10gen Inc.
6
5
*
7
6
*    This program is free software: you can redistribute it and/or  modify
8
7
*    it under the terms of the GNU Affero General Public License, version 3,
23
22
#include "../bson/util/builder.h"
24
23
#include <time.h>
25
24
#include "introspect.h"
26
 
#include "btree.h"
27
25
#include "../util/lruishmap.h"
28
26
#include "json.h"
29
27
#include "repl.h"
59
57
            return false;
60
58
        }
61
59
 
62
 
        auto_ptr<Scope> s = globalScriptEngine->getPooledScope( dbName );
 
60
        auto_ptr<Scope> s = globalScriptEngine->getPooledScope( dbName, "dbeval" );
63
61
        ScriptingFunction f = s->createFunction(code);
64
62
        if ( f == 0 ) {
65
63
            errmsg = (string)"compile failed: " + s->getError();
93
91
                else OCCASIONALLY log() << code << endl;
94
92
            }
95
93
        }
96
 
        if ( res ) {
 
94
        if (res || s->isLastRetNativeCode()) {
97
95
            result.append("errno", (double) res);
98
96
            errmsg = "invoke failed: ";
99
 
            errmsg += s->getError();
 
97
            if (s->isLastRetNativeCode())
 
98
                errmsg += "cannot return native function";
 
99
            else
 
100
                errmsg += s->getError();
100
101
            return false;
101
102
        }
102
103
 
103
 
        s->append( result , "retval" , "return" );
 
104
        s->append( result , "retval" , "__returnValue" );
104
105
 
105
106
        return true;
106
107
    }
115
116
            help << "Evaluate javascript at the server.\n" "http://dochub.mongodb.org/core/serversidecodeexecution";
116
117
        }
117
118
        virtual LockType locktype() const { return NONE; }
 
119
        virtual void addRequiredPrivileges(const std::string& dbname,
 
120
                                           const BSONObj& cmdObj,
 
121
                                           std::vector<Privilege>* out) {
 
122
            // $eval can do pretty much anything, so require all privileges.
 
123
            out->push_back(Privilege(PrivilegeSet::WILDCARD_RESOURCE,
 
124
                                     AuthorizationManager::getAllUserActions()));
 
125
        }
118
126
        CmdEval() : Command("eval", false, "$eval") { }
119
127
        bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
120
 
 
121
 
            AuthenticationInfo *ai = cc().getAuthenticationInfo();
122
 
            uassert( 12598 , "$eval reads unauthorized", ai->isAuthorizedReads(dbname.c_str()) );
123
 
 
124
128
            if ( cmdObj["nolock"].trueValue() ) {
125
129
                return dbEval(dbname, cmdObj, result, errmsg);
126
130
            }
127
131
 
128
 
            // write security will be enforced in DBDirectClient
129
 
            // TODO: should this be a db lock?
130
 
            scoped_ptr<Lock::ScopedLock> lk( ai->isAuthorized( dbname.c_str() ) ? 
131
 
                                             static_cast<Lock::ScopedLock*>( new Lock::GlobalWrite() ) : 
132
 
                                             static_cast<Lock::ScopedLock*>( new Lock::GlobalRead() ) );
 
132
            Lock::GlobalWrite lk;
133
133
            Client::Context ctx( dbname );
134
134
 
135
135
            return dbEval(dbname, cmdObj, result, errmsg);