~ubuntu-branches/debian/wheezy/netatalk/wheezy

« back to all changes in this revision

Viewing changes to test/afpd/afpfunc_helpers.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2011-06-05 21:04:21 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110605210421-19gag2srevj0ocxh
Tags: 2.2~beta4-1
* New upstream release.
  + Fixes "Internal Error" after ad_open on sparc.
    Closes: bug#606005. Thanks to Alfredo Sola.
* Adjust references to unofficial packages in README.Debian.
* Use dversionmangle (not uversionmangle) in watch file. Fix add
  leading dash (-) to upstream version in mangling.
* Update patches:
  + Drop patches 107 and 294 (Zeroconf support): Implemented
    (differently) upstream now.
  + Drop patches 109 and 112 (avoid broken XFS linkage) obsolete.
  + Drop patch 200 (hostname resolving): adopted upstream.
  + Refresh patch 205.
* Rewrite copyright file using draft 174 of DEP-5 format.
* Build-depend on and recommend unversioned (i.e. default) BerkeleyDB
  packages.
  Closes: bug#621413. Thanks to Ondřej Surý.
  Simplify suggestions on older versioned BerkeleyDB packages.
* Stop installing some documentation dropped upstream, and let CDBS
  automagically handle some of the remains.
* Update control file:
  + Bump policy compliance to standards-version 3.9.2.
  + Shorten Vcs-* URLs.
* Add patches 115 and (for automade file) 214 to avoid installing
  unneeded /default dir.
  Closes: bug#628119. Thanks to Russell Muetzelfeldt and Luk Claes.
* Don't ship .la files. Closes: bug#621849. Thanks to Andreas Metzler
  and Luk Claes.
* Stop renaming afile and achfile, dropped upstream.
* Explicitly enable DDP (AppleTalk), now disabled by default.
* Enable Zeroconf, should be stable now.
* Simplify package relations:
  + Drop (build-)dependency fallback unneeded even for oldstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  $Id: afpfunc_helpers.c,v 1.1.2.1 2010-02-01 10:56:08 franklahm Exp $
 
3
  Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU General Public License as published by
 
7
  the Free Software Foundation; either version 2 of the License, or
 
8
  (at your option) any later version.
 
9
 
 
10
  This program is distributed in the hope that it will be useful,
 
11
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
  GNU General Public License for more details.
 
14
*/
 
15
 
 
16
#ifdef HAVE_CONFIG_H
 
17
#include "config.h"
 
18
#endif /* HAVE_CONFIG_H */
 
19
 
 
20
#include <string.h>
 
21
#include <stdio.h>
 
22
#include <stdlib.h>
 
23
#include <errno.h>
 
24
 
 
25
#include <atalk/util.h>
 
26
#include <atalk/cnid.h>
 
27
#include <atalk/logger.h>
 
28
#include <atalk/volume.h>
 
29
#include <atalk/directory.h>
 
30
#include <atalk/queue.h>
 
31
#include <atalk/bstrlib.h>
 
32
 
 
33
#include "file.h"
 
34
#include "filedir.h"
 
35
#include "directory.h"
 
36
#include "dircache.h"
 
37
#include "hash.h"
 
38
#include "globals.h"
 
39
#include "afp_config.h"
 
40
#include "volume.h"
 
41
 
 
42
#include "test.h"
 
43
#include "subtests.h"
 
44
 
 
45
 
 
46
#define rbufsize 128000
 
47
static char rbuf[rbufsize];
 
48
static size_t rbuflen;
 
49
 
 
50
#define ADD(a, b, c) (a) += (c); \
 
51
                         (b) += (c)
 
52
 
 
53
#define PUSHBUF(p, val, size, len) \
 
54
    memcpy((p), (val), (size));    \
 
55
    (p) += (size);                 \
 
56
    (len) += (size)
 
57
 
 
58
#define PUSHVAL(p, type, val, len)         \
 
59
    { \
 
60
        type type = val;                          \
 
61
        memcpy(p, &type, sizeof(type));           \
 
62
        (p) += sizeof(type);                      \
 
63
        (len) += sizeof(type);                    \
 
64
    }
 
65
 
 
66
static int push_path(char **bufp, const char *name)
 
67
{
 
68
    int len = 0;
 
69
    int slen = strlen(name);
 
70
    char *p = *bufp;
 
71
 
 
72
    PUSHVAL(p, uint8_t, 3, len); /* path type */
 
73
    PUSHVAL(p, uint32_t, kTextEncodingUTF8, len); /* text encoding hint */
 
74
    PUSHVAL(p, uint16_t, htons(slen), len);
 
75
    if (slen) {
 
76
        for (int i = 0; i < slen; i++) {
 
77
            if (name[i] == '/')
 
78
                p[i] = 0;
 
79
            else
 
80
                p[i] = name[i];
 
81
        }
 
82
        len += slen;
 
83
    }
 
84
 
 
85
    *bufp += len;
 
86
    return len;
 
87
}
 
88
 
 
89
/***********************************************************************************
 
90
 * Interface
 
91
 ***********************************************************************************/
 
92
 
 
93
char **cnamewrap(const char *name)
 
94
{
 
95
    static char buf[256];
 
96
    static char *p = buf;
 
97
    int len = 0;
 
98
 
 
99
    PUSHVAL(p, uint8_t, 3, len); /* path type */
 
100
    PUSHVAL(p, uint32_t, kTextEncodingUTF8, len); /* text encoding hint */
 
101
    PUSHVAL(p, uint16_t, ntohs(strlen(name)), len);
 
102
    strcpy(p, name);
 
103
 
 
104
    p = buf;
 
105
    return &p;
 
106
}
 
107
 
 
108
int getfiledirparms(AFPObj *obj, uint16_t vid, cnid_t did, const char *name)
 
109
{
 
110
    const int bufsize = 256;
 
111
    char buf[bufsize];
 
112
    char *p = buf;
 
113
    int len = 0;
 
114
 
 
115
    ADD(p, len , 2);
 
116
 
 
117
    PUSHVAL(p, uint16_t, vid, len);
 
118
    PUSHVAL(p, cnid_t, did, len);
 
119
    PUSHVAL(p, uint16_t, htons(FILPBIT_FNUM | FILPBIT_PDINFO), len);
 
120
    PUSHVAL(p, uint16_t, htons(DIRPBIT_DID | DIRPBIT_PDINFO), len);
 
121
 
 
122
    len += push_path(&p, name);
 
123
 
 
124
    return afp_getfildirparams(obj, buf, len, rbuf, &rbuflen);
 
125
}
 
126
 
 
127
int createdir(AFPObj *obj, uint16_t vid, cnid_t did, const char *name)
 
128
{
 
129
    const int bufsize = 256;
 
130
    char buf[bufsize];
 
131
    char *p = buf;
 
132
    int len = 0;
 
133
 
 
134
    ADD(p, len , 2);
 
135
 
 
136
    PUSHVAL(p, uint16_t, vid, len);
 
137
    PUSHVAL(p, cnid_t, did, len);
 
138
    len += push_path(&p, name);
 
139
 
 
140
    return afp_createdir(obj, buf, len, rbuf, &rbuflen);
 
141
}
 
142
 
 
143
int createfile(AFPObj *obj, uint16_t vid, cnid_t did, const char *name)
 
144
{
 
145
    const int bufsize = 256;
 
146
    char buf[bufsize];
 
147
    char *p = buf;
 
148
    int len = 0;
 
149
 
 
150
    PUSHVAL(p, uint16_t, htons(128), len); /* hard create */
 
151
    PUSHVAL(p, uint16_t, vid, len);
 
152
    PUSHVAL(p, cnid_t, did, len);
 
153
    len += push_path(&p, name);
 
154
 
 
155
    return afp_createfile(obj, buf, len, rbuf, &rbuflen);
 
156
}
 
157
 
 
158
int delete(AFPObj *obj, uint16_t vid, cnid_t did, const char *name)
 
159
{
 
160
    const int bufsize = 256;
 
161
    char buf[bufsize];
 
162
    char *p = buf;
 
163
    int len = 0;
 
164
 
 
165
    PUSHVAL(p, uint16_t, htons(128), len); /* hard create */
 
166
    PUSHVAL(p, uint16_t, vid, len);
 
167
    PUSHVAL(p, cnid_t, did, len);
 
168
    len += push_path(&p, name);
 
169
 
 
170
    return afp_delete(obj, buf, len, rbuf, &rbuflen);
 
171
}
 
172
 
 
173
int enumerate(AFPObj *obj, uint16_t vid, cnid_t did)
 
174
{
 
175
    const int bufsize = 256;
 
176
    char buf[bufsize];
 
177
    char *p = buf;
 
178
    int len = 0;
 
179
 
 
180
    ADD(p, len , 2);
 
181
 
 
182
    PUSHVAL(p, uint16_t, vid, len);
 
183
    PUSHVAL(p, cnid_t, did, len);
 
184
    PUSHVAL(p, uint16_t, htons(FILPBIT_PDID | FILPBIT_FNUM | FILPBIT_PDINFO), len);
 
185
    PUSHVAL(p, uint16_t, htons(DIRPBIT_PDID | DIRPBIT_DID | DIRPBIT_PDINFO), len);
 
186
    PUSHVAL(p, uint16_t, htons(20), len);       /* reqcount */
 
187
    PUSHVAL(p, uint32_t, htonl(1), len);        /* startindex */
 
188
    PUSHVAL(p, uint32_t, htonl(rbufsize), len); /* max replysize */
 
189
 
 
190
    len += push_path(&p, "");
 
191
 
 
192
    return afp_enumerate_ext2(obj, buf, len, rbuf, &rbuflen);
 
193
}
 
194
 
 
195
uint16_t openvol(AFPObj *obj, const char *name)
 
196
{
 
197
    int ret;
 
198
    uint16_t bitmap;
 
199
    uint16_t vid;
 
200
    const int bufsize = 32;
 
201
    char buf[bufsize];
 
202
    char *p = buf;
 
203
    char len = strlen(name);
 
204
 
 
205
    memset(p, 0, bufsize);
 
206
    p += 2;
 
207
 
 
208
    /* bitmap */
 
209
    bitmap = htons(1<<VOLPBIT_VID);
 
210
    memcpy(p, &bitmap, 2);
 
211
    p += 2;
 
212
 
 
213
    /* name */
 
214
    *p = len;
 
215
    p++;
 
216
    memcpy(p, name, len);
 
217
    p += len;
 
218
 
 
219
    len += 2 + 2 + 1; /* (command+pad) + bitmap + len */
 
220
    if (len & 1)
 
221
        len++;
 
222
 
 
223
    rbuflen = 0;
 
224
    if ((ret = afp_openvol(obj, buf, len, rbuf, &rbuflen)) != AFP_OK)
 
225
        return 0;
 
226
 
 
227
    p = rbuf;
 
228
    memcpy(&bitmap, p, 2);
 
229
    p += 2;
 
230
    bitmap = ntohs(bitmap);
 
231
    if ( ! (bitmap & 1<<VOLPBIT_VID))
 
232
        return 0;
 
233
 
 
234
    memcpy(&vid, p, 2);
 
235
    return vid;
 
236
}
 
237