~ubuntu-branches/ubuntu/breezy/pam/breezy

« back to all changes in this revision

Viewing changes to Linux-PAM/conf/pam_conv1/pam_conv.y

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2004-06-28 14:28:08 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040628142808-adikk7vtfg3pzcjw
Tags: 0.76-22
* Add uploaders
* Document location of repository
* Fix options containing arguments in pam_unix, Closes: #254904

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%{
 
2
 
 
3
/*
 
4
 * $Id: pam_conv.y,v 1.1.1.2 2002/09/15 20:08:22 hartmans Exp $
 
5
 *
 
6
 * Copyright (c) Andrew G. Morgan 1997 <morgan@parc.power.net>
 
7
 *
 
8
 * This file is covered by the Linux-PAM License (which should be
 
9
 * distributed with this file.)
 
10
 */
 
11
 
 
12
    const static char bisonid[]=
 
13
        "$Id: pam_conv.y,v 1.1.1.2 2002/09/15 20:08:22 hartmans Exp $\n"
 
14
        "Copyright (c) Andrew G. Morgan 1997-8 <morgan@linux.kernel.org>\n";
 
15
 
 
16
#include <string.h>
 
17
#include <stdio.h>
 
18
#include <stdarg.h>
 
19
#include <stdlib.h>
 
20
 
 
21
    int current_line=1;
 
22
    extern char *yytext;
 
23
 
 
24
/* XXX - later we'll change this to be the specific conf file(s) */
 
25
#define newpamf stderr
 
26
 
 
27
#define PAM_D                "./pam.d"
 
28
#define PAM_D_MODE           0755
 
29
#define PAM_D_MAGIC_HEADER   \
 
30
    "#%PAM-1.0\n" \
 
31
    "#[For version 1.0 syntax, the above header is optional]\n"
 
32
 
 
33
#define PAM_D_FILE_FMT       PAM_D "/%s"
 
34
 
 
35
    const char *old_to_new_ctrl_flag(const char *old);
 
36
    void yyerror(const char *format, ...);
 
37
%}
 
38
 
 
39
%union {
 
40
    int def;
 
41
    char *string;
 
42
}
 
43
 
 
44
%token NL EOFILE TOK
 
45
 
 
46
%type <string> tok path tokenls
 
47
 
 
48
%start complete
 
49
 
 
50
%%
 
51
 
 
52
complete
 
53
:
 
54
| complete NL
 
55
| complete line
 
56
| complete EOFILE {
 
57
    return 0;
 
58
}
 
59
;
 
60
 
 
61
line
 
62
: tok tok tok path tokenls NL {
 
63
    char *filename;
 
64
    FILE *conf;
 
65
    int i;
 
66
 
 
67
    /* make sure we have lower case */
 
68
    for (i=0; $1[i]; ++i) {
 
69
        $1[i] = tolower($1[i]);
 
70
    }
 
71
 
 
72
    /* $1 = service-name */
 
73
    yyerror("Appending to " PAM_D "/%s", $1);
 
74
 
 
75
    filename = malloc(strlen($1) + sizeof(PAM_D) + 6);
 
76
    sprintf(filename, PAM_D_FILE_FMT, $1);
 
77
    conf = fopen(filename, "r");
 
78
    if (conf == NULL) {
 
79
        /* new file */
 
80
        conf = fopen(filename, "w");
 
81
        if (conf != NULL) {
 
82
            fprintf(conf, PAM_D_MAGIC_HEADER);
 
83
            fprintf(conf,
 
84
                    "#\n"
 
85
                    "# The PAM configuration file for the `%s' service\n"
 
86
                    "#\n", $1);
 
87
        }
 
88
    } else {
 
89
        fclose(conf);
 
90
        conf = fopen(filename, "a");
 
91
    }
 
92
    if (conf == NULL) {
 
93
        yyerror("trouble opening %s - aborting", filename);
 
94
        exit(1);
 
95
    }
 
96
    free(filename);
 
97
 
 
98
    /* $2 = module-type */
 
99
    fprintf(conf, "%-10s", $2);
 
100
    free($2);
 
101
 
 
102
    /* $3 = required etc. */
 
103
    {
 
104
        const char *trans;
 
105
 
 
106
        trans = old_to_new_ctrl_flag($3);
 
107
        free($3);
 
108
        fprintf(conf, " %-10s", trans);
 
109
    }
 
110
 
 
111
    /* $4 = module-path */
 
112
    fprintf(conf, " %s", $4);
 
113
    free($4);
 
114
 
 
115
    /* $5 = arguments */
 
116
    if ($5 != NULL) {
 
117
        fprintf(conf, " \\\n\t\t%s", $5);
 
118
        free($5);
 
119
    }
 
120
 
 
121
    /* end line */
 
122
    fprintf(conf, "\n");
 
123
 
 
124
    fclose(conf);
 
125
}
 
126
| error NL {
 
127
    yyerror("malformed line");
 
128
}
 
129
;
 
130
 
 
131
tokenls
 
132
: {
 
133
    $$=NULL;
 
134
}
 
135
| tokenls tok {
 
136
    int len;
 
137
 
 
138
    if ($1) {
 
139
        len = strlen($1) + strlen($2) + 2;
 
140
        $$ = malloc(len);
 
141
        sprintf($$,"%s %s",$1,$2);
 
142
        free($1);
 
143
        free($2);
 
144
    } else {
 
145
        $$ = $2;
 
146
    }
 
147
}
 
148
;
 
149
 
 
150
path
 
151
: TOK {
 
152
    /* XXX - this could be used to check if file present */
 
153
    $$ = strdup(yytext);
 
154
}
 
155
 
 
156
tok
 
157
: TOK {
 
158
    $$ = strdup(yytext);
 
159
}
 
160
 
 
161
%%
 
162
 
 
163
#include "lex.yy.c"
 
164
 
 
165
const char *old_to_new_ctrl_flag(const char *old)
 
166
{
 
167
    static const char *clist[] = {
 
168
        "requisite",
 
169
        "required",
 
170
        "sufficient",
 
171
        "optional",
 
172
        NULL,
 
173
    };
 
174
    int i;
 
175
 
 
176
    for (i=0; clist[i]; ++i) {
 
177
        if (strcasecmp(clist[i], old) == 0) {
 
178
            break;
 
179
        }
 
180
    }
 
181
 
 
182
    return clist[i];
 
183
}
 
184
 
 
185
void yyerror(const char *format, ...)
 
186
{
 
187
    va_list args;
 
188
 
 
189
    fprintf(stderr, "line %d: ", current_line);
 
190
    va_start(args, format);
 
191
    vfprintf(stderr, format, args);
 
192
    va_end(args);
 
193
    fprintf(stderr, "\n");
 
194
}
 
195
 
 
196
int main(int argc, char *argv[])
 
197
{
 
198
    if (mkdir(PAM_D, PAM_D_MODE) != 0) {
 
199
        yyerror(PAM_D " already exists.. aborting");
 
200
        exit(1);
 
201
    }
 
202
    yyparse();
 
203
    exit(0);
 
204
}