~ubuntu-branches/ubuntu/utopic/samba/utopic

« back to all changes in this revision

Viewing changes to source3/lib/recvfile.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-02-21 09:06:34 UTC
  • mfrom: (0.39.23 sid)
  • Revision ID: package-import@ubuntu.com-20120221090634-svd7q7m33pfz0847
Tags: 2:3.6.3-1ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module.
* Dropped:
  - debian/patches/fix-samba-printer-browsing.patch: No longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 * It's safe to make direct syscalls to lseek/write here
31
31
 * as we're below the Samba vfs layer.
32
32
 *
33
 
 * If tofd is -1 we just drain the incoming socket of count
34
 
 * bytes without writing to the outgoing fd.
35
 
 * If a write fails we do the same (to cope with disk full)
36
 
 * errors.
37
 
 *
38
33
 * Returns -1 on short reads from fromfd (read error)
39
34
 * and sets errno.
40
35
 *
41
36
 * Returns number of bytes written to 'tofd'
42
 
 * or thrown away if 'tofd == -1'.
43
37
 * return != count then sets errno.
44
38
 * Returns count if complete success.
45
39
 */
96
90
 
97
91
                num_written = 0;
98
92
 
99
 
                while (num_written < read_ret) {
 
93
                /* Don't write any more after a write error. */
 
94
                while (tofd != -1 && (num_written < read_ret)) {
100
95
                        ssize_t write_ret;
101
96
 
102
 
                        if (tofd == -1) {
103
 
                                write_ret = read_ret;
104
 
                        } else {
105
 
                                /* Write to file - ignore EINTR. */
106
 
                                write_ret = sys_write(tofd,
107
 
                                                buffer + num_written,
108
 
                                                read_ret - num_written);
 
97
                        /* Write to file - ignore EINTR. */
 
98
                        write_ret = sys_write(tofd,
 
99
                                        buffer + num_written,
 
100
                                        read_ret - num_written);
109
101
 
110
 
                                if (write_ret <= 0) {
111
 
                                        /* write error - stop writing. */
112
 
                                        tofd = -1;
113
 
                                        saved_errno = errno;
114
 
                                        continue;
115
 
                                }
 
102
                        if (write_ret <= 0) {
 
103
                                /* write error - stop writing. */
 
104
                                tofd = -1;
 
105
                                if (total_written == 0) {
 
106
                                        /* Ensure we return
 
107
                                           -1 if the first
 
108
                                           write failed. */
 
109
                                        total_written = -1;
 
110
                                }
 
111
                                saved_errno = errno;
 
112
                                break;
116
113
                        }
117
114
 
118
115
                        num_written += (size_t)write_ret;
214
211
        }
215
212
 
216
213
 done:
217
 
        if (total_written < count) {
 
214
        if (count) {
218
215
                int saved_errno = errno;
219
 
                if (drain_socket(fromfd, count-total_written) !=
220
 
                                count-total_written) {
 
216
                if (drain_socket(fromfd, count) != count) {
221
217
                        /* socket is dead. */
222
218
                        return -1;
223
219
                }
243
239
 
244
240
/*****************************************************************
245
241
 Throw away "count" bytes from the client socket.
 
242
 Returns count or -1 on error.
246
243
*****************************************************************/
247
244
 
248
245
ssize_t drain_socket(int sockfd, size_t count)
249
246
{
250
 
        return default_sys_recvfile(sockfd, -1, (SMB_OFF_T)-1, count);
 
247
        size_t total = 0;
 
248
        size_t bufsize = MIN(TRANSFER_BUF_SIZE,count);
 
249
        char *buffer = NULL;
 
250
 
 
251
        if (count == 0) {
 
252
                return 0;
 
253
        }
 
254
 
 
255
        buffer = SMB_MALLOC_ARRAY(char, bufsize);
 
256
        if (buffer == NULL) {
 
257
                return -1;
 
258
        }
 
259
 
 
260
        while (total < count) {
 
261
                ssize_t read_ret;
 
262
                size_t toread = MIN(bufsize,count - total);
 
263
 
 
264
                /* Read from socket - ignore EINTR. */
 
265
                read_ret = sys_read(sockfd, buffer, toread);
 
266
                if (read_ret <= 0) {
 
267
                        /* EOF or socket error. */
 
268
                        free(buffer);
 
269
                        return -1;
 
270
                }
 
271
                total += read_ret;
 
272
        }
 
273
 
 
274
        free(buffer);
 
275
        return count;
251
276
}