~ubuntu-branches/ubuntu/oneiric/openafs/oneiric-201305130334

« back to all changes in this revision

Viewing changes to src/auth/ktc.c

  • Committer: Bazaar Package Importer
  • Author(s): Russ Allbery
  • Date: 2008-09-22 19:07:02 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080922190702-59m13d7kn6gkw32d
Tags: 1.4.7.dfsg1-6
* Apply upstream patch to free /proc entries in the correct order.
  Thanks, Marc Dionne.  (Closes: #493914)
* Apply upstream deltas to support 2.6.27 kernels and to stop using
  COMMON_KERN_CFLAGS for all 2.6 kernels uniformly, which fixes
  problems on amd64 with newer kernels.  Thanks, Björn Torkelsson.
  (LP: #267504)
* Translation updates:
  - Swedish, thanks Martin Bagge.  (Closes: #493120)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#endif
18
18
 
19
19
RCSID
20
 
    ("$Header: /cvs/openafs/src/auth/ktc.c,v 1.15.2.6 2006/10/06 12:44:40 shadow Exp $");
 
20
    ("$Header: /cvs/openafs/src/auth/ktc.c,v 1.15.2.10 2007/12/13 18:54:09 shadow Exp $");
21
21
 
22
22
#if defined(UKERNEL)
23
23
#include "afs/sysincludes.h"
40
40
#include <unistd.h>
41
41
#endif
42
42
#include <stdio.h>
 
43
#include <stdlib.h>
43
44
#include <afs/stds.h>
44
45
#include <afs/pthread_glock.h>
45
46
#include <sys/types.h>
49
50
#include <errno.h>
50
51
#include <sys/ioctl.h>
51
52
#include <netinet/in.h>
52
 
#ifdef HAVE_STRING_H
53
53
#include <string.h>
54
 
#else
55
 
#ifdef HAVE_STRINGS_H
56
 
#include <strings.h>
57
 
#endif
58
 
#endif
59
54
#include <afs/vice.h>
60
55
#ifdef  AFS_AIX_ENV
61
56
#include <sys/lockf.h>
 
57
#ifdef AFS_AIX51_ENV
 
58
#include <sys/cred.h>
 
59
#include <sys/pag.h>
 
60
#endif
62
61
#endif
63
62
#ifdef HAVE_UNISTD_H
64
63
#include <unistd.h>
128
127
/* the following routines aren't static anymore on behalf of the kerberos IV
129
128
 * compatibility library built in subtree krb.
130
129
 */
131
 
int afs_tf_init(), afs_tf_get_pname(), afs_tf_get_pinst(), afs_tf_get_cred();
132
 
int afs_tf_save_cred(), afs_tf_close(), afs_tf_create();
133
 
int afs_tf_dest_tkt();
134
 
static void ktc_LocalCell();
 
130
int afs_tf_init(char *, int);
 
131
int afs_tf_get_pname(char *);
 
132
int afs_tf_get_pinst(char *);
 
133
int afs_tf_get_cred(struct ktc_principal *, struct ktc_token *);
 
134
int afs_tf_save_cred(struct ktc_principal *, struct ktc_token *, 
 
135
                     struct ktc_principal *);
 
136
int afs_tf_close(void);
 
137
int afs_tf_create(char *, char *);
 
138
int afs_tf_dest_tkt(void);
 
139
static void ktc_LocalCell(void);
135
140
#endif /* AFS_KERBEROS_ENV */
136
141
 
137
142
#ifdef AFS_DUX40_ENV
251
256
 * now. */
252
257
 
253
258
static int
254
 
NewSetToken(aserver, atoken, aclient, flags)
255
 
     struct ktc_principal *aserver;
256
 
     struct ktc_principal *aclient;
257
 
     struct ktc_token *atoken;
258
 
     afs_int32 flags;
 
259
NewSetToken(struct ktc_principal *aserver, 
 
260
            struct ktc_token *atoken, 
 
261
            struct ktc_principal *aclient, 
 
262
            afs_int32 flags)
259
263
{
260
264
    TRY_KERNEL(KTC_SETTOKEN_OP, aserver, aclient, atoken,
261
265
               sizeof(struct ktc_token));
267
271
(3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
268
272
 
269
273
static int
270
 
OldSetToken(aserver, atoken, aclient, flags)
271
 
     struct ktc_principal *aserver, *aclient;
272
 
     struct ktc_token *atoken;
273
 
     afs_int32 flags;
 
274
OldSetToken(struct ktc_principal *aserver, struct ktc_token *atoken, 
 
275
            struct ktc_principal *aclient, afs_int32 flags)
274
276
{
275
277
    struct ViceIoctl iob;
276
278
    char tbuffer[MAXPIOCTLTOKENLEN];
414
416
    return 0;
415
417
}
416
418
 
417
 
 
418
 
ktc_SetToken(aserver, atoken, aclient, flags)
419
 
     struct ktc_principal *aserver;
420
 
     struct ktc_principal *aclient;
421
 
     struct ktc_token *atoken;
422
 
     afs_int32 flags;
 
419
int
 
420
ktc_SetToken(struct ktc_principal *aserver,
 
421
    struct ktc_token *atoken,
 
422
    struct ktc_principal *aclient,
 
423
    afs_int32 flags)
423
424
{
424
425
    int ncode, ocode;
425
426
 
487
488
/* get token, given server we need and token buffer.  aclient will eventually
488
489
 * be set to our identity to the server.
489
490
 */
490
 
ktc_GetToken(aserver, atoken, atokenLen, aclient)
491
 
     struct ktc_principal *aserver, *aclient;
492
 
     int atokenLen;
493
 
     struct ktc_token *atoken;
 
491
int
 
492
ktc_GetToken(struct ktc_principal *aserver, struct ktc_token *atoken, 
 
493
             int atokenLen, struct ktc_principal *aclient)
494
494
{
495
495
    struct ViceIoctl iob;
496
496
    char tbuffer[MAXPIOCTLTOKENLEN];
502
502
    afs_int32 temp;
503
503
    int maxLen;                 /* biggest ticket we can copy */
504
504
    int tktLen;                 /* server ticket length */
 
505
#ifdef AFS_KERBEROS_ENV
505
506
    char found = 0;
 
507
#endif
506
508
 
507
509
    LOCK_GLOBAL_MUTEX;
508
510
#ifndef NO_AFS_CLIENT
540
542
                    found = 1;
541
543
            } else {
542
544
                char tmpstring[MAXHOSTCHARS];
543
 
                afs_tf_get_pname(&tmpstring);
544
 
                afs_tf_get_pinst(&tmpstring);
 
545
                afs_tf_get_pname(tmpstring);
 
546
                afs_tf_get_pinst(tmpstring);
545
547
                found = 1;
546
548
            }
547
549
        }
671
673
 * NOT IMPLEMENTED YET!
672
674
 */
673
675
#ifndef NO_AFS_CLIENT
674
 
ktc_ForgetToken(aserver)
675
 
     struct ktc_principal *aserver;
 
676
int
 
677
ktc_ForgetToken(struct ktc_principal *aserver)
676
678
{
677
679
    int rc;
678
680
 
689
691
 * next rock in (*aindex).  (*aserver) is set to the relevant ticket on
690
692
 * success.  */
691
693
 
692
 
ktc_ListTokens(aprevIndex, aindex, aserver)
693
 
     int aprevIndex, *aindex;
694
 
     struct ktc_principal *aserver;
 
694
int
 
695
ktc_ListTokens(int aprevIndex,
 
696
    int *aindex,
 
697
    struct ktc_principal *aserver)
695
698
{
696
699
    struct ViceIoctl iob;
697
700
    char tbuffer[MAXPIOCTLTOKENLEN];
841
844
/* discard all tokens from this user's cache */
842
845
 
843
846
static int
844
 
NewForgetAll()
 
847
NewForgetAll(void)
845
848
{
846
849
#ifndef NO_AFS_CLIENT
847
850
    TRY_KERNEL(KTC_FORGETALLTOKENS_OP, 0, 0, 0, 0);
850
853
}
851
854
 
852
855
static int
853
 
OldForgetAll()
 
856
OldForgetAll(void)
854
857
{
855
858
    struct ViceIoctl iob;
856
859
    register afs_int32 code;
872
875
}
873
876
 
874
877
int
875
 
ktc_ForgetAllTokens()
 
878
ktc_ForgetAllTokens(void)
876
879
{
877
880
    int ncode, ocode;
878
881
 
900
903
/* ktc_OldPioctl - returns a boolean true if the kernel supports only the old
901
904
 * pioctl interface for delivering AFS tickets to the cache manager. */
902
905
 
903
 
ktc_OldPioctl()
 
906
int
 
907
ktc_OldPioctl(void)
904
908
{
905
909
    int rc;
906
910
    LOCK_GLOBAL_MUTEX;
950
954
 *      c. In tf_close, be sure it gets reinitialized to a negative
951
955
 *         number. 
952
956
 */
953
 
static fd = -1;
954
 
static curpos;                  /* Position in tfbfr */
955
 
static lastpos;                 /* End of tfbfr */
 
957
static int fd = -1;
 
958
static int curpos;                      /* Position in tfbfr */
 
959
static int lastpos;                     /* End of tfbfr */
956
960
static char tfbfr[BUFSIZ];      /* Buffer for ticket data */
957
961
 
958
 
static tf_gets(), tf_read();
 
962
static int tf_gets(char *, int);
 
963
static int tf_read(char *, int);
959
964
 
960
965
/*
961
966
 * This file contains routines for manipulating the ticket cache file.
1020
1025
 * TKT_FIL_LCK  - couldn't lock the file, even after a retry
1021
1026
 */
1022
1027
 
1023
 
afs_tf_init(tf_name, rw)
1024
 
     char *tf_name;
 
1028
int
 
1029
afs_tf_init(char *tf_name, int rw)
1025
1030
{
1026
1031
    int wflag;
1027
1032
    int me;
1114
1119
 * was longer than MAXKTCNAMELEN, TKT_FIL_FMT is returned. 
1115
1120
 */
1116
1121
 
1117
 
afs_tf_get_pname(p)
1118
 
     char *p;
 
1122
int
 
1123
afs_tf_get_pname(char *p)
1119
1124
{
1120
1125
    if (fd < 0) {
1121
1126
        return TKT_FIL_INI;
1135
1140
 * instance may be null. 
1136
1141
 */
1137
1142
 
1138
 
afs_tf_get_pinst(inst)
1139
 
     char *inst;
 
1143
int
 
1144
afs_tf_get_pinst(char *inst)
1140
1145
{
1141
1146
    if (fd < 0) {
1142
1147
        return TKT_FIL_INI;
1157
1162
 * EOF          - end of file encountered
1158
1163
 */
1159
1164
 
1160
 
afs_tf_get_cred(principal, token)
1161
 
     struct ktc_principal *principal;
1162
 
     struct ktc_token *token;
 
1165
int
 
1166
afs_tf_get_cred(struct ktc_principal *principal, struct ktc_token *token)
1163
1167
{
1164
1168
    int k_errno;
1165
1169
    int kvno, lifetime;
 
1170
    long mit_compat;            /* MIT Kerberos 5 with Krb4 uses a "long" for issue_date */
1166
1171
 
1167
1172
    if (fd < 0) {
1168
1173
        return TKT_FIL_INI;
1199
1204
        /* don't try to read a silly amount into ticket->dat */
1200
1205
        token->ticketLen > MAXKTCTICKETLEN
1201
1206
        || tf_read((char *)(token->ticket), token->ticketLen) < 1
1202
 
        || tf_read((char *)&(token->startTime),
1203
 
                   sizeof(token->startTime)) < 1) {
 
1207
        || tf_read((char *)&mit_compat, sizeof(mit_compat)) < 1) {
1204
1208
        return TKT_FIL_FMT;
1205
1209
    }
 
1210
    token->startTime = mit_compat;
1206
1211
    token->endTime = life_to_time(token->startTime, lifetime);
1207
1212
    token->kvno = kvno;
1208
1213
    return 0;
1216
1221
 * The return value is not defined.
1217
1222
 */
1218
1223
 
1219
 
afs_tf_close()
 
1224
int
 
1225
afs_tf_close(void)
1220
1226
{
1221
1227
    if (!(fd < 0)) {
1222
1228
#if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_SUN5_ENV)
1228
1234
        fd = -1;                /* see declaration of fd above */
1229
1235
    }
1230
1236
    memset(tfbfr, 0, sizeof(tfbfr));
 
1237
    return 0;
1231
1238
}
1232
1239
 
1233
1240
/*
1248
1255
 *              file is seriously ill.
1249
1256
 */
1250
1257
 
1251
 
static
1252
 
tf_gets(s, n)
1253
 
     register char *s;
 
1258
static int
 
1259
tf_gets(register char *s, int n)
1254
1260
{
1255
 
    register count;
 
1261
    register int count;
1256
1262
 
1257
1263
    if (fd < 0) {
1258
1264
        return TKT_FIL_INI;
1284
1290
 * 0            on end of file or read error
1285
1291
 */
1286
1292
 
1287
 
static
1288
 
tf_read(s, n)
1289
 
     register char *s;
1290
 
     register n;
 
1293
static int
 
1294
tf_read(register char *s, register int n)
1291
1295
{
1292
 
    register count;
 
1296
    register int count;
1293
1297
 
1294
1298
    for (count = n; count > 0; --count) {
1295
1299
        if (curpos >= sizeof(tfbfr)) {
1304
1308
    return n;
1305
1309
}
1306
1310
 
1307
 
char *tkt_string();
1308
 
 
1309
1311
/*
1310
1312
 * afs_tf_save_cred() appends an incoming ticket to the end of the ticket
1311
1313
 * file.  You must call afs_tf_init() before calling afs_tf_save_cred().
1317
1319
 * called previously, and KFAILURE for anything else that went wrong.
1318
1320
 */
1319
1321
 
1320
 
afs_tf_save_cred(aserver, atoken, aclient)
1321
 
     struct ktc_principal *aserver;
1322
 
     struct ktc_principal *aclient;
1323
 
     struct ktc_token *atoken;  /* Token */
 
1322
int
 
1323
afs_tf_save_cred(struct ktc_principal *aserver, 
 
1324
                 struct ktc_token *atoken, 
 
1325
                 struct ktc_principal *aclient)
1324
1326
{
1325
1327
    char realm[MAXKTCREALMLEN + 1];
1326
1328
    char junk[MAXKTCNAMELEN];
1330
1332
    off_t start;
1331
1333
    int lifetime, kvno;
1332
1334
    int count;                  /* count for write */
 
1335
    long mit_compat;            /* MIT Kerberos 5 with Krb4 uses a "long" for issue_date */
1333
1336
 
1334
1337
    if (fd < 0) {               /* fd is ticket file as set by afs_tf_init */
1335
1338
        return TKT_FIL_INI;
1399
1402
    if (write(fd, atoken->ticket, count) != count)
1400
1403
        goto bad;
1401
1404
    /* Issue date */
1402
 
    if (write(fd, (char *)&atoken->startTime, sizeof(afs_int32))
1403
 
        != sizeof(afs_int32))
 
1405
    mit_compat = atoken->startTime;
 
1406
    if (write(fd, (char *)&mit_compat, sizeof(mit_compat))
 
1407
        != sizeof(mit_compat))
1404
1408
        goto bad;
1405
1409
 
1406
1410
    /* Actually, we should check each write for success */
1417
1421
 * <mit-copyright.h>.
1418
1422
 */
1419
1423
 
1420
 
char *getenv();
1421
 
 
1422
1424
/*
1423
1425
 * This routine is used to generate the name of the file that holds
1424
1426
 * the user's cache of server tickets and associated session keys.
1448
1450
 
1449
1451
    LOCK_GLOBAL_MUTEX;
1450
1452
    if (!*krb_ticket_string) {
1451
 
        if (env = getenv("KRBTKFILE")) {
 
1453
        if ((env = getenv("KRBTKFILE"))) {
1452
1454
            (void)strncpy(krb_ticket_string, env,
1453
1455
                          sizeof(krb_ticket_string) - 1);
1454
1456
            krb_ticket_string[sizeof(krb_ticket_string) - 1] = '\0';
1491
1493
 * success, or KFAILURE if something goes wrong.
1492
1494
 */
1493
1495
 
1494
 
afs_tf_create(pname, pinst)
1495
 
     char *pname;
1496
 
     char *pinst;
 
1496
int
 
1497
afs_tf_create(char *pname, char *pinst)
1497
1498
{
1498
1499
    int tktfile;
1499
1500
    int me, metoo;
1570
1571
 * failure.
1571
1572
 */
1572
1573
 
1573
 
afs_tf_dest_tkt()
 
1574
int
 
1575
afs_tf_dest_tkt(void)
1574
1576
{
1575
1577
    char *file = ktc_tkt_string();
1576
1578
    int i, fd;
1610
1612
}
1611
1613
 
1612
1614
static afs_uint32
1613
 
curpag()
 
1615
curpag(void)
1614
1616
{
 
1617
#if defined(AFS_AIX51_ENV)
 
1618
    int code = getpagvalue("afs");
 
1619
    if (code < 0 && errno == EINVAL)
 
1620
        code = 0;
 
1621
    return code;
 
1622
#else
1615
1623
    gid_t groups[NGROUPS_MAX];
1616
1624
    afs_uint32 g0, g1;
1617
1625
    afs_uint32 h, l, ret;
1635
1643
            return -1;
1636
1644
    }
1637
1645
    return -1;
 
1646
#endif
1638
1647
}
1639
1648
 
1640
 
 
1641
 
ktc_newpag()
 
1649
int
 
1650
ktc_newpag(void)
1642
1651
{
1643
1652
    extern char **environ;
1644
1653
 
1657
1666
    if (pag == -1) {
1658
1667
        sprintf(fname, "%s%d", prefix, getuid());
1659
1668
    } else {
1660
 
        sprintf(fname, "%sp%ld", prefix, pag);
 
1669
        sprintf(fname, "%sp%ld", prefix, (long int) pag);
1661
1670
    }
1662
1671
    ktc_set_tkt_string(fname);
1663
1672
 
1665
1674
        numenv++;
1666
1675
    newenv = (char **)malloc((numenv + 2) * sizeof(char *));
1667
1676
 
1668
 
    for (senv = environ, denv = newenv; *senv; *senv++) {
 
1677
    for (senv = environ, denv = newenv; *senv; senv++) {
1669
1678
        if (strncmp(*senv, "KRBTKFILE=", 10) != 0)
1670
1679
            *denv++ = *senv;
1671
1680
    }
1676
1685
    *++denv = 0;
1677
1686
    environ = newenv;
1678
1687
    UNLOCK_GLOBAL_MUTEX;
 
1688
    return 0;
1679
1689
}
1680
1690
 
1681
1691
/*
1683
1693
 * find out what the local cell is.
1684
1694
 */
1685
1695
static void
1686
 
ktc_LocalCell()
 
1696
ktc_LocalCell(void)
1687
1697
{
1688
1698
    int code;
1689
1699
    struct afsconf_dir *conf;