~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to dttools/src/password_cache.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
 
3
Copyright (C) 2005- The University of Notre Dame
 
4
This software is distributed under the GNU General Public License.
 
5
See the password COPYING for details.
 
6
*/
 
7
 
 
8
#include "password_cache.h"
 
9
 
 
10
#include <string.h>
 
11
#include <stdio.h>
 
12
#include <stdlib.h>
 
13
 
 
14
struct password_cache *password_cache_init( const char *uname, const char *pwd ) {
 
15
        struct password_cache *p = malloc(sizeof(*p));
 
16
        if(!p) return 0;
 
17
 
 
18
        p->username = strdup(uname);
 
19
        p->password = strdup(pwd);
 
20
        return p;
 
21
}
 
22
 
 
23
void password_cache_delete( struct password_cache *p ) {
 
24
        if(p) {
 
25
                password_cache_cleanup(p);
 
26
                free(p);
 
27
        }
 
28
}
 
29
 
 
30
void password_cache_cleanup( struct password_cache *p ) {
 
31
        int len;
 
32
 
 
33
        len = strlen(p->username);
 
34
        memset(p->username, 0, len);
 
35
        free(p->username);
 
36
        p->username = NULL;
 
37
 
 
38
        len = strlen(p->password);
 
39
        memset(p->password, 0, len);
 
40
        free(p->password);
 
41
        p->password = NULL;
 
42
}
 
43
 
 
44
int password_cache_register( struct password_cache *p, const char *uname, const char *pwd ) {
 
45
        if(!p) return -1;
 
46
        password_cache_cleanup(p);
 
47
        p->username = strdup(uname);
 
48
        p->password = strdup(pwd);
 
49
        return 0;
 
50
}
 
51
 
 
52
int password_cache_full( struct password_cache *c ) {
 
53
        if(c->username && c->password) return 1;
 
54
        else return 0;
 
55
}
 
56