Deleted Added
full compact
2c2
< * Copyright (c) 1997-2001 Kungliga Tekniska H�gskolan
---
> * Copyright (c) 1997-2003 Kungliga Tekniska H�gskolan
36c36
< RCSID("$Id: afslog.c,v 1.16 2001/05/16 22:10:15 assar Exp $");
---
> RCSID("$Id: afslog.c,v 1.21.2.1 2003/04/23 18:04:26 lha Exp $");
38a39
> #ifdef KRB5
39a41,44
> #endif
> #ifdef KRB4
> #include <krb.h>
> #endif
54a60,65
> #ifdef KRB4
> static int use_krb4 = 1;
> #endif
> #ifdef KRB5
> static int use_krb5 = 1;
> #endif
57,58c68,69
< { "cell", 'c', arg_strings, &cells, "cells to get tokens for", "cells" },
< { "file", 'p', arg_strings, &files, "files to get tokens for", "paths" },
---
> { "cell", 'c', arg_strings, &cells, "cells to get tokens for", "cell" },
> { "file", 'p', arg_strings, &files, "files to get tokens for", "path" },
60a72,77
> #ifdef KRB4
> { "v4", 0, arg_negative_flag, &use_krb4, "use Kerberos 4" },
> #endif
> #ifdef KRB5
> { "v5", 0, arg_negative_flag, &use_krb5, "use Kerberos 5" },
> #endif
70a88,92
> #ifdef KRB5
> krb5_context context;
> krb5_ccache id;
> #endif
>
72c94
< expand_cell_name(const char *cell)
---
> expand_one_file(FILE *f, const char *cell)
74,75c96
< FILE *f;
< static char buf[128];
---
> static char buf[1024];
78,80d98
< f = fopen(_PATH_CELLSERVDB, "r");
< if(f == NULL)
< return cell;
82,83c100,101
< if(buf[0] == '>'){
< for(p=buf; *p && !isspace((unsigned char)*p) && *p != '#'; p++)
---
> if(buf[0] == '>') {
> for(p = buf; *p && !isspace((unsigned char)*p) && *p != '#'; p++)
86,87c104
< if(strstr(buf, cell)){
< fclose(f);
---
> if(strncmp(buf + 1, cell, strlen(cell)) == 0)
89d105
< }
91c107
< buf[0] = 0;
---
> buf[0] = '\0';
93c109,130
< fclose(f);
---
> return NULL;
> }
>
> static const char *
> expand_cell_name(const char *cell)
> {
> FILE *f;
> const char *c;
> const char **fn, *files[] = { _PATH_CELLSERVDB,
> _PATH_ARLA_CELLSERVDB,
> _PATH_OPENAFS_DEBIAN_CELLSERVDB,
> _PATH_ARLA_DEBIAN_CELLSERVDB,
> NULL };
> for(fn = files; *fn; fn++) {
> f = fopen(*fn, "r");
> if(f == NULL)
> continue;
> c = expand_one_file(f, cell);
> fclose(f);
> if(c)
> return c;
> }
137c174
< arg_printusage(args, num_args, NULL, "[cell]... [path]...");
---
> arg_printusage(args, num_args, NULL, "[cell|path]...");
140a178,182
> struct cell_list {
> char *cell;
> struct cell_list *next;
> } *cell_list;
>
142,143c184
< afslog_cell(krb5_context context, krb5_ccache id,
< const char *cell, int expand)
---
> afslog_cell(const char *cell, int expand)
144a186
> struct cell_list *p, **q;
149c191
< krb5_warnx(context, "No cell matching \"%s\" found.", cell);
---
> warnx("No cell matching \"%s\" found.", cell);
152,153c194,195
< if(verbose)
< krb5_warnx(context, "Cell \"%s\" expanded to \"%s\"", cell, c);
---
> if(verbose && strcmp(c, cell) != 0)
> warnx("Cell \"%s\" expanded to \"%s\"", cell, c);
155c197,212
< return krb5_afslog(context, id, c, realm);
---
> /* add to list of cells to get tokens for, and also remove
> duplicates; the actual afslog takes place later */
> for(p = cell_list, q = &cell_list; p; q = &p->next, p = p->next)
> if(strcmp(p->cell, c) == 0)
> return 0;
> p = malloc(sizeof(*p));
> if(p == NULL)
> return -1;
> p->cell = strdup(c);
> if(p->cell == NULL) {
> free(p);
> return -1;
> }
> p->next = NULL;
> *q = p;
> return 0;
159,160c216
< afslog_file(krb5_context context, krb5_ccache id,
< const char *path)
---
> afslog_file(const char *path)
164c220
< krb5_warnx(context, "No cell found for file \"%s\".", path);
---
> warnx("No cell found for file \"%s\".", path);
168,169c224,225
< krb5_warnx(context, "File \"%s\" lives in cell \"%s\"", path, cell);
< return afslog_cell(context, id, cell, 0);
---
> warnx("File \"%s\" lives in cell \"%s\"", path, cell);
> return afslog_cell(cell, 0);
171a228,267
> static int
> do_afslog(const char *cell)
> {
> int k5ret, k4ret;
>
> k5ret = k4ret = 0;
>
> #ifdef KRB5
> if(context != NULL && id != NULL && use_krb5) {
> k5ret = krb5_afslog(context, id, cell, NULL);
> if(k5ret == 0)
> return 0;
> }
> #endif
> #if KRB4
> if (use_krb4) {
> k4ret = krb_afslog(cell, NULL);
> if(k4ret == 0)
> return 0;
> }
> #endif
> #ifdef KRB5
> if (k5ret)
> warnx("krb5_afslog(%s): %s", cell, krb5_get_err_text(context, k5ret));
> #endif
> #ifdef KRB4
> if (k4ret)
> warnx("krb_afslog(%s): %s", cell, krb_get_err_text(k4ret));
> #endif
> if (k5ret || k4ret)
> return 1;
> return 0;
> }
>
> static void
> log_func(void *ctx, const char *str)
> {
> fprintf(stderr, "%s\n", str);
> }
>
176,177d271
< krb5_context context;
< krb5_ccache id;
180a275,276
> int failed = 0;
> struct cell_list *p;
193,195d288
< ret = krb5_init_context(&context);
< if (ret)
< errx (1, "krb5_init_context failed: %d", ret);
197,198c290
< krb5_errx(context, 1,
< "AFS doesn't seem to be present on this machine");
---
> errx(1, "AFS does not seem to be present on this machine");
204c296,307
< krb5_cc_default(context, &id);
---
> #ifdef KRB5
> ret = krb5_init_context(&context);
> if (ret)
> context = NULL;
> else
> if(krb5_cc_default(context, &id) != 0)
> id = NULL;
> #endif
>
> if (verbose)
> kafs_set_verbose(log_func, NULL);
>
207c310
< afslog_file(context, id, files.strings[i]);
---
> afslog_file(files.strings[i]);
209d311
< free_getarg_strings (&files);
210a313
> free_getarg_strings (&files);
212c315
< afslog_cell(context, id, cells.strings[i], 1);
---
> afslog_cell(cells.strings[i], 1);
214d316
< free_getarg_strings (&cells);
215a318
> free_getarg_strings (&cells);
222c325
< afslog_file(context, id, argv[i]);
---
> afslog_file(argv[i]);
224c327
< afslog_cell(context, id, argv[i], 1);
---
> afslog_cell(argv[i], 1);
227c330,337
< krb5_afslog(context, id, NULL, NULL);
---
> if(do_afslog(NULL))
> failed++;
> } else
> for(p = cell_list; p; p = p->next) {
> if(verbose)
> warnx("Getting tokens for cell \"%s\"", p->cell);
> if(do_afslog(p->cell))
> failed++;
230c340
< return ret;
---
> return failed;