File: v2client_wrappers.c

package info (click to toggle)
cvm 0.90-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 836 kB
  • ctags: 555
  • sloc: ansic: 3,848; sh: 1,131; makefile: 118; sql: 15
file content (73 lines) | stat: -rw-r--r-- 2,299 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* cvm/v2client_wrappers.c - CVM version 2 client library wrapper functions
 * Copyright (C)2006  Bruce Guenter <bruce@untroubled.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include <string.h>
#include "v2client.h"
#include "credentials.h"

static unsigned add(struct cvm_credential* creds,
		    unsigned i, unsigned type, const char* value)
{
  if (value == 0)
    return i;
  if (value[0] == 0)
    return i;
  creds[i].type = type;
  if (!str_copys(&creds[i].value, value))
    return 0;
  return i + 1;
}

static int doit(struct cvm_credential creds[],
		const char* module,
		const char* account,
		const char* domain,
		const char* password,
		int split_account)
{
  unsigned i;
  creds[0].type = CVM_CRED_ACCOUNT;
  if (!str_copys(&creds[0].value, account))
    return CVME_IO;
  if ((i = add(creds, 1, CVM_CRED_DOMAIN, domain)) == 0)
    return CVME_IO;
  if (split_account) {
    cvm_client_split_account(&creds[0].value, &creds[1].value);
    if (i == 1)
      if ((i = add(creds, i, CVM_CRED_DOMAIN, creds[i].value.s)) == 0)
	return CVME_IO;
  }
  if ((i = add(creds, i, CVM_CRED_PASSWORD, password)) == 0)
    return CVME_IO;
  return cvm_client_authenticate(module, i, creds);
}

int cvm_client_authenticate_password(const char* module,
			      const char* account,
			      const char* domain,
			      const char* password,
			      int split_account)
{
  struct cvm_credential creds[3];
  unsigned i;
  int result;
  memset(creds, 0, sizeof creds);
  result = doit(creds, module, account, domain, password, split_account);
  for (i = 0; i < 3; ++i)
    str_free(&creds[i].value);
  return result;
}