CVE-2013-6442: s3:smbcacls - ensure we don't lose an existing ACL when setting owner...
[Samba.git] / examples / libsmbclient / testtruncate.c
blob3e29ad225c718e324da46d93b2333f31f35ea84f
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4 #include <time.h>
5 #include <errno.h>
6 #include <libsmbclient.h>
7 #include "get_auth_data_fn.h"
10 int main(int argc, char * argv[])
12 int fd;
13 int ret;
14 int debug = 0;
15 int savedErrno;
16 char buffer[128];
17 struct stat st;
19 if (argc != 2)
21 printf("usage: "
22 "%s smb://path/to/file\n",
23 argv[0]);
24 return 1;
27 smbc_init(get_auth_data_fn, debug);
29 if ((fd = smbc_open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
31 perror("smbc_open");
32 return 1;
35 strcpy(buffer, "Hello world.\nThis is a test.\n");
37 ret = smbc_write(fd, buffer, strlen(buffer));
38 savedErrno = errno;
39 smbc_close(fd);
41 if (ret < 0)
43 errno = savedErrno;
44 perror("write");
47 if (smbc_stat(argv[1], &st) < 0)
49 perror("smbc_stat");
50 return 1;
53 printf("Original size: %lu\n", (unsigned long) st.st_size);
55 if ((fd = smbc_open(argv[1], O_WRONLY, 0)) < 0)
57 perror("smbc_open");
58 return 1;
61 ret = smbc_ftruncate(fd, 13);
62 savedErrno = errno;
63 smbc_close(fd);
64 if (ret < 0)
66 errno = savedErrno;
67 perror("smbc_ftruncate");
68 return 1;
71 if (smbc_stat(argv[1], &st) < 0)
73 perror("smbc_stat");
74 return 1;
77 printf("New size: %lu\n", (unsigned long) st.st_size);
79 return 0;