~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzleclient/libdrizzle.c

  • Committer: Brian Aker
  • Date: 2009-03-10 02:20:19 UTC
  • mto: This revision was merged to the branch mainline in revision 925.
  • Revision ID: brian@tangent.org-20090310022019-y8hiqhc4yn25ovnq
Remove Change User code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
  }
109
109
}
110
110
 
111
 
/**************************************************************************
112
 
  Change user and database
113
 
**************************************************************************/
114
 
 
115
 
int drizzleclient_cli_read_change_user_result(DRIZZLE *drizzle)
116
 
{
117
 
  uint32_t pkt_length;
118
 
 
119
 
  pkt_length= drizzleclient_cli_safe_read(drizzle);
120
 
 
121
 
  if (pkt_length == packet_error)
122
 
    return 1;
123
 
 
124
 
  return 0;
125
 
}
126
 
 
127
 
bool drizzleclient_change_user(DRIZZLE *drizzle, const char *user,
128
 
                                 const char *passwd, const char *db)
129
 
{
130
 
  char buff[USERNAME_LENGTH+SCRAMBLED_PASSWORD_CHAR_LENGTH+NAME_LEN+2];
131
 
  char *end= buff;
132
 
  int rc;
133
 
 
134
 
  /* Use an empty string instead of NULL. */
135
 
 
136
 
  if (!user)
137
 
    user="";
138
 
  if (!passwd)
139
 
    passwd="";
140
 
 
141
 
  /* Store user into the buffer */
142
 
  end= strncpy(end, user, USERNAME_LENGTH) + USERNAME_LENGTH + 1;
143
 
 
144
 
  /* write scrambled password according to server capabilities */
145
 
  if (passwd[0])
146
 
  {
147
 
    {
148
 
      *end++= SCRAMBLE_LENGTH;
149
 
      end+= SCRAMBLE_LENGTH;
150
 
    }
151
 
  }
152
 
  else
153
 
    *end++= '\0';                               /* empty password */
154
 
  /* Add database if needed */
155
 
  end= strncpy(end, db ? db : "", NAME_LEN) + NAME_LEN + 1;
156
 
 
157
 
  /* Add character set number. */
158
 
  if (drizzle->server_capabilities & CLIENT_SECURE_CONNECTION)
159
 
  {
160
 
    int2store(end, (uint16_t) 45); // utf8mb4 number from mystrings/ctype-utf8.c
161
 
    end+= 2;
162
 
  }
163
 
 
164
 
  /* Write authentication package */
165
 
  (void)simple_command(drizzle,COM_CHANGE_USER, (unsigned char*) buff, (uint32_t) (end-buff), 1);
166
 
 
167
 
  rc= (*drizzle->methods->read_change_user_result)(drizzle);
168
 
 
169
 
  if (rc == 0)
170
 
  {
171
 
    /* Free old connect information */
172
 
    if(drizzle->user)
173
 
      free(drizzle->user);
174
 
    if(drizzle->passwd)
175
 
      free(drizzle->passwd);
176
 
    if(drizzle->db)
177
 
      free(drizzle->db);
178
 
 
179
 
    /* alloc new connect information */
180
 
    drizzle->user= strdup(user);
181
 
    drizzle->passwd= strdup(passwd);
182
 
    drizzle->db= db ? strdup(db) : 0;
183
 
  }
184
 
 
185
 
  return(rc);
186
 
}
187
 
 
188
111
#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL)
189
112
struct passwd *getpwuid(uid_t);
190
113
char* getlogin(void);