python: models: rename argument ldb to samdb
[samba.git] / source3 / smbd / srvstr.c
blob5298ea735b3a995900b14916cb62345c2c700774
1 /*
2 Unix SMB/CIFS implementation.
3 server specific string routines
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "smbd/smbd.h"
23 #include "smbd/globals.h"
24 #include "lib/util/string_wrappers.h"
26 /* Make sure we can't write a string past the end of the buffer */
28 NTSTATUS srvstr_push_fn(const char *base_ptr, uint16_t smb_flags2, void *dest,
29 const char *src, int dest_len, int flags, size_t *ret_len)
31 size_t len;
32 int saved_errno;
33 NTSTATUS status;
35 if (dest_len < 0) {
36 return NT_STATUS_INVALID_PARAMETER;
39 saved_errno = errno;
40 errno = 0;
42 /* 'normal' push into size-specified buffer */
43 len = push_string_base(base_ptr, smb_flags2, dest, src,
44 dest_len, flags);
46 if (errno != 0) {
48 * Special case E2BIG, EILSEQ, EINVAL
49 * as they mean conversion errors here,
50 * but we don't generically map them as
51 * they can mean different things in
52 * generic filesystem calls (such as
53 * read xattrs).
55 if (errno == E2BIG || errno == EILSEQ || errno == EINVAL) {
56 status = NT_STATUS_ILLEGAL_CHARACTER;
57 } else {
58 status = map_nt_error_from_unix_common(errno);
60 * Paranoia - Filter out STATUS_MORE_ENTRIES.
61 * I don't think we can get this but it has a
62 * specific meaning to the client.
64 if (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
65 status = NT_STATUS_UNSUCCESSFUL;
68 DEBUG(10,("character conversion failure "
69 "on string (%s) (%s)\n",
70 src, strerror(errno)));
71 } else {
72 /* Success - restore untouched errno. */
73 errno = saved_errno;
74 *ret_len = len;
75 status = NT_STATUS_OK;
77 return status;