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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/* This file is part of Eclat.
Copyright (C) 2012 Sergey Poznyakoff.
Eclat 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 3, or (at your option)
any later version.
Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>. */
#include "eclat.h"
char *access_file_name;
static void
skipline(FILE *fp)
{
int c;
while ((c = getc(fp)) != EOF && c != '\n')
;
}
int
access_file_lookup(const char *id, char **access_key_ptr, char **secret_key_ptr)
{
int rc;
int c;
FILE *fp;
size_t line = 0;
struct grecs_txtacc *acc;
if (!access_file_name)
return 1;
fp = fopen(access_file_name, "r");
if (!fp) {
err("cannot open \"%s\": %s",
access_file_name, strerror(errno));
return 1;
}
while ((c = getc(fp)) != EOF) {
line++;
while (c != EOF && (c == ' ' || c == '\t'))
c = getc(fp);
if (c == '\n')
continue;
if (c == '#') {
skipline(fp);
continue;
}
if (c == EOF)
break;
if (id) {
const char *p;
for (p = id; c != EOF && c != ':' && *p == c; p++)
c = getc(fp);
if (c == EOF)
break;
if (c == '\n')
continue;
if (c != ':') {
skipline(fp);
continue;
}
} else {
acc = grecs_txtacc_create();
while ((c = getc(fp)) != EOF && c != ':') {
if (c == '\n') {
err("%s:%u: incomplete line",
access_file_name, line);
break;
}
grecs_txtacc_grow_char(acc, c);
}
if (c == ':') {
grecs_txtacc_grow_char(acc, 0);
*access_key_ptr = grecs_txtacc_finish(acc, 1);
}
grecs_txtacc_free(acc);
}
break;
}
if (c == ':') {
acc = grecs_txtacc_create();
while ((c = getc(fp)) != EOF && c != '\n')
grecs_txtacc_grow_char(acc, c);
grecs_txtacc_grow_char(acc, 0);
*secret_key_ptr = grecs_txtacc_finish(acc, 1);
rc = 0;
} else
rc = 1;
fclose(fp);
return rc;
}
|