~ubuntu-branches/ubuntu/breezy/openafs/breezy

« back to all changes in this revision

Viewing changes to src/tests/stagehdr.c

  • Committer: Bazaar Package Importer
  • Author(s): Russ Allbery
  • Date: 2005-08-26 01:30:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050826013021-f0cwayjrju8bbfxu
Tags: 1.4rc1-1
* New upstream version.
* Install pam_afs.krb.so on hppa.  I believe the new PAM module build
  process fixes the issue that was being worked around before.
* Improve the documentation and scripts for setting up new servers or a
  new cell.  afs-rootvol can now be run from a client configured to use
  dynroot.  afs-newcell generates the server CellServDB directly to work
  around oddities with bos addhost.  There are many other, more minor
  improvements as well.  Thanks to Faheem Mitha and Sergio Gelato for
  analysis and patches.  (Closes: #322638)
* Update the configuration transcript to reflect the current packages,
  messages, and instructions.  Thanks, Faheem Mitha.
* Fill in the server CellServDB with information about the local cell,
  if available in the client CellServDB, rather than always initializing
  it to contain just the name of the cell.
* Detect AFS caches on non-ext2/ext3 file systems and abort AFS client
  initialization.  (Closes: #249315)
* Provide a way of setting sysname in afs.conf.  (Closes: #324694)
* Don't create the unused /etc/openafs/AFSLog file.  (Closes: #120097)
* Redo how library object files are found for the PAM module build to
  avoid assuming C locale character set behavior.  (Closes: #323582)
* Remove the openafs-client warning against dynroot for the first system
  in a cell now that afs-rootvol can cope.  Provide some basic
  documentation of the CellAlias syntax in that message until we have a
  real man page.
* Suggest openafs-doc.
* Update standards version to 3.6.2 for the kernel module packages (no
  changes required).
* Translation updates.
  - Czech, thanks Martin Sin.
  - Vietnamese, thanks Clytie Siddall.
  - French, thanks Christian Perrier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include "xf_errs.h"
39
39
#include "stagehdr.h"
40
40
 
41
 
static afs_uint32 hdr_checksum(char *buf, int size)
 
41
static afs_uint32
 
42
hdr_checksum(char *buf, int size)
42
43
{
43
 
  afs_uint32 sum = 0, n = size / sizeof(afs_uint32), *words = (afs_uint32 *)buf;
 
44
    afs_uint32 sum = 0, n = size / sizeof(afs_uint32), *words =
 
45
        (afs_uint32 *) buf;
44
46
 
45
 
  while (--n)
46
 
    sum += ntohl(*words++);
47
 
  return sum;
 
47
    while (--n)
 
48
        sum += ntohl(*words++);
 
49
    return sum;
48
50
}
49
51
 
50
52
 
56
58
 * Iff there is no header, returns DSERR_MAGIC and leaves us
57
59
 * positioned where we started.
58
60
 */
59
 
afs_uint32 ParseStageHdr(XFILE *X, unsigned char *tag, backup_system_header *hdr)
 
61
afs_uint32
 
62
ParseStageHdr(XFILE * X, unsigned char *tag, backup_system_header * hdr)
60
63
{
61
 
  char buf[STAGE_HDRLEN];
62
 
  struct stage_header *bckhdr = (struct stage_header *)buf;
63
 
  u_int64 where;
64
 
  afs_uint32 r;
65
 
 
66
 
  if (r = xftell(X, &where)) return r;
67
 
  if (hdr) memset(hdr, 0, sizeof(*hdr));
68
 
  if (tag) {
69
 
    if (*tag != STAGE_VERSMIN) return DSERR_MAGIC;
70
 
    buf[0] = *tag;
71
 
    r = xfread(X, buf + 1, STAGE_HDRLEN - 1);
72
 
  } else {
73
 
    r = xfread(X, buf, STAGE_HDRLEN);
74
 
  }
75
 
 
76
 
  if (r == ERROR_XFILE_EOF) {
77
 
    r = xfseek(X, &where);
78
 
    return r ? r : DSERR_MAGIC;
79
 
  } else if (r) return r;
80
 
 
81
 
  if (bckhdr->c_vers < STAGE_VERSMIN
82
 
  ||  ntohl(bckhdr->c_magic) != STAGE_MAGIC
83
 
  ||  hdr_checksum(buf, STAGE_HDRLEN) != STAGE_CHECKSUM) {
84
 
    r = xfseek(X, &where);
85
 
    return r ? r : DSERR_MAGIC;
86
 
  }
87
 
 
88
 
  if (hdr) {
89
 
    hdr->version   = bckhdr->c_vers;
90
 
    hdr->from_date = ntohl(bckhdr->c_fdate);
91
 
    hdr->to_date   = ntohl(bckhdr->c_tdate);
92
 
    hdr->dump_date = ntohl(bckhdr->c_time);
93
 
    hdr->filenum   = ntohl(bckhdr->c_filenum);
94
 
    hdr->volid     = ntohl(bckhdr->c_id);
95
 
    hdr->dumplen   = ntohl(bckhdr->c_length);
96
 
    hdr->level     = ntohl(bckhdr->c_level);
97
 
    hdr->magic     = ntohl(bckhdr->c_magic);
98
 
    hdr->cksum     = ntohl(bckhdr->c_checksum);
99
 
    hdr->flags     = ntohl(bckhdr->c_flags);
100
 
    hdr->server    = malloc(strlen(bckhdr->c_host) + 1);
101
 
    hdr->part      = malloc(strlen(bckhdr->c_disk) + 1);
102
 
    hdr->volname   = malloc(strlen(bckhdr->c_name) + 1);
103
 
 
104
 
    if (!hdr->server || !hdr->part || !hdr->volname) {
105
 
      if (hdr->server)  free(hdr->server);
106
 
      if (hdr->part)    free(hdr->part);
107
 
      if (hdr->volname) free(hdr->volname);
108
 
      return ENOMEM;
109
 
    }
110
 
    strcpy(hdr->server,  bckhdr->c_host);
111
 
    strcpy(hdr->part,    bckhdr->c_disk);
112
 
    strcpy(hdr->volname, bckhdr->c_name);
113
 
  }
114
 
 
115
 
  if (tag) return ReadByte(X, tag);
116
 
  else return 0;
 
64
    char buf[STAGE_HDRLEN];
 
65
    struct stage_header *bckhdr = (struct stage_header *)buf;
 
66
    u_int64 where;
 
67
    afs_uint32 r;
 
68
 
 
69
    if (r = xftell(X, &where))
 
70
        return r;
 
71
    if (hdr)
 
72
        memset(hdr, 0, sizeof(*hdr));
 
73
    if (tag) {
 
74
        if (*tag != STAGE_VERSMIN)
 
75
            return DSERR_MAGIC;
 
76
        buf[0] = *tag;
 
77
        r = xfread(X, buf + 1, STAGE_HDRLEN - 1);
 
78
    } else {
 
79
        r = xfread(X, buf, STAGE_HDRLEN);
 
80
    }
 
81
 
 
82
    if (r == ERROR_XFILE_EOF) {
 
83
        r = xfseek(X, &where);
 
84
        return r ? r : DSERR_MAGIC;
 
85
    } else if (r)
 
86
        return r;
 
87
 
 
88
    if (bckhdr->c_vers < STAGE_VERSMIN
 
89
        || ntohl(bckhdr->c_magic) != STAGE_MAGIC
 
90
        || hdr_checksum(buf, STAGE_HDRLEN) != STAGE_CHECKSUM) {
 
91
        r = xfseek(X, &where);
 
92
        return r ? r : DSERR_MAGIC;
 
93
    }
 
94
 
 
95
    if (hdr) {
 
96
        hdr->version = bckhdr->c_vers;
 
97
        hdr->from_date = ntohl(bckhdr->c_fdate);
 
98
        hdr->to_date = ntohl(bckhdr->c_tdate);
 
99
        hdr->dump_date = ntohl(bckhdr->c_time);
 
100
        hdr->filenum = ntohl(bckhdr->c_filenum);
 
101
        hdr->volid = ntohl(bckhdr->c_id);
 
102
        hdr->dumplen = ntohl(bckhdr->c_length);
 
103
        hdr->level = ntohl(bckhdr->c_level);
 
104
        hdr->magic = ntohl(bckhdr->c_magic);
 
105
        hdr->cksum = ntohl(bckhdr->c_checksum);
 
106
        hdr->flags = ntohl(bckhdr->c_flags);
 
107
        hdr->server = malloc(strlen(bckhdr->c_host) + 1);
 
108
        hdr->part = malloc(strlen(bckhdr->c_disk) + 1);
 
109
        hdr->volname = malloc(strlen(bckhdr->c_name) + 1);
 
110
 
 
111
        if (!hdr->server || !hdr->part || !hdr->volname) {
 
112
            if (hdr->server)
 
113
                free(hdr->server);
 
114
            if (hdr->part)
 
115
                free(hdr->part);
 
116
            if (hdr->volname)
 
117
                free(hdr->volname);
 
118
            return ENOMEM;
 
119
        }
 
120
        strcpy(hdr->server, bckhdr->c_host);
 
121
        strcpy(hdr->part, bckhdr->c_disk);
 
122
        strcpy(hdr->volname, bckhdr->c_name);
 
123
    }
 
124
 
 
125
    if (tag)
 
126
        return ReadByte(X, tag);
 
127
    else
 
128
        return 0;
117
129
}
118
130
 
119
131
 
120
132
/* Dump a stage backup header */
121
 
afs_uint32 DumpStageHdr(XFILE *OX, backup_system_header *hdr)
 
133
afs_uint32
 
134
DumpStageHdr(XFILE * OX, backup_system_header * hdr)
122
135
{
123
 
  char buf[STAGE_HDRLEN];
124
 
  struct stage_header *bckhdr = (struct stage_header *)buf;
125
 
  afs_uint32 checksum;
126
 
  afs_uint32 r;
127
 
 
128
 
  memset(buf, 0, STAGE_HDRLEN);
129
 
  bckhdr->c_vers     = hdr->version;
130
 
  bckhdr->c_fdate    = htonl(hdr->from_date);
131
 
  bckhdr->c_tdate    = htonl(hdr->to_date);
132
 
  bckhdr->c_filenum  = htonl(hdr->filenum);
133
 
  bckhdr->c_time     = htonl(hdr->dump_date);
134
 
  bckhdr->c_id       = htonl(hdr->volid);
135
 
  bckhdr->c_length   = htonl(hdr->dumplen);
136
 
  bckhdr->c_level    = htonl(hdr->level);
137
 
  bckhdr->c_magic    = htonl(STAGE_MAGIC);
138
 
  bckhdr->c_flags    = htonl(hdr->flags);
139
 
 
140
 
  strcpy(bckhdr->c_host, hdr->server);
141
 
  strcpy(bckhdr->c_disk, hdr->part);
142
 
  strcpy(bckhdr->c_name, hdr->volname);
143
 
 
144
 
  /* Now, compute the checksum */
145
 
  checksum = hdr_checksum(buf, STAGE_HDRLEN);
146
 
  bckhdr->c_checksum = htonl(STAGE_CHECKSUM - checksum);
147
 
 
148
 
  if (r = xfwrite(OX, buf, STAGE_HDRLEN)) return r;
149
 
  return 0;
 
136
    char buf[STAGE_HDRLEN];
 
137
    struct stage_header *bckhdr = (struct stage_header *)buf;
 
138
    afs_uint32 checksum;
 
139
    afs_uint32 r;
 
140
 
 
141
    memset(buf, 0, STAGE_HDRLEN);
 
142
    bckhdr->c_vers = hdr->version;
 
143
    bckhdr->c_fdate = htonl(hdr->from_date);
 
144
    bckhdr->c_tdate = htonl(hdr->to_date);
 
145
    bckhdr->c_filenum = htonl(hdr->filenum);
 
146
    bckhdr->c_time = htonl(hdr->dump_date);
 
147
    bckhdr->c_id = htonl(hdr->volid);
 
148
    bckhdr->c_length = htonl(hdr->dumplen);
 
149
    bckhdr->c_level = htonl(hdr->level);
 
150
    bckhdr->c_magic = htonl(STAGE_MAGIC);
 
151
    bckhdr->c_flags = htonl(hdr->flags);
 
152
 
 
153
    strcpy(bckhdr->c_host, hdr->server);
 
154
    strcpy(bckhdr->c_disk, hdr->part);
 
155
    strcpy(bckhdr->c_name, hdr->volname);
 
156
 
 
157
    /* Now, compute the checksum */
 
158
    checksum = hdr_checksum(buf, STAGE_HDRLEN);
 
159
    bckhdr->c_checksum = htonl(STAGE_CHECKSUM - checksum);
 
160
 
 
161
    if (r = xfwrite(OX, buf, STAGE_HDRLEN))
 
162
        return r;
 
163
    return 0;
150
164
}