~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/function/str/user.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
 
22
 
#include <drizzled/function/str/user.h>
23
 
#include <drizzled/session.h>
24
 
 
25
 
namespace drizzled
26
 
{
27
 
 
28
 
/**
29
 
  @todo
30
 
  make USER() replicate properly (currently it is replicated to "")
31
 
*/
32
 
bool Item_func_user::init(const char *user, const char *host)
33
 
{
34
 
  assert(fixed == 1);
35
 
 
36
 
  // For system threads (e.g. replication SQL thread) user may be empty
37
 
  if (user)
38
 
  {
39
 
    const CHARSET_INFO * const cs= str_value.charset();
40
 
    uint32_t res_length= (strlen(user)+strlen(host)+2) * cs->mbmaxlen;
41
 
 
42
 
    if (str_value.alloc(res_length))
43
 
    {
44
 
      null_value=1;
45
 
      return true;
46
 
    }
47
 
 
48
 
    res_length=cs->cset->snprintf(cs, (char*)str_value.ptr(), res_length,
49
 
                                  "%s@%s", user, host);
50
 
    str_value.length(res_length);
51
 
    str_value.mark_as_const();
52
 
  }
53
 
  return false;
54
 
}
55
 
 
56
 
 
57
 
bool Item_func_user::fix_fields(Session *session, Item **ref)
58
 
{
59
 
  return (Item_str_func::fix_fields(session, ref) ||
60
 
          init(session->getSecurityContext().getUser().c_str(),
61
 
               session->getSecurityContext().getIp().c_str()));
62
 
}
63
 
 
64
 
 
65
 
bool Item_func_current_user::fix_fields(Session *session, Item **ref)
66
 
{
67
 
  if (Item_str_func::fix_fields(session, ref))
68
 
    return true;
69
 
 
70
 
  const SecurityContext *ctx= &session->getSecurityContext();
71
 
  return init(ctx->getUser().c_str(), ctx->getIp().c_str());
72
 
}
73
 
 
74
 
} /* namespace drizzled */