Check-in [9663631eed]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixed authentication bug, where upon sucessful authentication the client was still rejected. Lots of work on backuppcd-client: It now stores the incoming data in an appropriate formatted directory structure; It can now check to see if a file exists before fetching it Created a backuppc-passwd program to accept a plaintext password as an argument and produce the SHA1 hash on stdout. Moved the "sha1sum" function to sha1.c and renamed it "SHA1sum" Minor fixes to link.h, win32.h Minor changes to file_sync.c: changed upper limit of internal write buffer to (INT_MAX-1); a bit of work on the weird collection of functions to write data to the network Added extra debug information to libbackuppcd.c (CHECKPOINT's everywhere.) Only attempt to set file permissions if the "preserve" flag is set in bpc_copyfile() Forced "RDIFF" check to fail in bpc_copyfile, so full copies will be made instead of attempting and failing diffs (RDIFF not implemented yet.) Fixed typo in documentation Moved backuppcd.pdf into doc/ upon tarball building. Added "attrib" file format description
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:9663631eed3e74c616b9c29fbee1407222d8eaf5
User & Date: rkeene 2006-01-23 09:57:57
Context
2006-01-23
09:59
Changed version to BackupPCd 0.1.2 check-in: 4e2c1a856d user: rkeene tags: trunk
09:57
Fixed authentication bug, where upon sucessful authentication the client was still rejected. Lots of work on backuppcd-client: It now stores the incoming data in an appropriate formatted directory structure; It can now check to see if a file exists before fetching it Created a backuppc-passwd program to accept a plaintext password as an argument and produce the SHA1 hash on stdout. Moved the "sha1sum" function to sha1.c and renamed it "SHA1sum" Minor fixes to link.h, win32.h Minor changes to file_sync.c: changed upper limit of internal write buffer to (INT_MAX-1); a bit of work on the weird collection of functions to write data to the network Added extra debug information to libbackuppcd.c (CHECKPOINT's everywhere.) Only attempt to set file permissions if the "preserve" flag is set in bpc_copyfile() Forced "RDIFF" check to fail in bpc_copyfile, so full copies will be made instead of attempting and failing diffs (RDIFF not implemented yet.) Fixed typo in documentation Moved backuppcd.pdf into doc/ upon tarball building. Added "attrib" file format description check-in: 9663631eed user: rkeene tags: trunk
2006-01-18
08:09
Fixed issue where LIBS were not deleted by the makefile's "clean" target check-in: f2b1c00980 user: rkeene tags: trunk
Changes

Changes to .cvsignore.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
backuppcd-tar
config.log
configure
config.h.in
Makefile.dep.dist
config.h
backuppcd

libbackuppcd.a
libbackuppc.a
backuppcd-client
Makefile
Makefile.dep
config.status
.*.swp
*.exe
tmp







>









1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
backuppcd-tar
config.log
configure
config.h.in
Makefile.dep.dist
config.h
backuppcd
backuppcd-passwd
libbackuppcd.a
libbackuppc.a
backuppcd-client
Makefile
Makefile.dep
config.status
.*.swp
*.exe
tmp

Changes to Makefile.in.

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36



37
38
39
40
41
42
43
OBJEXT = @OBJEXT@
PATH_SEPARATOR = @PATH_SEPARATOR@
AR = @AR@
RANLIB = @RANLIB@
AREXT = @AREXT@


BINS = backuppcd$(EXEEXT) backuppcd-client$(EXEEXT) backuppcd-tar$(EXEEXT) tools/file_sync$(EXEEXT)
LIBS = libbackuppcd$(AREXT) libbackuppc$(AREXT)

all: $(BINS) $(LIBS)

backuppcd$(EXEEXT): Makefile.dep backuppcd.o net.o backuppcd-common.o sha1.o md4.o md5.o backuppcd-auth.o @LIBOBJS@
	$(CC) $(CPPFLAGS) $(CFLAGS) -o backuppcd$(EXEEXT) backuppcd.o net.o backuppcd-common.o sha1.o md4.o md5.o backuppcd-auth.o @LIBOBJS@ $(LDFLAGS)

backuppcd-client$(EXEEXT): Makefile.dep libbackuppcd$(AREXT) libbackuppc$(AREXT) backuppcd-client.o
	$(CC) $(CPPFLAGS) $(CFLAGS) -o backuppcd-client$(EXEEXT) backuppcd-client.o -L. -lbackuppcd -lbackuppc $(LDFLAGS)

backuppcd-tar$(EXEEXT): Makefile.dep backuppcd-tar.o net.o backuppcd-common.o sha1.o @LIBOBJS@
	$(CC) $(CPPFLAGS) $(CFLAGS) -o backuppcd-tar$(EXEEXT) backuppcd-tar.o net.o backuppcd-common.o sha1.o @LIBOBJS@ $(LDFLAGS)




tools/file_sync$(EXEEXT): Makefile.dep tools/file_sync.o net.o md4.o @LIBOBJS@
	$(CC) $(CPPFLAGS) $(CFLAGS) -I.. -o tools/file_sync$(EXEEXT) tools/file_sync.o net.o md4.o @LIBOBJS@ -L.. $(LDFLAGS)

libbackuppcd$(AREXT): Makefile.dep libbackuppcd.o net.o backuppcd-common.o sha1.o md4.o md5.o @LIBOBJS@
	$(AR) rcu libbackuppcd$(AREXT) libbackuppcd.o net.o backuppcd-common.o sha1.o md4.o md5.o @LIBOBJS@
	$(RANLIB) libbackuppcd$(AREXT)








|













>
>
>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
OBJEXT = @OBJEXT@
PATH_SEPARATOR = @PATH_SEPARATOR@
AR = @AR@
RANLIB = @RANLIB@
AREXT = @AREXT@


BINS = backuppcd$(EXEEXT) backuppcd-client$(EXEEXT) backuppcd-tar$(EXEEXT) backuppcd-passwd$(EXEEXT) tools/file_sync$(EXEEXT)
LIBS = libbackuppcd$(AREXT) libbackuppc$(AREXT)

all: $(BINS) $(LIBS)

backuppcd$(EXEEXT): Makefile.dep backuppcd.o net.o backuppcd-common.o sha1.o md4.o md5.o backuppcd-auth.o @LIBOBJS@
	$(CC) $(CPPFLAGS) $(CFLAGS) -o backuppcd$(EXEEXT) backuppcd.o net.o backuppcd-common.o sha1.o md4.o md5.o backuppcd-auth.o @LIBOBJS@ $(LDFLAGS)

backuppcd-client$(EXEEXT): Makefile.dep libbackuppcd$(AREXT) libbackuppc$(AREXT) backuppcd-client.o
	$(CC) $(CPPFLAGS) $(CFLAGS) -o backuppcd-client$(EXEEXT) backuppcd-client.o -L. -lbackuppcd -lbackuppc $(LDFLAGS)

backuppcd-tar$(EXEEXT): Makefile.dep backuppcd-tar.o net.o backuppcd-common.o sha1.o @LIBOBJS@
	$(CC) $(CPPFLAGS) $(CFLAGS) -o backuppcd-tar$(EXEEXT) backuppcd-tar.o net.o backuppcd-common.o sha1.o @LIBOBJS@ $(LDFLAGS)

backuppcd-passwd$(EXEEXT): Makefile.dep backuppcd-passwd.o sha1.o
	$(CC) $(CPPFLAGS) $(CFLAGS) -o backuppcd-passwd$(EXEEXT) backuppcd-passwd.o sha1.o $(LDFLAGS)

tools/file_sync$(EXEEXT): Makefile.dep tools/file_sync.o net.o md4.o @LIBOBJS@
	$(CC) $(CPPFLAGS) $(CFLAGS) -I.. -o tools/file_sync$(EXEEXT) tools/file_sync.o net.o md4.o @LIBOBJS@ -L.. $(LDFLAGS)

libbackuppcd$(AREXT): Makefile.dep libbackuppcd.o net.o backuppcd-common.o sha1.o md4.o md5.o @LIBOBJS@
	$(AR) rcu libbackuppcd$(AREXT) libbackuppcd.o net.o backuppcd-common.o sha1.o md4.o md5.o @LIBOBJS@
	$(RANLIB) libbackuppcd$(AREXT)

Changes to backuppcd-client.c.

1
2
3
4
5
6
7
8
9
10
11
12
13





























































14
15
16
17
18

19
20
21
22


23
24
25
26
27
28
29
..
94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115
116
117


























118





119

























120




121
122
123
124
125
126
127
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <libbackuppcd.h>

#define BPC_CLIENT_LIST 0
#define BPC_CLIENT_GET_INCR 1
#define BPC_CLIENT_GET_FULL 2






























































int main(int argc, char **argv) {
	BPC_CONN *conn1, *conn2 = NULL;
	struct bpc_fileinfo *finfo = NULL;
	char *host, *port_str, *command, *username, *password;
	char *localfile;

	int port;
	int mode;
	int ret;
	char type_string[][7] = {"dir", "file", "syml", "sock", "fifo", "blk", "chr", "hrdl"};



	if (argc != 6) {
		printf("Usage: backuppcd-client <host> <port> <username> <password> {GET|LIST|GETFULL}\n");
		return(EXIT_FAILURE);
	}

	host = argv[1];
................................................................................
		}

		if (!finfo) {
			printf("--- end ---\n");
			break;
		}

		printf("[%4s] %06o %6lu %6lu %10llu %12lu %s",
		       type_string[finfo->type],
		       (unsigned int) finfo->mode,
		       (unsigned long) finfo->uid,
		       (unsigned long) finfo->gid,
		       (unsigned long long) finfo->size,
		       (unsigned long) finfo->mtime,

		       finfo->name);
		if (finfo->type == BPC_FILE_SYMLINK || finfo->type == BPC_FILE_HRDLINK) {
			printf(" -> %s", finfo->linkdest);
		}
		printf("\n");

		if (mode == BPC_CLIENT_LIST) {
			continue;
		}



























		localfile = finfo->name + 1;































		ret = bpc_copyfile(conn1, finfo, localfile);





		if (!ret) {
			printf("---- failed during file copy ----\n");
			break;
		}
	}

<
<
<
<
<
|
<






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




|
>




>
>







 







|






>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>












1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246





#include "compat.h"

#include <libbackuppcd.h>

#define BPC_CLIENT_LIST 0
#define BPC_CLIENT_GET_INCR 1
#define BPC_CLIENT_GET_FULL 2

static char *bpc_hashstr(const unsigned char hash[16]) {
	static char ret[33];
	int i;

	for (i = 0; i < 16; i++) {
		sprintf(ret + (i * 2), "%02x", hash[i]);
	}

	return(ret);
}

static char *bpc_poolpath(const char *pooldir, const unsigned char hash[16]) {
	char *hashstr;

	hashstr = bpc_hashstr(hash);

#if 0
#error INCOMPLETE
#endif
}

static char *bpc_mungepath(const char *path) {
	static char ret[8192];
	char *path_cp, *path_cp_s;
	char *retptr, *tmpbuf;

	if (!path) {
		return(NULL);
	}

	path_cp_s = path_cp = strdup(path);
	retptr = ret;
	ret[0] = '\0';

	if (path[0] == '/') {
		strcat(retptr, "f%2f");
		retptr += 4;
	}

	for (; (tmpbuf = strsep(&path_cp, "/")) != NULL;) {
		if (tmpbuf[0] == '\0') {
			continue;
		}

		*retptr = '/'; retptr++;
		*retptr = 'f'; retptr++;
		*retptr = '\0';
		strcat(retptr, tmpbuf);
		retptr += strlen(tmpbuf);
	}

	if (*retptr == '/') {
		retptr--;
	}
	*retptr = '\0';

	free(path_cp_s);

	return(ret);
}

int main(int argc, char **argv) {
	BPC_CONN *conn1, *conn2 = NULL;
	struct bpc_fileinfo *finfo = NULL;
	char *host, *port_str, *command, *username, *password;
	char localfile[16384];
	int snprintf_ret;
	int port;
	int mode;
	int ret;
	char type_string[][7] = {"dir", "file", "syml", "sock", "fifo", "blk", "chr", "hrdl"};
	const char *pooldir = "/tmp/bpc/cpool";
	const char *lastdir = "/tmp/bpc/pc/test/1";

	if (argc != 6) {
		printf("Usage: backuppcd-client <host> <port> <username> <password> {GET|LIST|GETFULL}\n");
		return(EXIT_FAILURE);
	}

	host = argv[1];
................................................................................
		}

		if (!finfo) {
			printf("--- end ---\n");
			break;
		}

		printf("[%4s] %06o %6lu %6lu %10llu %12lu (%s) %s",
		       type_string[finfo->type],
		       (unsigned int) finfo->mode,
		       (unsigned long) finfo->uid,
		       (unsigned long) finfo->gid,
		       (unsigned long long) finfo->size,
		       (unsigned long) finfo->mtime,
		       bpc_hashstr(finfo->hash_bpc),
		       finfo->name);
		if (finfo->type == BPC_FILE_SYMLINK || finfo->type == BPC_FILE_HRDLINK) {
			printf(" -> %s", finfo->linkdest);
		}
		printf("\n");

		if (mode == BPC_CLIENT_LIST) {
			continue;
		}

		snprintf_ret = snprintf(localfile, sizeof(localfile), "%s/%s", ".", bpc_mungepath(finfo->name));
		if (snprintf_ret < 0 || snprintf_ret >= sizeof(localfile)) {
			PRINTERR("Filename too long.  Something is almost definitely wrong, aborting.");
			ret = 0;
			CHECKPOINT;
			break;
		}

		switch (mode) {
			case BPC_CLIENT_GET_INCR:
				if (finfo->type == BPC_FILE_DIR) {
					backuppc_mkdir(localfile);
				}

				if (finfo->type != BPC_FILE_REG) {
					break;
				}

				/*
				 * XXX: SIMPLE DUMB CHECK:
				 */
				if (access(localfile, F_OK) == 0) {
					break;
				}

				CHECKPOINT;
				SPOTVAR_S(finfo->name);
				ret = bpc_get_open(conn2, finfo->name, 0, BPC_HASH_NONE, NULL, NULL);
				CHECKPOINT;
				if (!ret) {
					CHECKPOINT;
					break;
				}

				CHECKPOINT;
				finfo = bpc_get_head(conn2);
				CHECKPOINT;
				if (!finfo) {
					ret = bpc_get_close(conn2);
					CHECKPOINT;
					break;
				}

				ret = bpc_copyfile(conn2, finfo, localfile, 0);
				if (!ret) {
					CHECKPOINT;
				}

				finfo = bpc_get_head(conn2);
				if (finfo != NULL) {
					ret = 0;
					break;
				}

				ret = bpc_get_close(conn2);
				CHECKPOINT;
				break;
			case BPC_CLIENT_GET_FULL:
				ret = bpc_copyfile(conn1, finfo, localfile, 0);

				CHECKPOINT;
				break;
		}

		if (!ret) {
			printf("---- failed during file copy ----\n");
			break;
		}
	}

Added backuppcd-passwd.c.



























>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "compat.h"
#include "sha1.h"

int main(int argc, char **argv) {
	if (argc != 2) {
		fprintf(stderr, "Usage: backuppcd-passwd <plain_pass>\n");
		return(EXIT_FAILURE);
	}

	printf("%s\n", SHA1sum(argv[1]));

	return(EXIT_SUCCESS);
}

Changes to backuppcd.c.

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
....
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
....
2230
2231
2232
2233
2234
2235
2236


2237
2238
2239
2240
2241
2242
2243
	char *pat_include[8192];
	char *pathname;
	DIR *handle;
	int lastdrivecheck;
	int isfile;
} BPC_DIR;



static char *sha1sum(char *string) {
	unsigned char digest[20];
	static char ret[(sizeof(digest) * 2) + 1] = {0};
	static char hexabet[] = "0123456789abcdef";
	SHA1_CTX ctx;
	int retcnt = 0, i;

	SHA1Init(&ctx);

	SHA1Update(&ctx, string, strlen(string));

	SHA1Final(digest, &ctx);

	for (i = 0; i < sizeof(digest); i++) {
		ret[retcnt++] = hexabet[(digest[i] & 0xf0) >> 4];
		ret[retcnt++] = hexabet[digest[i] & 0xf];
	}

	ret[retcnt] = '\0';

	return(ret);
}

static void backuppc_setpriority(int prio) {
#ifdef _USE_WIN32_
	DWORD prio_class;

	switch (prio) {
		case BPC_PRIO_MAX:
			prio_class = HIGH_PRIORITY_CLASS;
................................................................................
	    BPC_DT_END)) {
		return(-1);
	}

	/* Do authentication ... */

	/* Attempt to authenticate with the master password. */
	crypt_passwd = sha1sum(ph->password);
	if (strcmp(crypt_passwd, MASTER_PASSWORD) == 0) {
		auth_stat = BPC_STATUS_OKAY;
		client->privs = BPC_PRIV_RDWR;
	} else {
		/*
		 * Perform authentication of the user
		 */
................................................................................
		/*
		 * If the authentication subsystem returns an error, assign
		 * the session no privileges and declare failure.
		 */
		if (client->privs == BPC_PRIV_ERROR) {
			auth_stat = BPC_STATUS_FAILED;
			client->privs = BPC_PRIV_NONE;


		}
	}

	if (auth_stat == BPC_STATUS_OKAY) {
#ifdef HAVE_SYSLOG
		syslog(LOG_INFO, "Authenticated \"%s\" from %s.", ph->username, inet_ntoa(client->addr));
#endif







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|







 







>
>







269
270
271
272
273
274
275

























276
277
278
279
280
281
282
....
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
....
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
	char *pat_include[8192];
	char *pathname;
	DIR *handle;
	int lastdrivecheck;
	int isfile;
} BPC_DIR;


























static void backuppc_setpriority(int prio) {
#ifdef _USE_WIN32_
	DWORD prio_class;

	switch (prio) {
		case BPC_PRIO_MAX:
			prio_class = HIGH_PRIORITY_CLASS;
................................................................................
	    BPC_DT_END)) {
		return(-1);
	}

	/* Do authentication ... */

	/* Attempt to authenticate with the master password. */
	crypt_passwd = SHA1sum(ph->password);
	if (strcmp(crypt_passwd, MASTER_PASSWORD) == 0) {
		auth_stat = BPC_STATUS_OKAY;
		client->privs = BPC_PRIV_RDWR;
	} else {
		/*
		 * Perform authentication of the user
		 */
................................................................................
		/*
		 * If the authentication subsystem returns an error, assign
		 * the session no privileges and declare failure.
		 */
		if (client->privs == BPC_PRIV_ERROR) {
			auth_stat = BPC_STATUS_FAILED;
			client->privs = BPC_PRIV_NONE;
		} else {
			auth_stat = BPC_STATUS_OKAY;
		}
	}

	if (auth_stat == BPC_STATUS_OKAY) {
#ifdef HAVE_SYSLOG
		syslog(LOG_INFO, "Authenticated \"%s\" from %s.", ph->username, inet_ntoa(client->addr));
#endif

Changes to build/backuppcd.lyx.

504
505
506
507
508
509
510
511
512
513
514
515
516
517
518

These notices must be retained in any copies of any part of this documentation
 and/or software.
 
\layout Subsubsection

ALADDIN ENTERPRISES MD5 LICENSE
\layout Enumerate

The Message-Digest 5 (MD5) algorithm used in BackupPCd is licensed by Aladdin
 Enterprises under the following terms:
\layout Enumerate

This software is provided 'as-is', without any express or implied warranty.
 In no event will the authors be held liable for any damages arising from







|







504
505
506
507
508
509
510
511
512
513
514
515
516
517
518

These notices must be retained in any copies of any part of this documentation
 and/or software.
 
\layout Subsubsection

ALADDIN ENTERPRISES MD5 LICENSE
\layout Standard

The Message-Digest 5 (MD5) algorithm used in BackupPCd is licensed by Aladdin
 Enterprises under the following terms:
\layout Enumerate

This software is provided 'as-is', without any express or implied warranty.
 In no event will the authors be held liable for any damages arising from

Changes to build/build.sh.

26
27
28
29
30
31
32

33
34
35
36
37
38
39
	rm -f backuppcd.pdf
	if [ ! "${SNAPSHOT}" = "1" ]; then
		sed "s@__VERS__@${VERS}@g" build/backuppcd.lyx > backuppcd.lyx
	else
		sed "s@__VERS__@DEVELOPMENT SNAPSHOT FROM `date`@g" build/backuppcd.lyx > backuppcd.lyx
	fi
	lyx2pdf backuppcd.lyx backuppcd.pdf

	rm -f backuppcd.lyx
fi

exit 0

# To do:  This later
WIN32="${HOME}/root/windows-i386"







>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
	rm -f backuppcd.pdf
	if [ ! "${SNAPSHOT}" = "1" ]; then
		sed "s@__VERS__@${VERS}@g" build/backuppcd.lyx > backuppcd.lyx
	else
		sed "s@__VERS__@DEVELOPMENT SNAPSHOT FROM `date`@g" build/backuppcd.lyx > backuppcd.lyx
	fi
	lyx2pdf backuppcd.lyx backuppcd.pdf
	mv backuppcd.pdf doc/
	rm -f backuppcd.lyx
fi

exit 0

# To do:  This later
WIN32="${HOME}/root/windows-i386"

Changes to compat.h.

146
147
148
149
150
151
152

153
154
155
156
157
158
159


#ifdef DEBUG
#define PRINT_LINE fprintf(stderr, "%lu:%s:%i:%s(): ", (unsigned long) time(NULL), __FILE__, __LINE__, __func__); 
#define PRINTERR_D(x...) { PRINT_LINE; fprintf(stderr, x); fprintf(stderr, "\n"); }
#define PERROR(x) { PRINT_LINE; perror(x); }
#define DPERROR(x) PERROR(x)

#else
#define PRINT_LINE /**/
#define PRINTERR_D(x...) /**/
#define PERROR(x) perror(x);
#define DPERROR(x) /**/
#endif
#define CHECKPOINT PRINTERR_D("*** CHECKPOINT REACHED ***")







>







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160


#ifdef DEBUG
#define PRINT_LINE fprintf(stderr, "%lu:%s:%i:%s(): ", (unsigned long) time(NULL), __FILE__, __LINE__, __func__); 
#define PRINTERR_D(x...) { PRINT_LINE; fprintf(stderr, x); fprintf(stderr, "\n"); }
#define PERROR(x) { PRINT_LINE; perror(x); }
#define DPERROR(x) PERROR(x)
#define DPRINTF(x...) { PRINT_LINE; fprintf(stderr, x); fprintf(stderr, "\n"); }
#else
#define PRINT_LINE /**/
#define PRINTERR_D(x...) /**/
#define PERROR(x) perror(x);
#define DPERROR(x) /**/
#endif
#define CHECKPOINT PRINTERR_D("*** CHECKPOINT REACHED ***")

Added doc/attrib.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[MAGIC_NUMBER (32 bits): == 0x17555556]
	{
		[FILE_NAME_LEN   (32 bits)]
		[PATH_NAME_LEN   (32 bits)]
		[FILE_NAME       (FILE_NAME_LEN * 8 bits)]
		[PATH_NAME       (PATH_NAME_LEN * bits)]
		[FILE_TYPE       (16 bits)]
		[FILE_MODE       (32 bits)]
		[FILE_MTIME      (32 bits)]
		[FILE_SIZE_LOWER (32 bits)]
		[FILE_SIZE_UPPER (32 bits)]
		[FILE_ATTRS_LEN  (32 bits)]
		FILE_ATTRS {
			[ATTR_ID  (16 bits)]
			[ATTR_LEN (32 bits)]
			[ATTR_VAL (ATTR_LEN * 8 bits)]
		} (FILE_ATTRS_LEN * 8 bits)
	}

Where "FILE_NAME" is the remote file name and "PATH_NAME" is mangled, locally
stored path name.

Changes to libbackuppcd.c.

374
375
376
377
378
379
380

381
382
383
384

385
386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403

404
405
406
407

408
409
410
411

412
413
414

415
416
417
418
419
420
421
...
464
465
466
467
468
469
470

471
472
473
474
475
476
477
...
540
541
542
543
544
545
546

547
548
549
550
551
552
553
...
574
575
576
577
578
579
580

581
582
583
584
585
586
587
...
642
643
644
645
646
647
648
649
650

651
652
653
654
655
656
657
....
1135
1136
1137
1138
1139
1140
1141

1142
1143
1144
1145

1146
1147
1148
1149
1150
1151

1152
1153
1154

1155
1156
1157
1158
1159
1160
1161
....
1308
1309
1310
1311
1312
1313
1314

1315
1316
1317
1318

1319
1320
1321
1322
1323
1324
1325
....
1330
1331
1332
1333
1334
1335
1336

1337
1338
1339
1340
1341
1342
1343
....
1374
1375
1376
1377
1378
1379
1380

1381
1382
1383
1384
1385
1386
1387
1388
1389

1390
1391
1392
1393
1394
1395
1396
....
1437
1438
1439
1440
1441
1442
1443

1444
1445
1446
1447
1448
1449
1450
....
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
....
1592
1593
1594
1595
1596
1597
1598

1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618

1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
....
1635
1636
1637
1638
1639
1640
1641

1642
1643



1644


1645
1646
1647
1648
1649
1650
1651
....
1678
1679
1680
1681
1682
1683
1684

1685
1686
1687
1688
1689
1690
1691


1692
1693
1694
1695
1696
1697
1698
1699
1700
1701


1702
1703
1704
1705

1706
1707
1708
1709
1710
1711
1712
....
1723
1724
1725
1726
1727
1728
1729

1730
1731
1732
1733

1734
1735
1736
1737
1738
1739

1740
1741
1742
1743
1744

1745
1746
 */
int bpc_auth(BPC_CONN *handle, const char *username, const char *password) {
	uint8_t cmd_reply;
	uint8_t status;
	int sockid;

	if (!handle || !username || !password) {

		return(0);
	}

	if (handle->state != BPC_CMD_NONE) {

		return(0);
	}

	sockid = handle->fd;

	if (!_bpc_client_write(sockid,
	                      BPC_CDT_UINT8, (uint8_t) BPC_CMD_AUTH,
	                      BPC_CDT_UINT16, (uint16_t) strlen(username),
	                      BPC_CDT_UINT16, (uint16_t) strlen(password),
	                      BPC_CDT_STRING, username,
	                      BPC_CDT_STRING, password,
	                      BPC_CDT_END)) {

		return(0);
	}

	if (!_bpc_client_read(sockid,
	                     BPC_CDT_UINT8, (uint8_t *) &cmd_reply,
	                     BPC_CDT_UINT8, (uint8_t *) &status,
	                     BPC_CDT_END)) {

		return(0);
	}

	if (cmd_reply != BPC_CMD_AUTH_REPLY) {

		return(0);
	}

	if (status != BPC_STATUS_OKAY) {

		return(0);
	}


	return(1);
}

/*
 * SYNOPSIS (internal):
 *   static int _bpc_listget_open(
 *                                BPC_CONN *handle,
................................................................................
static int _bpc_listget_open(BPC_CONN *handle, backuppc_cmd_t sendcmd, const char *rootpath, const int recursive, backuppc_hashid_t hashalgo, const char *exclpat, const char *inclpat) {
	uint8_t cmd, cmd_options = 0;
	int sockid;

	sockid = handle->fd;

	if (sendcmd != BPC_CMD_LIST && sendcmd != BPC_CMD_GET) {

		return(0);
	}

	/*
	 * Handle NULL patterns as blank ones.
	 */
	if (!exclpat) {
................................................................................
	handle->dent.name[0] = '\0';

	memset(&handle->dent.hash_md4, 0, sizeof(handle->dent.hash_md4));
	memset(&handle->dent.hash_md5, 0, sizeof(handle->dent.hash_md5));
	memset(&handle->dent.hash_sha1, 0, sizeof(handle->dent.hash_sha1));
	memset(&handle->dent.hash_bpc, 0, sizeof(handle->dent.hash_bpc));


	return(1);
}

/*
 * SYNOPSIS (internal):
 *   static int _bpc_listget_close(
 *                                 BPC_CONN *handle
................................................................................
 *   }
 *
 */
static int _bpc_listget_close(BPC_CONN *handle) {

	handle->state = BPC_CMD_NONE;


	return(1);
}

/*
 * SYNOPSIS (internal):
 *   static struct bpc_fileinfo *_bpc_list(
 *                                         BPC_CONN *handle,
................................................................................
	                      BPC_CDT_UINT8, (uint8_t *) &filetype,
	                      BPC_CDT_END)) {
		CHECKPOINT;
		return(NULL);
	}

	if (filetype == 0xff) {
		CHECKPOINT;
		_bpc_listget_close(handle);

		return(NULL);
	}

	if (!_bpc_client_read(sockid,
	                      BPC_CDT_UINT32, (uint32_t *) &attr_sect_len,
	                      BPC_CDT_UINT64, (uint64_t *) &filesize,
	                      BPC_CDT_UINT32, (uint32_t *) &blocksize,
................................................................................
 *   }
 *
 */
int bpc_get_open(BPC_CONN *handle, const char *rootpath, const int recursive, backuppc_hashid_t hashalgo, const char *exclpat, const char *inclpat) {
	int retval;

	if (!handle) {

		return(0);
	}

	if (handle->state != BPC_CMD_NONE) {

		return(0);
	}

	retval = _bpc_listget_open(handle, BPC_CMD_GET, rootpath, recursive, hashalgo, exclpat, inclpat);

	if (retval == 0) {

		return(0);
	}


	return(retval);
}

/*
 * SYNOPSIS:
 *   int bpc_get_close(
 *                     BPC_CONN *handle
................................................................................
	struct bpc_transfer *tinfo;
	ssize_t recv_ret;
	uint32_t bytes_left;
	uint32_t sinkbytes = 0;
	int sockid;

	if (!handle) {

		return(-1);
	}

	if (handle->state != BPC_CMD_GET_DATA) {

		return(-1);
	}

	sockid = handle->fd;

	tinfo = &handle->tinfo;

................................................................................
			                      BPC_CDT_END)) {
				CHECKPOINT;
				return(-1);
			}

			if (tinfo->currblocknum == 0xffffffff) {
				handle->state = BPC_CMD_GET;

				return(0);
			}
		}

		if (tinfo->currblocknum == 0) {
			tinfo->idealblocknum = 0;
		} else {
................................................................................
				CHECKPOINT;
				return(-1);
			}
		}
	}

	if (recv_ret < 0) {

		return(-1);
	}

	tinfo->blockoffset += recv_ret + sinkbytes;

	if (tinfo->blockoffset == tinfo->blocksize) {
		tinfo->blockoffset = 0;
	}


	return(recv_ret);
}

int bpc_copy(BPC_CONN *handle, bpc_mode_t mode, int fd) {
	char buf[32768];
	ssize_t read_ret, write_ret;
	int write_fail_count = 0;
................................................................................
				break;
			}

			read_ret -= write_ret;
		}
	}


	return(retval);
}

int bpc_rdiffget(BPC_CONN *handle, const char *remote_src, const char *dest) {
	backuppc_hashid_t hashalgo = BPC_HASH_MD4;
	struct stat stbuf;
	uint64_t filesize;
................................................................................
	if (hash_handle) {
		free(hash_handle);
	}

	return(1);
}

int bpc_copyfile(BPC_CONN *handle, struct bpc_fileinfo *src, const char *dest) {
	int fd;
	int retval = 0;
	int sys_ret;

	switch (src->type) {
		case BPC_FILE_DIR:
			backuppc_mkdir(dest);
................................................................................
			}
			break;
		case BPC_FILE_CDEV:
		case BPC_FILE_BDEV:
		case BPC_FILE_SOCKET:
		case BPC_FILE_FIFO:
		case BPC_FILE_UNKNOWN:

			return(0); 
		case BPC_FILE_REG:
			/*
			 * Regular files are handled seperately
			 */
			break;
	}

	if (src->type != BPC_FILE_REG) {
		if (retval) {
			chmod(dest, src->mode);
#ifdef HAVE_LCHOWN
			lchown(dest, src->uid, src->gid);
#else
			chown(dest, src->uid, src->gid);
#endif
#ifdef HAVE_UTIME
//			utime(...)
#endif
		}

		return(retval);
	}


	/*
	 * Handle the regular files using either RDIFF or GET.
	 */
	if (access(dest, F_OK) == 0) {
		/*
		 * Do RDIFF 
		 */
	} else {
		/*
		 * Copy the entire file.
		 */
................................................................................

		if (bpc_copy(handle, BPC_MODE_WRITE, fd)) {
			retval = 1;
		}

		close(fd);
	}

	chmod(dest, src->mode);
	chown(dest, src->uid, src->gid);






	return(retval);
}

/*
 * SYNOPSIS:
 *   BPC_CONN *bpc_connect(
 *                         const char *host,
................................................................................
	} else {
		real_port = port;
	}

	sockid = net_connect_tcp(host, real_port);

	if (sockid < 0) {

		return(NULL);
	}

	ret = malloc(sizeof(*ret));

	if (!ret) {
		close(sockid);


		return(NULL);
	}

	ret->fd = sockid;
	ret->state = BPC_CMD_NONE;

	if (username && password) {
		if (!bpc_auth(ret, username, password)) {
			close(ret->fd);
			free(ret);


			return(NULL);
		}
	}


	return(ret);
}

/*
 * SYNOPSIS:
 *   int bpc_disconnect(
 *                      BPC_CONN *handle
................................................................................
 * EXAMPLES:
 *
 */
int bpc_disconnect(BPC_CONN *handle) {
	int close_ret;

	if (!handle) {

		return(-1);
	}

	if (handle->fd < 0) {

		return(0);
	}

	close_ret = net_close(handle->fd);

	if (close_ret < 0) {

		return(close_ret);
	}

	free(handle);


	return(0);
}







>




>












>







>




>




>



>







 







>







 







>







 







>







 







<

>







 







>




>






>



>







 







>




>







 







>







 







>









>







 







>







 







|







 







>









|










>







|







 







>
|
|
>
>
>
|
>
>







 







>







>
>










>
>




>







 







>




>






>





>


374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
...
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
...
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
...
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
...
652
653
654
655
656
657
658

659
660
661
662
663
664
665
666
667
....
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
....
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
....
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
....
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
....
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
....
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
....
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
....
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
....
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
....
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
 */
int bpc_auth(BPC_CONN *handle, const char *username, const char *password) {
	uint8_t cmd_reply;
	uint8_t status;
	int sockid;

	if (!handle || !username || !password) {
		CHECKPOINT;
		return(0);
	}

	if (handle->state != BPC_CMD_NONE) {
		CHECKPOINT;
		return(0);
	}

	sockid = handle->fd;

	if (!_bpc_client_write(sockid,
	                      BPC_CDT_UINT8, (uint8_t) BPC_CMD_AUTH,
	                      BPC_CDT_UINT16, (uint16_t) strlen(username),
	                      BPC_CDT_UINT16, (uint16_t) strlen(password),
	                      BPC_CDT_STRING, username,
	                      BPC_CDT_STRING, password,
	                      BPC_CDT_END)) {
		CHECKPOINT;
		return(0);
	}

	if (!_bpc_client_read(sockid,
	                     BPC_CDT_UINT8, (uint8_t *) &cmd_reply,
	                     BPC_CDT_UINT8, (uint8_t *) &status,
	                     BPC_CDT_END)) {
		CHECKPOINT;
		return(0);
	}

	if (cmd_reply != BPC_CMD_AUTH_REPLY) {
		CHECKPOINT;
		return(0);
	}

	if (status != BPC_STATUS_OKAY) {
		CHECKPOINT;
		return(0);
	}

	CHECKPOINT;
	return(1);
}

/*
 * SYNOPSIS (internal):
 *   static int _bpc_listget_open(
 *                                BPC_CONN *handle,
................................................................................
static int _bpc_listget_open(BPC_CONN *handle, backuppc_cmd_t sendcmd, const char *rootpath, const int recursive, backuppc_hashid_t hashalgo, const char *exclpat, const char *inclpat) {
	uint8_t cmd, cmd_options = 0;
	int sockid;

	sockid = handle->fd;

	if (sendcmd != BPC_CMD_LIST && sendcmd != BPC_CMD_GET) {
		CHECKPOINT;
		return(0);
	}

	/*
	 * Handle NULL patterns as blank ones.
	 */
	if (!exclpat) {
................................................................................
	handle->dent.name[0] = '\0';

	memset(&handle->dent.hash_md4, 0, sizeof(handle->dent.hash_md4));
	memset(&handle->dent.hash_md5, 0, sizeof(handle->dent.hash_md5));
	memset(&handle->dent.hash_sha1, 0, sizeof(handle->dent.hash_sha1));
	memset(&handle->dent.hash_bpc, 0, sizeof(handle->dent.hash_bpc));

	CHECKPOINT;
	return(1);
}

/*
 * SYNOPSIS (internal):
 *   static int _bpc_listget_close(
 *                                 BPC_CONN *handle
................................................................................
 *   }
 *
 */
static int _bpc_listget_close(BPC_CONN *handle) {

	handle->state = BPC_CMD_NONE;

	CHECKPOINT;
	return(1);
}

/*
 * SYNOPSIS (internal):
 *   static struct bpc_fileinfo *_bpc_list(
 *                                         BPC_CONN *handle,
................................................................................
	                      BPC_CDT_UINT8, (uint8_t *) &filetype,
	                      BPC_CDT_END)) {
		CHECKPOINT;
		return(NULL);
	}

	if (filetype == 0xff) {

		_bpc_listget_close(handle);
		CHECKPOINT;
		return(NULL);
	}

	if (!_bpc_client_read(sockid,
	                      BPC_CDT_UINT32, (uint32_t *) &attr_sect_len,
	                      BPC_CDT_UINT64, (uint64_t *) &filesize,
	                      BPC_CDT_UINT32, (uint32_t *) &blocksize,
................................................................................
 *   }
 *
 */
int bpc_get_open(BPC_CONN *handle, const char *rootpath, const int recursive, backuppc_hashid_t hashalgo, const char *exclpat, const char *inclpat) {
	int retval;

	if (!handle) {
		CHECKPOINT;
		return(0);
	}

	if (handle->state != BPC_CMD_NONE) {
		CHECKPOINT;
		return(0);
	}

	retval = _bpc_listget_open(handle, BPC_CMD_GET, rootpath, recursive, hashalgo, exclpat, inclpat);

	if (retval == 0) {
		CHECKPOINT;
		return(0);
	}

	CHECKPOINT;
	return(retval);
}

/*
 * SYNOPSIS:
 *   int bpc_get_close(
 *                     BPC_CONN *handle
................................................................................
	struct bpc_transfer *tinfo;
	ssize_t recv_ret;
	uint32_t bytes_left;
	uint32_t sinkbytes = 0;
	int sockid;

	if (!handle) {
		CHECKPOINT;
		return(-1);
	}

	if (handle->state != BPC_CMD_GET_DATA) {
		CHECKPOINT;
		return(-1);
	}

	sockid = handle->fd;

	tinfo = &handle->tinfo;

................................................................................
			                      BPC_CDT_END)) {
				CHECKPOINT;
				return(-1);
			}

			if (tinfo->currblocknum == 0xffffffff) {
				handle->state = BPC_CMD_GET;
				CHECKPOINT;
				return(0);
			}
		}

		if (tinfo->currblocknum == 0) {
			tinfo->idealblocknum = 0;
		} else {
................................................................................
				CHECKPOINT;
				return(-1);
			}
		}
	}

	if (recv_ret < 0) {
		CHECKPOINT;
		return(-1);
	}

	tinfo->blockoffset += recv_ret + sinkbytes;

	if (tinfo->blockoffset == tinfo->blocksize) {
		tinfo->blockoffset = 0;
	}

	CHECKPOINT;
	return(recv_ret);
}

int bpc_copy(BPC_CONN *handle, bpc_mode_t mode, int fd) {
	char buf[32768];
	ssize_t read_ret, write_ret;
	int write_fail_count = 0;
................................................................................
				break;
			}

			read_ret -= write_ret;
		}
	}

	CHECKPOINT;
	return(retval);
}

int bpc_rdiffget(BPC_CONN *handle, const char *remote_src, const char *dest) {
	backuppc_hashid_t hashalgo = BPC_HASH_MD4;
	struct stat stbuf;
	uint64_t filesize;
................................................................................
	if (hash_handle) {
		free(hash_handle);
	}

	return(1);
}

int bpc_copyfile(BPC_CONN *handle, struct bpc_fileinfo *src, const char *dest, int preserve) {
	int fd;
	int retval = 0;
	int sys_ret;

	switch (src->type) {
		case BPC_FILE_DIR:
			backuppc_mkdir(dest);
................................................................................
			}
			break;
		case BPC_FILE_CDEV:
		case BPC_FILE_BDEV:
		case BPC_FILE_SOCKET:
		case BPC_FILE_FIFO:
		case BPC_FILE_UNKNOWN:
			CHECKPOINT;
			return(0); 
		case BPC_FILE_REG:
			/*
			 * Regular files are handled seperately
			 */
			break;
	}

	if (src->type != BPC_FILE_REG) {
		if (retval && preserve) {
			chmod(dest, src->mode);
#ifdef HAVE_LCHOWN
			lchown(dest, src->uid, src->gid);
#else
			chown(dest, src->uid, src->gid);
#endif
#ifdef HAVE_UTIME
//			utime(...)
#endif
		}
		CHECKPOINT;
		return(retval);
	}


	/*
	 * Handle the regular files using either RDIFF or GET.
	 */
	if (access(dest, F_OK) == 0 && 0 /* XXX: RGET NOT IMPLEMENTED */) {
		/*
		 * Do RDIFF 
		 */
	} else {
		/*
		 * Copy the entire file.
		 */
................................................................................

		if (bpc_copy(handle, BPC_MODE_WRITE, fd)) {
			retval = 1;
		}

		close(fd);
	}
	if (preserve) {
		chmod(dest, src->mode);
		chown(dest, src->uid, src->gid);
#ifdef HAVE_UTIME
//		utime(...)
#endif
	}

	CHECKPOINT;
	return(retval);
}

/*
 * SYNOPSIS:
 *   BPC_CONN *bpc_connect(
 *                         const char *host,
................................................................................
	} else {
		real_port = port;
	}

	sockid = net_connect_tcp(host, real_port);

	if (sockid < 0) {
		CHECKPOINT;
		return(NULL);
	}

	ret = malloc(sizeof(*ret));

	if (!ret) {
		close(sockid);

		CHECKPOINT;
		return(NULL);
	}

	ret->fd = sockid;
	ret->state = BPC_CMD_NONE;

	if (username && password) {
		if (!bpc_auth(ret, username, password)) {
			close(ret->fd);
			free(ret);

			CHECKPOINT;
			return(NULL);
		}
	}

	CHECKPOINT;
	return(ret);
}

/*
 * SYNOPSIS:
 *   int bpc_disconnect(
 *                      BPC_CONN *handle
................................................................................
 * EXAMPLES:
 *
 */
int bpc_disconnect(BPC_CONN *handle) {
	int close_ret;

	if (!handle) {
		CHECKPOINT;
		return(-1);
	}

	if (handle->fd < 0) {
		CHECKPOINT;
		return(0);
	}

	close_ret = net_close(handle->fd);

	if (close_ret < 0) {
		CHECKPOINT;
		return(close_ret);
	}

	free(handle);

	CHECKPOINT;
	return(0);
}

Changes to libbackuppcd.h.

92
93
94
95
96
97
98
99
100
101
102
/*
 * Operations associated with transfering files
 */
int bpc_get_open(BPC_CONN *handle, const char *rootpath, const int recursive, backuppc_hashid_t hashalgo, const char *exclpat, const char *inclpat);
struct bpc_fileinfo *bpc_get_head(BPC_CONN *handle);
ssize_t bpc_get(BPC_CONN *handle, void *buf, size_t count);
int bpc_copy(BPC_CONN *handle, bpc_mode_t mode, int fd);
int bpc_copyfile(BPC_CONN *handle, struct bpc_fileinfo *src, const char *dest);
int bpc_get_close(BPC_CONN *handle);

#endif







|



92
93
94
95
96
97
98
99
100
101
102
/*
 * Operations associated with transfering files
 */
int bpc_get_open(BPC_CONN *handle, const char *rootpath, const int recursive, backuppc_hashid_t hashalgo, const char *exclpat, const char *inclpat);
struct bpc_fileinfo *bpc_get_head(BPC_CONN *handle);
ssize_t bpc_get(BPC_CONN *handle, void *buf, size_t count);
int bpc_copy(BPC_CONN *handle, bpc_mode_t mode, int fd);
int bpc_copyfile(BPC_CONN *handle, struct bpc_fileinfo *src, const char *dest, int preserve);
int bpc_get_close(BPC_CONN *handle);

#endif

Changes to link.h.





1
2
3
4
5
6
7
8
9
10
11




#ifndef HAVE_LINK
#  ifndef _RSK_LINK_H
#    define _RSK_LINK_H 1
#    include "compat.h"
#    include "backuppcd.h"
#    include "backuppcd-common.h"

int link(const char *oldpath, const char *newpath);

#  endif /* _RSK_LINK_H */
#endif /* HAVE_LINK */
>
>
>
>











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "compat.h"
#include "backuppcd.h"
#include "backuppcd-common.h"

#ifndef HAVE_LINK
#  ifndef _RSK_LINK_H
#    define _RSK_LINK_H 1
#    include "compat.h"
#    include "backuppcd.h"
#    include "backuppcd-common.h"

int link(const char *oldpath, const char *newpath);

#  endif /* _RSK_LINK_H */
#endif /* HAVE_LINK */

Changes to sha1.c.

192
193
194
195
196
197
198























    memset(context->state, 0, 20);
    memset(context->count, 0, 8);
    memset(&finalcount, 0, 8);
#ifdef SHA1HANDSOFF  /* make SHA1Transform overwrite it's own static vars */
    SHA1Transform(context->state, context->buffer);
#endif
}






























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
    memset(context->state, 0, 20);
    memset(context->count, 0, 8);
    memset(&finalcount, 0, 8);
#ifdef SHA1HANDSOFF  /* make SHA1Transform overwrite it's own static vars */
    SHA1Transform(context->state, context->buffer);
#endif
}

char *SHA1sum(char *string) {
	unsigned char digest[20];
	static char ret[(sizeof(digest) * 2) + 1] = {0};
	static char hexabet[] = "0123456789abcdef";
	SHA1_CTX ctx;
	int retcnt = 0, i;

	SHA1Init(&ctx);

	SHA1Update(&ctx, string, strlen(string));

	SHA1Final(digest, &ctx);

	for (i = 0; i < sizeof(digest); i++) {
		ret[retcnt++] = hexabet[(digest[i] & 0xf0) >> 4];
		ret[retcnt++] = hexabet[digest[i] & 0xf];
	}

	ret[retcnt] = '\0';

	return(ret);
}

Changes to sha1.h.

5
6
7
8
9
10
11
12
13
14



15
    unsigned long state[5];
    unsigned long count[2];
    unsigned char buffer[64];
} SHA1_CTX;

void SHA1Transform(unsigned long state[5], unsigned char buffer[64]);
void SHA1Init(SHA1_CTX* context);
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len);                                                                 
void SHA1Final(unsigned char digest[20], SHA1_CTX* context);                                                                               




#endif







|
|

>
>
>

5
6
7
8
9
10
11
12
13
14
15
16
17
18
    unsigned long state[5];
    unsigned long count[2];
    unsigned char buffer[64];
} SHA1_CTX;

void SHA1Transform(unsigned long state[5], unsigned char buffer[64]);
void SHA1Init(SHA1_CTX* context);
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len);
void SHA1Final(unsigned char digest[20], SHA1_CTX* context);

/* RSK */
char *SHA1sum(char *string);

#endif

Changes to tools/file_sync.c.

34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
..
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
90
...
109
110
111
112
113
114
115
116
117
118





119
120
121
122
123
124
125
...
127
128
129
130
131
132
133
134
135
136





137
138
139
140
141
142
143
static ssize_t read_large(int fd, char *buf, size_t count) {
	size_t bytestoread;
	ssize_t read_ret;
	ssize_t retval = 0;

	while (count) {
		bytestoread = count;
#if 0

		if (bytestoread > 32768) {
			bytestoread = 32768;
		}
#endif

		read_ret = read(fd, buf, bytestoread);
		if (read_ret < 0) {
			/*
			 * Only indicate an error if we have not read anything
			 * into the buffer.  Subsequent calls to read() should
			 * generate the error again.  Hopefully.
................................................................................
static ssize_t write_large(int fd, char *buf, size_t count) {
	size_t bytestowrite;
	ssize_t write_ret;
	ssize_t retval = 0;

	while (count) {
		bytestowrite = count;
#if 0

		if (bytestowrite > 32768) {
			bytestowrite = 32768;
		}
#endif

		write_ret = write(fd, buf, bytestowrite);
		if (write_ret < 0) {
			retval = -1;
			break;
		}

................................................................................
		net_bytesin += retval;
	}

	return(retval);
}

static ssize_t write_net(int fd, void *buf, size_t count) {
	net_bytesout += count;

	return(write(fd, buf, count));





}

static ssize_t read_large_net(int fd, void *buf, size_t count) {
	ssize_t retval;

	retval = read_large(fd, buf, count);

................................................................................
		net_bytesin += retval;
	}

	return(retval);
}

static ssize_t write_large_net(int fd, void *buf, size_t count) {
	net_bytesout += count;

	return(write_large(fd, buf, count));





}

int sync_transmit(const char *host, int port, const char *file) {
	rsaref_MD4_CTX mdctx;
	unsigned char md4buf[16];
	uint64_t filesize;
	uint32_t blocksize;







<
>
|
|

<







 







<
>
|
|

<







 







|

|
>
>
>
>
>







 







|

|
>
>
>
>
>







34
35
36
37
38
39
40

41
42
43
44

45
46
47
48
49
50
51
..
71
72
73
74
75
76
77

78
79
80
81

82
83
84
85
86
87
88
...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
static ssize_t read_large(int fd, char *buf, size_t count) {
	size_t bytestoread;
	ssize_t read_ret;
	ssize_t retval = 0;

	while (count) {
		bytestoread = count;


		if (bytestoread >= INT_MAX) {
			bytestoread = INT_MAX - 1;
		}


		read_ret = read(fd, buf, bytestoread);
		if (read_ret < 0) {
			/*
			 * Only indicate an error if we have not read anything
			 * into the buffer.  Subsequent calls to read() should
			 * generate the error again.  Hopefully.
................................................................................
static ssize_t write_large(int fd, char *buf, size_t count) {
	size_t bytestowrite;
	ssize_t write_ret;
	ssize_t retval = 0;

	while (count) {
		bytestowrite = count;


		if (bytestowrite >= INT_MAX) {
			bytestowrite = INT_MAX - 1;
		}


		write_ret = write(fd, buf, bytestowrite);
		if (write_ret < 0) {
			retval = -1;
			break;
		}

................................................................................
		net_bytesin += retval;
	}

	return(retval);
}

static ssize_t write_net(int fd, void *buf, size_t count) {
	ssize_t retval;

	retval = write(fd, buf, count);
	if (retval > 0) {
		net_bytesout += retval;
	}

	return(retval);
}

static ssize_t read_large_net(int fd, void *buf, size_t count) {
	ssize_t retval;

	retval = read_large(fd, buf, count);

................................................................................
		net_bytesin += retval;
	}

	return(retval);
}

static ssize_t write_large_net(int fd, void *buf, size_t count) {
	ssize_t retval;

	retval = write_large(fd, buf, count);
	if (retval > 0) {
		net_bytesout += retval;
	}

	return(retval);
}

int sync_transmit(const char *host, int port, const char *file) {
	rsaref_MD4_CTX mdctx;
	unsigned char md4buf[16];
	uint64_t filesize;
	uint32_t blocksize;

Changes to win32.h.

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#    define HAVE_GETHOSTBYNAME 1
#    define HAVE_INET_ADDR 1
#    define HAVE_SOCKET 1
#    define HAVE_CONNECT 1
#  endif
#  define sleep(x) Sleep((x) * 1000)
#else
   /* MSVC++ configuration follows */
#  undef HAVE_UNISTD_H
#  define HAVE_STDLIB_H 1
#  define HAVE_WINDOWS_H 1
#  define HAVE_STDARG_H 1
#  define HAVE_WINSVC_H 1
#  define HAVE_WINSOCK2_H 1
#  define HAVE_WINDOWSX_H 1







|







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#    define HAVE_GETHOSTBYNAME 1
#    define HAVE_INET_ADDR 1
#    define HAVE_SOCKET 1
#    define HAVE_CONNECT 1
#  endif
#  define sleep(x) Sleep((x) * 1000)
#else
   /* MSVC++ configuration follows (untested) */
#  undef HAVE_UNISTD_H
#  define HAVE_STDLIB_H 1
#  define HAVE_WINDOWS_H 1
#  define HAVE_STDARG_H 1
#  define HAVE_WINSVC_H 1
#  define HAVE_WINSOCK2_H 1
#  define HAVE_WINDOWSX_H 1