~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/get_password.cc

  • Committer: Monty Taylor
  • Date: 2010-06-19 16:36:52 UTC
  • mto: This revision was merged to the branch mainline in revision 1628.
  • Revision ID: mordred@inaugust.com-20100619163652-6fej38011wsop52k
Moved password parsing code into get_password.cc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "config.h"
26
26
#include "client/get_password.h"
27
27
 
 
28
#include <string>
 
29
 
28
30
#include <string.h>
29
31
#include <stdio.h>
30
32
#include <stdlib.h>
45
47
#  endif
46
48
#endif
47
49
 
 
50
using namespace std;
 
51
 
 
52
bool tty_password= false;
 
53
const std::string PASSWORD_SENTINEL("\0\0\0\0\0", 5);
 
54
 
48
55
/*
49
56
  Can't use fgets, because readline will get confused
50
57
  length is max number of chars in to, not counting \0
133
140
 
134
141
  return strdup(buff);
135
142
}
 
143
 
 
144
pair<string, string> parse_password_arg(string s)
 
145
{
 
146
  if (s.find("--password") == 0)
 
147
  {
 
148
    if (s == "--password")
 
149
    {
 
150
      tty_password= true;
 
151
      //check if no argument is passed.
 
152
      return make_pair("password", PASSWORD_SENTINEL);
 
153
    }
 
154
 
 
155
    if (s.substr(10,3) == "=\"\"" || s.substr(10,3) == "=''")
 
156
    {
 
157
      // Check if --password="" or --password=''
 
158
      return make_pair("password", PASSWORD_SENTINEL);
 
159
    }
 
160
    
 
161
    if(s.substr(10) == "=" && s.length() == 11)
 
162
    {
 
163
      // check if --password= and return a default value
 
164
      return make_pair("password", PASSWORD_SENTINEL);
 
165
    }
 
166
  }
 
167
 
 
168
  return make_pair(string(""), string(""));
 
169
}
 
170