Fix coverity CID-602. Possible use of uninitialized var.
[Samba.git] / source / libsmb / libsmb_dir.c
blobb0762e89a34824a225070c52526718486be2d591
1 /*
2 Unix SMB/Netbios implementation.
3 SMB client library implementation
4 Copyright (C) Andrew Tridgell 1998
5 Copyright (C) Richard Sharpe 2000, 2002
6 Copyright (C) John Terpstra 2000
7 Copyright (C) Tom Jansen (Ninja ISD) 2002
8 Copyright (C) Derrell Lipman 2003-2008
9 Copyright (C) Jeremy Allison 2007, 2008
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "includes.h"
26 #include "libsmbclient.h"
27 #include "libsmb_internal.h"
31 * Routine to open a directory
32 * We accept the URL syntax explained in SMBC_parse_path(), above.
35 static void
36 remove_dir(SMBCFILE *dir)
38 struct smbc_dir_list *d,*f;
40 d = dir->dir_list;
41 while (d) {
43 f = d; d = d->next;
45 SAFE_FREE(f->dirent);
46 SAFE_FREE(f);
50 dir->dir_list = dir->dir_end = dir->dir_next = NULL;
54 static int
55 add_dirent(SMBCFILE *dir,
56 const char *name,
57 const char *comment,
58 uint32 type)
60 struct smbc_dirent *dirent;
61 int size;
62 int name_length = (name == NULL ? 0 : strlen(name));
63 int comment_len = (comment == NULL ? 0 : strlen(comment));
66 * Allocate space for the dirent, which must be increased by the
67 * size of the name and the comment and 1 each for the null terminator.
70 size = sizeof(struct smbc_dirent) + name_length + comment_len + 2;
72 dirent = (struct smbc_dirent *)SMB_MALLOC(size);
74 if (!dirent) {
76 dir->dir_error = ENOMEM;
77 return -1;
81 ZERO_STRUCTP(dirent);
83 if (dir->dir_list == NULL) {
85 dir->dir_list = SMB_MALLOC_P(struct smbc_dir_list);
86 if (!dir->dir_list) {
88 SAFE_FREE(dirent);
89 dir->dir_error = ENOMEM;
90 return -1;
93 ZERO_STRUCTP(dir->dir_list);
95 dir->dir_end = dir->dir_next = dir->dir_list;
97 else {
99 dir->dir_end->next = SMB_MALLOC_P(struct smbc_dir_list);
101 if (!dir->dir_end->next) {
103 SAFE_FREE(dirent);
104 dir->dir_error = ENOMEM;
105 return -1;
108 ZERO_STRUCTP(dir->dir_end->next);
110 dir->dir_end = dir->dir_end->next;
113 dir->dir_end->next = NULL;
114 dir->dir_end->dirent = dirent;
116 dirent->smbc_type = type;
117 dirent->namelen = name_length;
118 dirent->commentlen = comment_len;
119 dirent->dirlen = size;
122 * dirent->namelen + 1 includes the null (no null termination needed)
123 * Ditto for dirent->commentlen.
124 * The space for the two null bytes was allocated.
126 strncpy(dirent->name, (name?name:""), dirent->namelen + 1);
127 dirent->comment = (char *)(&dirent->name + dirent->namelen + 1);
128 strncpy(dirent->comment, (comment?comment:""), dirent->commentlen + 1);
130 return 0;
134 static void
135 list_unique_wg_fn(const char *name,
136 uint32 type,
137 const char *comment,
138 void *state)
140 SMBCFILE *dir = (SMBCFILE *)state;
141 struct smbc_dir_list *dir_list;
142 struct smbc_dirent *dirent;
143 int dirent_type;
144 int do_remove = 0;
146 dirent_type = dir->dir_type;
148 if (add_dirent(dir, name, comment, dirent_type) < 0) {
150 /* An error occurred, what do we do? */
151 /* FIXME: Add some code here */
154 /* Point to the one just added */
155 dirent = dir->dir_end->dirent;
157 /* See if this was a duplicate */
158 for (dir_list = dir->dir_list;
159 dir_list != dir->dir_end;
160 dir_list = dir_list->next) {
161 if (! do_remove &&
162 strcmp(dir_list->dirent->name, dirent->name) == 0) {
163 /* Duplicate. End end of list need to be removed. */
164 do_remove = 1;
167 if (do_remove && dir_list->next == dir->dir_end) {
168 /* Found the end of the list. Remove it. */
169 dir->dir_end = dir_list;
170 free(dir_list->next);
171 free(dirent);
172 dir_list->next = NULL;
173 break;
178 static void
179 list_fn(const char *name,
180 uint32 type,
181 const char *comment,
182 void *state)
184 SMBCFILE *dir = (SMBCFILE *)state;
185 int dirent_type;
188 * We need to process the type a little ...
190 * Disk share = 0x00000000
191 * Print share = 0x00000001
192 * Comms share = 0x00000002 (obsolete?)
193 * IPC$ share = 0x00000003
195 * administrative shares:
196 * ADMIN$, IPC$, C$, D$, E$ ... are type |= 0x80000000
199 if (dir->dir_type == SMBC_FILE_SHARE) {
200 switch (type) {
201 case 0 | 0x80000000:
202 case 0:
203 dirent_type = SMBC_FILE_SHARE;
204 break;
206 case 1:
207 dirent_type = SMBC_PRINTER_SHARE;
208 break;
210 case 2:
211 dirent_type = SMBC_COMMS_SHARE;
212 break;
214 case 3 | 0x80000000:
215 case 3:
216 dirent_type = SMBC_IPC_SHARE;
217 break;
219 default:
220 dirent_type = SMBC_FILE_SHARE; /* FIXME, error? */
221 break;
224 else {
225 dirent_type = dir->dir_type;
228 if (add_dirent(dir, name, comment, dirent_type) < 0) {
230 /* An error occurred, what do we do? */
231 /* FIXME: Add some code here */
236 static void
237 dir_list_fn(const char *mnt,
238 file_info *finfo,
239 const char *mask,
240 void *state)
243 if (add_dirent((SMBCFILE *)state, finfo->name, "",
244 (finfo->mode&aDIR?SMBC_DIR:SMBC_FILE)) < 0) {
246 /* Handle an error ... */
248 /* FIXME: Add some code ... */
254 static int
255 net_share_enum_rpc(struct cli_state *cli,
256 void (*fn)(const char *name,
257 uint32 type,
258 const char *comment,
259 void *state),
260 void *state)
262 int i;
263 WERROR result;
264 uint32 preferred_len = 0xffffffff;
265 uint32 type;
266 struct srvsvc_NetShareInfoCtr info_ctr;
267 struct srvsvc_NetShareCtr1 ctr1;
268 fstring name = "";
269 fstring comment = "";
270 struct rpc_pipe_client *pipe_hnd;
271 NTSTATUS nt_status;
272 uint32_t resume_handle = 0;
273 uint32_t total_entries = 0;
275 /* Open the server service pipe */
276 pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &nt_status);
277 if (!pipe_hnd) {
278 DEBUG(1, ("net_share_enum_rpc pipe open fail!\n"));
279 return -1;
282 ZERO_STRUCT(info_ctr);
283 ZERO_STRUCT(ctr1);
285 info_ctr.level = 1;
286 info_ctr.ctr.ctr1 = &ctr1;
288 /* Issue the NetShareEnum RPC call and retrieve the response */
289 nt_status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, talloc_tos(),
290 pipe_hnd->cli->desthost,
291 &info_ctr,
292 preferred_len,
293 &total_entries,
294 &resume_handle,
295 &result);
297 /* Was it successful? */
298 if (!NT_STATUS_IS_OK(nt_status) || !W_ERROR_IS_OK(result) ||
299 total_entries == 0) {
300 /* Nope. Go clean up. */
301 goto done;
304 /* For each returned entry... */
305 for (i = 0; i < total_entries; i++) {
307 /* pull out the share name */
308 fstrcpy(name, info_ctr.ctr.ctr1->array[i].name);
310 /* pull out the share's comment */
311 fstrcpy(comment, info_ctr.ctr.ctr1->array[i].comment);
313 /* Get the type value */
314 type = info_ctr.ctr.ctr1->array[i].type;
316 /* Add this share to the list */
317 (*fn)(name, type, comment, state);
320 done:
321 /* Close the server service pipe */
322 cli_rpc_pipe_close(pipe_hnd);
324 /* Tell 'em if it worked */
325 return W_ERROR_IS_OK(result) ? 0 : -1;
330 * Verify that the options specified in a URL are valid
333 SMBC_check_options(char *server,
334 char *share,
335 char *path,
336 char *options)
338 DEBUG(4, ("SMBC_check_options(): server='%s' share='%s' "
339 "path='%s' options='%s'\n",
340 server, share, path, options));
342 /* No options at all is always ok */
343 if (! *options) return 0;
345 /* Currently, we don't support any options. */
346 return -1;
350 SMBCFILE *
351 SMBC_opendir_ctx(SMBCCTX *context,
352 const char *fname)
354 int saved_errno;
355 char *server = NULL;
356 char *share = NULL;
357 char *user = NULL;
358 char *password = NULL;
359 char *options = NULL;
360 char *workgroup = NULL;
361 char *path = NULL;
362 uint16 mode;
363 char *p = NULL;
364 SMBCSRV *srv = NULL;
365 SMBCFILE *dir = NULL;
366 struct sockaddr_storage rem_ss;
367 TALLOC_CTX *frame = talloc_stackframe();
369 if (!context || !context->internal->initialized) {
370 DEBUG(4, ("no valid context\n"));
371 errno = EINVAL + 8192;
372 TALLOC_FREE(frame);
373 return NULL;
377 if (!fname) {
378 DEBUG(4, ("no valid fname\n"));
379 errno = EINVAL + 8193;
380 TALLOC_FREE(frame);
381 return NULL;
384 if (SMBC_parse_path(frame,
385 context,
386 fname,
387 &workgroup,
388 &server,
389 &share,
390 &path,
391 &user,
392 &password,
393 &options)) {
394 DEBUG(4, ("no valid path\n"));
395 errno = EINVAL + 8194;
396 TALLOC_FREE(frame);
397 return NULL;
400 DEBUG(4, ("parsed path: fname='%s' server='%s' share='%s' "
401 "path='%s' options='%s'\n",
402 fname, server, share, path, options));
404 /* Ensure the options are valid */
405 if (SMBC_check_options(server, share, path, options)) {
406 DEBUG(4, ("unacceptable options (%s)\n", options));
407 errno = EINVAL + 8195;
408 TALLOC_FREE(frame);
409 return NULL;
412 if (!user || user[0] == (char)0) {
413 user = talloc_strdup(frame, smbc_getUser(context));
414 if (!user) {
415 errno = ENOMEM;
416 TALLOC_FREE(frame);
417 return NULL;
421 dir = SMB_MALLOC_P(SMBCFILE);
423 if (!dir) {
424 errno = ENOMEM;
425 TALLOC_FREE(frame);
426 return NULL;
429 ZERO_STRUCTP(dir);
431 dir->cli_fd = 0;
432 dir->fname = SMB_STRDUP(fname);
433 dir->srv = NULL;
434 dir->offset = 0;
435 dir->file = False;
436 dir->dir_list = dir->dir_next = dir->dir_end = NULL;
438 if (server[0] == (char)0) {
440 int i;
441 int count;
442 int max_lmb_count;
443 struct ip_service *ip_list;
444 struct ip_service server_addr;
445 struct user_auth_info u_info;
447 if (share[0] != (char)0 || path[0] != (char)0) {
449 errno = EINVAL + 8196;
450 if (dir) {
451 SAFE_FREE(dir->fname);
452 SAFE_FREE(dir);
454 TALLOC_FREE(frame);
455 return NULL;
458 /* Determine how many local master browsers to query */
459 max_lmb_count = (smbc_getOptionBrowseMaxLmbCount(context) == 0
460 ? INT_MAX
461 : smbc_getOptionBrowseMaxLmbCount(context));
463 memset(&u_info, '\0', sizeof(u_info));
464 u_info.username = talloc_strdup(frame,user);
465 u_info.password = talloc_strdup(frame,password);
466 if (!u_info.username || !u_info.password) {
467 if (dir) {
468 SAFE_FREE(dir->fname);
469 SAFE_FREE(dir);
471 TALLOC_FREE(frame);
472 return NULL;
476 * We have server and share and path empty but options
477 * requesting that we scan all master browsers for their list
478 * of workgroups/domains. This implies that we must first try
479 * broadcast queries to find all master browsers, and if that
480 * doesn't work, then try our other methods which return only
481 * a single master browser.
484 ip_list = NULL;
485 if (!NT_STATUS_IS_OK(name_resolve_bcast(MSBROWSE, 1, &ip_list,
486 &count)))
489 SAFE_FREE(ip_list);
491 if (!find_master_ip(workgroup, &server_addr.ss)) {
493 if (dir) {
494 SAFE_FREE(dir->fname);
495 SAFE_FREE(dir);
497 errno = ENOENT;
498 TALLOC_FREE(frame);
499 return NULL;
502 ip_list = (struct ip_service *)memdup(
503 &server_addr, sizeof(server_addr));
504 if (ip_list == NULL) {
505 errno = ENOMEM;
506 TALLOC_FREE(frame);
507 return NULL;
509 count = 1;
512 for (i = 0; i < count && i < max_lmb_count; i++) {
513 char addr[INET6_ADDRSTRLEN];
514 char *wg_ptr = NULL;
515 struct cli_state *cli = NULL;
517 print_sockaddr(addr, sizeof(addr), &ip_list[i].ss);
518 DEBUG(99, ("Found master browser %d of %d: %s\n",
519 i+1, MAX(count, max_lmb_count),
520 addr));
522 cli = get_ipc_connect_master_ip(talloc_tos(),
523 &ip_list[i],
524 &u_info,
525 &wg_ptr);
526 /* cli == NULL is the master browser refused to talk or
527 could not be found */
528 if (!cli) {
529 continue;
532 workgroup = talloc_strdup(frame, wg_ptr);
533 server = talloc_strdup(frame, cli->desthost);
535 cli_shutdown(cli);
537 if (!workgroup || !server) {
538 errno = ENOMEM;
539 TALLOC_FREE(frame);
540 return NULL;
543 DEBUG(4, ("using workgroup %s %s\n",
544 workgroup, server));
547 * For each returned master browser IP address, get a
548 * connection to IPC$ on the server if we do not
549 * already have one, and determine the
550 * workgroups/domains that it knows about.
553 srv = SMBC_server(frame, context, True, server, "IPC$",
554 &workgroup, &user, &password);
555 if (!srv) {
556 continue;
559 dir->srv = srv;
560 dir->dir_type = SMBC_WORKGROUP;
562 /* Now, list the stuff ... */
564 if (!cli_NetServerEnum(srv->cli,
565 workgroup,
566 SV_TYPE_DOMAIN_ENUM,
567 list_unique_wg_fn,
568 (void *)dir)) {
569 continue;
573 SAFE_FREE(ip_list);
574 } else {
576 * Server not an empty string ... Check the rest and see what
577 * gives
579 if (*share == '\0') {
580 if (*path != '\0') {
582 /* Should not have empty share with path */
583 errno = EINVAL + 8197;
584 if (dir) {
585 SAFE_FREE(dir->fname);
586 SAFE_FREE(dir);
588 TALLOC_FREE(frame);
589 return NULL;
594 * We don't know if <server> is really a server name
595 * or is a workgroup/domain name. If we already have
596 * a server structure for it, we'll use it.
597 * Otherwise, check to see if <server><1D>,
598 * <server><1B>, or <server><20> translates. We check
599 * to see if <server> is an IP address first.
603 * See if we have an existing server. Do not
604 * establish a connection if one does not already
605 * exist.
607 srv = SMBC_server(frame, context, False,
608 server, "IPC$",
609 &workgroup, &user, &password);
612 * If no existing server and not an IP addr, look for
613 * LMB or DMB
615 if (!srv &&
616 !is_ipaddress(server) &&
617 (resolve_name(server, &rem_ss, 0x1d) || /* LMB */
618 resolve_name(server, &rem_ss, 0x1b) )) { /* DMB */
620 fstring buserver;
622 dir->dir_type = SMBC_SERVER;
625 * Get the backup list ...
627 if (!name_status_find(server, 0, 0,
628 &rem_ss, buserver)) {
630 DEBUG(0,("Could not get name of "
631 "local/domain master browser "
632 "for server %s\n", server));
633 if (dir) {
634 SAFE_FREE(dir->fname);
635 SAFE_FREE(dir);
637 errno = EPERM;
638 TALLOC_FREE(frame);
639 return NULL;
644 * Get a connection to IPC$ on the server if
645 * we do not already have one
647 srv = SMBC_server(frame, context, True,
648 buserver, "IPC$",
649 &workgroup,
650 &user, &password);
651 if (!srv) {
652 DEBUG(0, ("got no contact to IPC$\n"));
653 if (dir) {
654 SAFE_FREE(dir->fname);
655 SAFE_FREE(dir);
657 TALLOC_FREE(frame);
658 return NULL;
662 dir->srv = srv;
664 /* Now, list the servers ... */
665 if (!cli_NetServerEnum(srv->cli, server,
666 0x0000FFFE, list_fn,
667 (void *)dir)) {
669 if (dir) {
670 SAFE_FREE(dir->fname);
671 SAFE_FREE(dir);
673 TALLOC_FREE(frame);
674 return NULL;
676 } else if (srv ||
677 (resolve_name(server, &rem_ss, 0x20))) {
680 * If we hadn't found the server, get one now
682 if (!srv) {
683 srv = SMBC_server(frame, context, True,
684 server, "IPC$",
685 &workgroup,
686 &user, &password);
689 if (!srv) {
690 if (dir) {
691 SAFE_FREE(dir->fname);
692 SAFE_FREE(dir);
694 TALLOC_FREE(frame);
695 return NULL;
699 dir->dir_type = SMBC_FILE_SHARE;
700 dir->srv = srv;
702 /* List the shares ... */
704 if (net_share_enum_rpc(
705 srv->cli,
706 list_fn,
707 (void *) dir) < 0 &&
708 cli_RNetShareEnum(
709 srv->cli,
710 list_fn,
711 (void *)dir) < 0) {
713 errno = cli_errno(srv->cli);
714 if (dir) {
715 SAFE_FREE(dir->fname);
716 SAFE_FREE(dir);
718 TALLOC_FREE(frame);
719 return NULL;
722 } else {
723 /* Neither the workgroup nor server exists */
724 errno = ECONNREFUSED;
725 if (dir) {
726 SAFE_FREE(dir->fname);
727 SAFE_FREE(dir);
729 TALLOC_FREE(frame);
730 return NULL;
734 else {
736 * The server and share are specified ... work from
737 * there ...
739 char *targetpath;
740 struct cli_state *targetcli;
742 /* We connect to the server and list the directory */
743 dir->dir_type = SMBC_FILE_SHARE;
745 srv = SMBC_server(frame, context, True, server, share,
746 &workgroup, &user, &password);
748 if (!srv) {
749 if (dir) {
750 SAFE_FREE(dir->fname);
751 SAFE_FREE(dir);
753 TALLOC_FREE(frame);
754 return NULL;
757 dir->srv = srv;
759 /* Now, list the files ... */
761 p = path + strlen(path);
762 path = talloc_asprintf_append(path, "\\*");
763 if (!path) {
764 if (dir) {
765 SAFE_FREE(dir->fname);
766 SAFE_FREE(dir);
768 TALLOC_FREE(frame);
769 return NULL;
772 if (!cli_resolve_path(frame, "", srv->cli, path,
773 &targetcli, &targetpath)) {
774 d_printf("Could not resolve %s\n", path);
775 if (dir) {
776 SAFE_FREE(dir->fname);
777 SAFE_FREE(dir);
779 TALLOC_FREE(frame);
780 return NULL;
783 if (cli_list(targetcli, targetpath,
784 aDIR | aSYSTEM | aHIDDEN,
785 dir_list_fn, (void *)dir) < 0) {
787 if (dir) {
788 SAFE_FREE(dir->fname);
789 SAFE_FREE(dir);
791 saved_errno = SMBC_errno(context, targetcli);
793 if (saved_errno == EINVAL) {
795 * See if they asked to opendir
796 * something other than a directory.
797 * If so, the converted error value we
798 * got would have been EINVAL rather
799 * than ENOTDIR.
801 *p = '\0'; /* restore original path */
803 if (SMBC_getatr(context, srv, path,
804 &mode, NULL,
805 NULL, NULL, NULL, NULL,
806 NULL) &&
807 ! IS_DOS_DIR(mode)) {
809 /* It is. Correct the error value */
810 saved_errno = ENOTDIR;
815 * If there was an error and the server is no
816 * good any more...
818 if (cli_is_error(targetcli) &&
819 smbc_getFunctionCheckServer(context)(context, srv)) {
821 /* ... then remove it. */
822 if (smbc_getFunctionRemoveUnusedServer(context)(context,
823 srv)) {
825 * We could not remove the
826 * server completely, remove
827 * it from the cache so we
828 * will not get it again. It
829 * will be removed when the
830 * last file/dir is closed.
832 smbc_getFunctionRemoveCachedServer(context)(context, srv);
836 errno = saved_errno;
837 TALLOC_FREE(frame);
838 return NULL;
844 DLIST_ADD(context->internal->files, dir);
845 TALLOC_FREE(frame);
846 return dir;
851 * Routine to close a directory
855 SMBC_closedir_ctx(SMBCCTX *context,
856 SMBCFILE *dir)
858 TALLOC_CTX *frame = talloc_stackframe();
860 if (!context || !context->internal->initialized) {
861 errno = EINVAL;
862 TALLOC_FREE(frame);
863 return -1;
866 if (!dir || !SMBC_dlist_contains(context->internal->files, dir)) {
867 errno = EBADF;
868 TALLOC_FREE(frame);
869 return -1;
872 remove_dir(dir); /* Clean it up */
874 DLIST_REMOVE(context->internal->files, dir);
876 if (dir) {
878 SAFE_FREE(dir->fname);
879 SAFE_FREE(dir); /* Free the space too */
882 TALLOC_FREE(frame);
883 return 0;
887 static void
888 smbc_readdir_internal(SMBCCTX * context,
889 struct smbc_dirent *dest,
890 struct smbc_dirent *src,
891 int max_namebuf_len)
893 if (smbc_getOptionUrlEncodeReaddirEntries(context)) {
895 /* url-encode the name. get back remaining buffer space */
896 max_namebuf_len =
897 smbc_urlencode(dest->name, src->name, max_namebuf_len);
899 /* We now know the name length */
900 dest->namelen = strlen(dest->name);
902 /* Save the pointer to the beginning of the comment */
903 dest->comment = dest->name + dest->namelen + 1;
905 /* Copy the comment */
906 strncpy(dest->comment, src->comment, max_namebuf_len - 1);
907 dest->comment[max_namebuf_len - 1] = '\0';
909 /* Save other fields */
910 dest->smbc_type = src->smbc_type;
911 dest->commentlen = strlen(dest->comment);
912 dest->dirlen = ((dest->comment + dest->commentlen + 1) -
913 (char *) dest);
914 } else {
916 /* No encoding. Just copy the entry as is. */
917 memcpy(dest, src, src->dirlen);
918 dest->comment = (char *)(&dest->name + src->namelen + 1);
924 * Routine to get a directory entry
927 struct smbc_dirent *
928 SMBC_readdir_ctx(SMBCCTX *context,
929 SMBCFILE *dir)
931 int maxlen;
932 struct smbc_dirent *dirp, *dirent;
933 TALLOC_CTX *frame = talloc_stackframe();
935 /* Check that all is ok first ... */
937 if (!context || !context->internal->initialized) {
939 errno = EINVAL;
940 DEBUG(0, ("Invalid context in SMBC_readdir_ctx()\n"));
941 TALLOC_FREE(frame);
942 return NULL;
946 if (!dir || !SMBC_dlist_contains(context->internal->files, dir)) {
948 errno = EBADF;
949 DEBUG(0, ("Invalid dir in SMBC_readdir_ctx()\n"));
950 TALLOC_FREE(frame);
951 return NULL;
955 if (dir->file != False) { /* FIXME, should be dir, perhaps */
957 errno = ENOTDIR;
958 DEBUG(0, ("Found file vs directory in SMBC_readdir_ctx()\n"));
959 TALLOC_FREE(frame);
960 return NULL;
964 if (!dir->dir_next) {
965 TALLOC_FREE(frame);
966 return NULL;
969 dirent = dir->dir_next->dirent;
970 if (!dirent) {
972 errno = ENOENT;
973 TALLOC_FREE(frame);
974 return NULL;
978 dirp = &context->internal->dirent;
979 maxlen = sizeof(context->internal->_dirent_name);
981 smbc_readdir_internal(context, dirp, dirent, maxlen);
983 dir->dir_next = dir->dir_next->next;
985 TALLOC_FREE(frame);
986 return dirp;
990 * Routine to get directory entries
994 SMBC_getdents_ctx(SMBCCTX *context,
995 SMBCFILE *dir,
996 struct smbc_dirent *dirp,
997 int count)
999 int rem = count;
1000 int reqd;
1001 int maxlen;
1002 char *ndir = (char *)dirp;
1003 struct smbc_dir_list *dirlist;
1004 TALLOC_CTX *frame = talloc_stackframe();
1006 /* Check that all is ok first ... */
1008 if (!context || !context->internal->initialized) {
1010 errno = EINVAL;
1011 TALLOC_FREE(frame);
1012 return -1;
1016 if (!dir || !SMBC_dlist_contains(context->internal->files, dir)) {
1018 errno = EBADF;
1019 TALLOC_FREE(frame);
1020 return -1;
1024 if (dir->file != False) { /* FIXME, should be dir, perhaps */
1026 errno = ENOTDIR;
1027 TALLOC_FREE(frame);
1028 return -1;
1033 * Now, retrieve the number of entries that will fit in what was passed
1034 * We have to figure out if the info is in the list, or we need to
1035 * send a request to the server to get the info.
1038 while ((dirlist = dir->dir_next)) {
1039 struct smbc_dirent *dirent;
1041 if (!dirlist->dirent) {
1043 errno = ENOENT; /* Bad error */
1044 TALLOC_FREE(frame);
1045 return -1;
1049 /* Do urlencoding of next entry, if so selected */
1050 dirent = &context->internal->dirent;
1051 maxlen = sizeof(context->internal->_dirent_name);
1052 smbc_readdir_internal(context, dirent,
1053 dirlist->dirent, maxlen);
1055 reqd = dirent->dirlen;
1057 if (rem < reqd) {
1059 if (rem < count) { /* We managed to copy something */
1061 errno = 0;
1062 TALLOC_FREE(frame);
1063 return count - rem;
1066 else { /* Nothing copied ... */
1068 errno = EINVAL; /* Not enough space ... */
1069 TALLOC_FREE(frame);
1070 return -1;
1076 memcpy(ndir, dirent, reqd); /* Copy the data in ... */
1078 ((struct smbc_dirent *)ndir)->comment =
1079 (char *)(&((struct smbc_dirent *)ndir)->name +
1080 dirent->namelen +
1083 ndir += reqd;
1085 rem -= reqd;
1087 dir->dir_next = dirlist = dirlist -> next;
1090 TALLOC_FREE(frame);
1092 if (rem == count)
1093 return 0;
1094 else
1095 return count - rem;
1100 * Routine to create a directory ...
1104 SMBC_mkdir_ctx(SMBCCTX *context,
1105 const char *fname,
1106 mode_t mode)
1108 SMBCSRV *srv = NULL;
1109 char *server = NULL;
1110 char *share = NULL;
1111 char *user = NULL;
1112 char *password = NULL;
1113 char *workgroup = NULL;
1114 char *path = NULL;
1115 char *targetpath = NULL;
1116 struct cli_state *targetcli = NULL;
1117 TALLOC_CTX *frame = talloc_stackframe();
1119 if (!context || !context->internal->initialized) {
1120 errno = EINVAL;
1121 TALLOC_FREE(frame);
1122 return -1;
1125 if (!fname) {
1126 errno = EINVAL;
1127 TALLOC_FREE(frame);
1128 return -1;
1131 DEBUG(4, ("smbc_mkdir(%s)\n", fname));
1133 if (SMBC_parse_path(frame,
1134 context,
1135 fname,
1136 &workgroup,
1137 &server,
1138 &share,
1139 &path,
1140 &user,
1141 &password,
1142 NULL)) {
1143 errno = EINVAL;
1144 TALLOC_FREE(frame);
1145 return -1;
1148 if (!user || user[0] == (char)0) {
1149 user = talloc_strdup(frame, smbc_getUser(context));
1150 if (!user) {
1151 errno = ENOMEM;
1152 TALLOC_FREE(frame);
1153 return -1;
1157 srv = SMBC_server(frame, context, True,
1158 server, share, &workgroup, &user, &password);
1160 if (!srv) {
1162 TALLOC_FREE(frame);
1163 return -1; /* errno set by SMBC_server */
1167 /*d_printf(">>>mkdir: resolving %s\n", path);*/
1168 if (!cli_resolve_path(frame, "", srv->cli, path,
1169 &targetcli, &targetpath)) {
1170 d_printf("Could not resolve %s\n", path);
1171 TALLOC_FREE(frame);
1172 return -1;
1174 /*d_printf(">>>mkdir: resolved path as %s\n", targetpath);*/
1176 if (!cli_mkdir(targetcli, targetpath)) {
1178 errno = SMBC_errno(context, targetcli);
1179 TALLOC_FREE(frame);
1180 return -1;
1184 TALLOC_FREE(frame);
1185 return 0;
1190 * Our list function simply checks to see if a directory is not empty
1193 static int smbc_rmdir_dirempty = True;
1195 static void
1196 rmdir_list_fn(const char *mnt,
1197 file_info *finfo,
1198 const char *mask,
1199 void *state)
1201 if (strncmp(finfo->name, ".", 1) != 0 &&
1202 strncmp(finfo->name, "..", 2) != 0) {
1203 smbc_rmdir_dirempty = False;
1208 * Routine to remove a directory
1212 SMBC_rmdir_ctx(SMBCCTX *context,
1213 const char *fname)
1215 SMBCSRV *srv = NULL;
1216 char *server = NULL;
1217 char *share = NULL;
1218 char *user = NULL;
1219 char *password = NULL;
1220 char *workgroup = NULL;
1221 char *path = NULL;
1222 char *targetpath = NULL;
1223 struct cli_state *targetcli = NULL;
1224 TALLOC_CTX *frame = talloc_stackframe();
1226 if (!context || !context->internal->initialized) {
1227 errno = EINVAL;
1228 TALLOC_FREE(frame);
1229 return -1;
1232 if (!fname) {
1233 errno = EINVAL;
1234 TALLOC_FREE(frame);
1235 return -1;
1238 DEBUG(4, ("smbc_rmdir(%s)\n", fname));
1240 if (SMBC_parse_path(frame,
1241 context,
1242 fname,
1243 &workgroup,
1244 &server,
1245 &share,
1246 &path,
1247 &user,
1248 &password,
1249 NULL)) {
1250 errno = EINVAL;
1251 TALLOC_FREE(frame);
1252 return -1;
1255 if (!user || user[0] == (char)0) {
1256 user = talloc_strdup(frame, smbc_getUser(context));
1257 if (!user) {
1258 errno = ENOMEM;
1259 TALLOC_FREE(frame);
1260 return -1;
1264 srv = SMBC_server(frame, context, True,
1265 server, share, &workgroup, &user, &password);
1267 if (!srv) {
1269 TALLOC_FREE(frame);
1270 return -1; /* errno set by SMBC_server */
1274 /*d_printf(">>>rmdir: resolving %s\n", path);*/
1275 if (!cli_resolve_path(frame, "", srv->cli, path,
1276 &targetcli, &targetpath)) {
1277 d_printf("Could not resolve %s\n", path);
1278 TALLOC_FREE(frame);
1279 return -1;
1281 /*d_printf(">>>rmdir: resolved path as %s\n", targetpath);*/
1284 if (!cli_rmdir(targetcli, targetpath)) {
1286 errno = SMBC_errno(context, targetcli);
1288 if (errno == EACCES) { /* Check if the dir empty or not */
1290 /* Local storage to avoid buffer overflows */
1291 char *lpath;
1293 smbc_rmdir_dirempty = True; /* Make this so ... */
1295 lpath = talloc_asprintf(frame, "%s\\*",
1296 targetpath);
1297 if (!lpath) {
1298 errno = ENOMEM;
1299 TALLOC_FREE(frame);
1300 return -1;
1303 if (cli_list(targetcli, lpath,
1304 aDIR | aSYSTEM | aHIDDEN,
1305 rmdir_list_fn, NULL) < 0) {
1307 /* Fix errno to ignore latest error ... */
1308 DEBUG(5, ("smbc_rmdir: "
1309 "cli_list returned an error: %d\n",
1310 SMBC_errno(context, targetcli)));
1311 errno = EACCES;
1315 if (smbc_rmdir_dirempty)
1316 errno = EACCES;
1317 else
1318 errno = ENOTEMPTY;
1322 TALLOC_FREE(frame);
1323 return -1;
1327 TALLOC_FREE(frame);
1328 return 0;
1333 * Routine to return the current directory position
1336 off_t
1337 SMBC_telldir_ctx(SMBCCTX *context,
1338 SMBCFILE *dir)
1340 TALLOC_CTX *frame = talloc_stackframe();
1342 if (!context || !context->internal->initialized) {
1344 errno = EINVAL;
1345 TALLOC_FREE(frame);
1346 return -1;
1350 if (!dir || !SMBC_dlist_contains(context->internal->files, dir)) {
1352 errno = EBADF;
1353 TALLOC_FREE(frame);
1354 return -1;
1358 if (dir->file != False) { /* FIXME, should be dir, perhaps */
1360 errno = ENOTDIR;
1361 TALLOC_FREE(frame);
1362 return -1;
1366 /* See if we're already at the end. */
1367 if (dir->dir_next == NULL) {
1368 /* We are. */
1369 TALLOC_FREE(frame);
1370 return -1;
1374 * We return the pointer here as the offset
1376 TALLOC_FREE(frame);
1377 return (off_t)(long)dir->dir_next->dirent;
1381 * A routine to run down the list and see if the entry is OK
1384 static struct smbc_dir_list *
1385 check_dir_ent(struct smbc_dir_list *list,
1386 struct smbc_dirent *dirent)
1389 /* Run down the list looking for what we want */
1391 if (dirent) {
1393 struct smbc_dir_list *tmp = list;
1395 while (tmp) {
1397 if (tmp->dirent == dirent)
1398 return tmp;
1400 tmp = tmp->next;
1406 return NULL; /* Not found, or an error */
1412 * Routine to seek on a directory
1416 SMBC_lseekdir_ctx(SMBCCTX *context,
1417 SMBCFILE *dir,
1418 off_t offset)
1420 long int l_offset = offset; /* Handle problems of size */
1421 struct smbc_dirent *dirent = (struct smbc_dirent *)l_offset;
1422 struct smbc_dir_list *list_ent = (struct smbc_dir_list *)NULL;
1423 TALLOC_CTX *frame = talloc_stackframe();
1425 if (!context || !context->internal->initialized) {
1427 errno = EINVAL;
1428 TALLOC_FREE(frame);
1429 return -1;
1433 if (dir->file != False) { /* FIXME, should be dir, perhaps */
1435 errno = ENOTDIR;
1436 TALLOC_FREE(frame);
1437 return -1;
1441 /* Now, check what we were passed and see if it is OK ... */
1443 if (dirent == NULL) { /* Seek to the begining of the list */
1445 dir->dir_next = dir->dir_list;
1446 TALLOC_FREE(frame);
1447 return 0;
1451 if (offset == -1) { /* Seek to the end of the list */
1452 dir->dir_next = NULL;
1453 TALLOC_FREE(frame);
1454 return 0;
1457 /* Now, run down the list and make sure that the entry is OK */
1458 /* This may need to be changed if we change the format of the list */
1460 if ((list_ent = check_dir_ent(dir->dir_list, dirent)) == NULL) {
1461 errno = EINVAL; /* Bad entry */
1462 TALLOC_FREE(frame);
1463 return -1;
1466 dir->dir_next = list_ent;
1468 TALLOC_FREE(frame);
1469 return 0;
1473 * Routine to fstat a dir
1477 SMBC_fstatdir_ctx(SMBCCTX *context,
1478 SMBCFILE *dir,
1479 struct stat *st)
1482 if (!context || !context->internal->initialized) {
1484 errno = EINVAL;
1485 return -1;
1488 /* No code yet ... */
1489 return 0;
1493 SMBC_chmod_ctx(SMBCCTX *context,
1494 const char *fname,
1495 mode_t newmode)
1497 SMBCSRV *srv = NULL;
1498 char *server = NULL;
1499 char *share = NULL;
1500 char *user = NULL;
1501 char *password = NULL;
1502 char *workgroup = NULL;
1503 char *path = NULL;
1504 uint16 mode;
1505 TALLOC_CTX *frame = talloc_stackframe();
1507 if (!context || !context->internal->initialized) {
1509 errno = EINVAL; /* Best I can think of ... */
1510 TALLOC_FREE(frame);
1511 return -1;
1514 if (!fname) {
1515 errno = EINVAL;
1516 TALLOC_FREE(frame);
1517 return -1;
1520 DEBUG(4, ("smbc_chmod(%s, 0%3o)\n", fname, newmode));
1522 if (SMBC_parse_path(frame,
1523 context,
1524 fname,
1525 &workgroup,
1526 &server,
1527 &share,
1528 &path,
1529 &user,
1530 &password,
1531 NULL)) {
1532 errno = EINVAL;
1533 TALLOC_FREE(frame);
1534 return -1;
1537 if (!user || user[0] == (char)0) {
1538 user = talloc_strdup(frame, smbc_getUser(context));
1539 if (!user) {
1540 errno = ENOMEM;
1541 TALLOC_FREE(frame);
1542 return -1;
1546 srv = SMBC_server(frame, context, True,
1547 server, share, &workgroup, &user, &password);
1549 if (!srv) {
1550 TALLOC_FREE(frame);
1551 return -1; /* errno set by SMBC_server */
1554 mode = 0;
1556 if (!(newmode & (S_IWUSR | S_IWGRP | S_IWOTH))) mode |= aRONLY;
1557 if ((newmode & S_IXUSR) && lp_map_archive(-1)) mode |= aARCH;
1558 if ((newmode & S_IXGRP) && lp_map_system(-1)) mode |= aSYSTEM;
1559 if ((newmode & S_IXOTH) && lp_map_hidden(-1)) mode |= aHIDDEN;
1561 if (!cli_setatr(srv->cli, path, mode, 0)) {
1562 errno = SMBC_errno(context, srv->cli);
1563 TALLOC_FREE(frame);
1564 return -1;
1567 TALLOC_FREE(frame);
1568 return 0;
1572 SMBC_utimes_ctx(SMBCCTX *context,
1573 const char *fname,
1574 struct timeval *tbuf)
1576 SMBCSRV *srv = NULL;
1577 char *server = NULL;
1578 char *share = NULL;
1579 char *user = NULL;
1580 char *password = NULL;
1581 char *workgroup = NULL;
1582 char *path = NULL;
1583 time_t access_time;
1584 time_t write_time;
1585 TALLOC_CTX *frame = talloc_stackframe();
1587 if (!context || !context->internal->initialized) {
1589 errno = EINVAL; /* Best I can think of ... */
1590 TALLOC_FREE(frame);
1591 return -1;
1594 if (!fname) {
1595 errno = EINVAL;
1596 TALLOC_FREE(frame);
1597 return -1;
1600 if (tbuf == NULL) {
1601 access_time = write_time = time(NULL);
1602 } else {
1603 access_time = tbuf[0].tv_sec;
1604 write_time = tbuf[1].tv_sec;
1607 if (DEBUGLVL(4)) {
1608 char *p;
1609 char atimebuf[32];
1610 char mtimebuf[32];
1612 strncpy(atimebuf, ctime(&access_time), sizeof(atimebuf) - 1);
1613 atimebuf[sizeof(atimebuf) - 1] = '\0';
1614 if ((p = strchr(atimebuf, '\n')) != NULL) {
1615 *p = '\0';
1618 strncpy(mtimebuf, ctime(&write_time), sizeof(mtimebuf) - 1);
1619 mtimebuf[sizeof(mtimebuf) - 1] = '\0';
1620 if ((p = strchr(mtimebuf, '\n')) != NULL) {
1621 *p = '\0';
1624 dbgtext("smbc_utimes(%s, atime = %s mtime = %s)\n",
1625 fname, atimebuf, mtimebuf);
1628 if (SMBC_parse_path(frame,
1629 context,
1630 fname,
1631 &workgroup,
1632 &server,
1633 &share,
1634 &path,
1635 &user,
1636 &password,
1637 NULL)) {
1638 errno = EINVAL;
1639 TALLOC_FREE(frame);
1640 return -1;
1643 if (!user || user[0] == (char)0) {
1644 user = talloc_strdup(frame, smbc_getUser(context));
1645 if (!user) {
1646 errno = ENOMEM;
1647 TALLOC_FREE(frame);
1648 return -1;
1652 srv = SMBC_server(frame, context, True,
1653 server, share, &workgroup, &user, &password);
1655 if (!srv) {
1656 TALLOC_FREE(frame);
1657 return -1; /* errno set by SMBC_server */
1660 if (!SMBC_setatr(context, srv, path,
1661 0, access_time, write_time, 0, 0)) {
1662 TALLOC_FREE(frame);
1663 return -1; /* errno set by SMBC_setatr */
1666 TALLOC_FREE(frame);
1667 return 0;
1671 * Routine to unlink() a file
1675 SMBC_unlink_ctx(SMBCCTX *context,
1676 const char *fname)
1678 char *server = NULL;
1679 char *share = NULL;
1680 char *user = NULL;
1681 char *password = NULL;
1682 char *workgroup = NULL;
1683 char *path = NULL;
1684 char *targetpath = NULL;
1685 struct cli_state *targetcli = NULL;
1686 SMBCSRV *srv = NULL;
1687 TALLOC_CTX *frame = talloc_stackframe();
1689 if (!context || !context->internal->initialized) {
1691 errno = EINVAL; /* Best I can think of ... */
1692 TALLOC_FREE(frame);
1693 return -1;
1697 if (!fname) {
1698 errno = EINVAL;
1699 TALLOC_FREE(frame);
1700 return -1;
1704 if (SMBC_parse_path(frame,
1705 context,
1706 fname,
1707 &workgroup,
1708 &server,
1709 &share,
1710 &path,
1711 &user,
1712 &password,
1713 NULL)) {
1714 errno = EINVAL;
1715 TALLOC_FREE(frame);
1716 return -1;
1719 if (!user || user[0] == (char)0) {
1720 user = talloc_strdup(frame, smbc_getUser(context));
1721 if (!user) {
1722 errno = ENOMEM;
1723 TALLOC_FREE(frame);
1724 return -1;
1728 srv = SMBC_server(frame, context, True,
1729 server, share, &workgroup, &user, &password);
1731 if (!srv) {
1732 TALLOC_FREE(frame);
1733 return -1; /* SMBC_server sets errno */
1737 /*d_printf(">>>unlink: resolving %s\n", path);*/
1738 if (!cli_resolve_path(frame, "", srv->cli, path,
1739 &targetcli, &targetpath)) {
1740 d_printf("Could not resolve %s\n", path);
1741 TALLOC_FREE(frame);
1742 return -1;
1744 /*d_printf(">>>unlink: resolved path as %s\n", targetpath);*/
1746 if (!cli_unlink(targetcli, targetpath)) {
1748 errno = SMBC_errno(context, targetcli);
1750 if (errno == EACCES) { /* Check if the file is a directory */
1752 int saverr = errno;
1753 SMB_OFF_T size = 0;
1754 uint16 mode = 0;
1755 struct timespec write_time_ts;
1756 struct timespec access_time_ts;
1757 struct timespec change_time_ts;
1758 SMB_INO_T ino = 0;
1760 if (!SMBC_getatr(context, srv, path, &mode, &size,
1761 NULL,
1762 &access_time_ts,
1763 &write_time_ts,
1764 &change_time_ts,
1765 &ino)) {
1767 /* Hmmm, bad error ... What? */
1769 errno = SMBC_errno(context, targetcli);
1770 TALLOC_FREE(frame);
1771 return -1;
1774 else {
1776 if (IS_DOS_DIR(mode))
1777 errno = EISDIR;
1778 else
1779 errno = saverr; /* Restore this */
1784 TALLOC_FREE(frame);
1785 return -1;
1789 TALLOC_FREE(frame);
1790 return 0; /* Success ... */
1795 * Routine to rename() a file
1799 SMBC_rename_ctx(SMBCCTX *ocontext,
1800 const char *oname,
1801 SMBCCTX *ncontext,
1802 const char *nname)
1804 char *server1 = NULL;
1805 char *share1 = NULL;
1806 char *server2 = NULL;
1807 char *share2 = NULL;
1808 char *user1 = NULL;
1809 char *user2 = NULL;
1810 char *password1 = NULL;
1811 char *password2 = NULL;
1812 char *workgroup = NULL;
1813 char *path1 = NULL;
1814 char *path2 = NULL;
1815 char *targetpath1 = NULL;
1816 char *targetpath2 = NULL;
1817 struct cli_state *targetcli1 = NULL;
1818 struct cli_state *targetcli2 = NULL;
1819 SMBCSRV *srv = NULL;
1820 TALLOC_CTX *frame = talloc_stackframe();
1822 if (!ocontext || !ncontext ||
1823 !ocontext->internal->initialized ||
1824 !ncontext->internal->initialized) {
1826 errno = EINVAL; /* Best I can think of ... */
1827 TALLOC_FREE(frame);
1828 return -1;
1831 if (!oname || !nname) {
1832 errno = EINVAL;
1833 TALLOC_FREE(frame);
1834 return -1;
1837 DEBUG(4, ("smbc_rename(%s,%s)\n", oname, nname));
1839 if (SMBC_parse_path(frame,
1840 ocontext,
1841 oname,
1842 &workgroup,
1843 &server1,
1844 &share1,
1845 &path1,
1846 &user1,
1847 &password1,
1848 NULL)) {
1849 errno = EINVAL;
1850 TALLOC_FREE(frame);
1851 return -1;
1854 if (!user1 || user1[0] == (char)0) {
1855 user1 = talloc_strdup(frame, smbc_getUser(ocontext));
1856 if (!user1) {
1857 errno = ENOMEM;
1858 TALLOC_FREE(frame);
1859 return -1;
1863 if (SMBC_parse_path(frame,
1864 ncontext,
1865 nname,
1866 NULL,
1867 &server2,
1868 &share2,
1869 &path2,
1870 &user2,
1871 &password2,
1872 NULL)) {
1873 errno = EINVAL;
1874 TALLOC_FREE(frame);
1875 return -1;
1878 if (!user2 || user2[0] == (char)0) {
1879 user2 = talloc_strdup(frame, smbc_getUser(ncontext));
1880 if (!user2) {
1881 errno = ENOMEM;
1882 TALLOC_FREE(frame);
1883 return -1;
1887 if (strcmp(server1, server2) || strcmp(share1, share2) ||
1888 strcmp(user1, user2)) {
1889 /* Can't rename across file systems, or users?? */
1890 errno = EXDEV;
1891 TALLOC_FREE(frame);
1892 return -1;
1895 srv = SMBC_server(frame, ocontext, True,
1896 server1, share1, &workgroup, &user1, &password1);
1897 if (!srv) {
1898 TALLOC_FREE(frame);
1899 return -1;
1903 /*d_printf(">>>rename: resolving %s\n", path1);*/
1904 if (!cli_resolve_path(frame, "", srv->cli, path1,
1905 &targetcli1, &targetpath1)) {
1906 d_printf("Could not resolve %s\n", path1);
1907 TALLOC_FREE(frame);
1908 return -1;
1910 /*d_printf(">>>rename: resolved path as %s\n", targetpath1);*/
1911 /*d_printf(">>>rename: resolving %s\n", path2);*/
1912 if (!cli_resolve_path(frame, "", srv->cli, path2,
1913 &targetcli2, &targetpath2)) {
1914 d_printf("Could not resolve %s\n", path2);
1915 TALLOC_FREE(frame);
1916 return -1;
1918 /*d_printf(">>>rename: resolved path as %s\n", targetpath2);*/
1920 if (strcmp(targetcli1->desthost, targetcli2->desthost) ||
1921 strcmp(targetcli1->share, targetcli2->share))
1923 /* can't rename across file systems */
1924 errno = EXDEV;
1925 TALLOC_FREE(frame);
1926 return -1;
1929 if (!cli_rename(targetcli1, targetpath1, targetpath2)) {
1930 int eno = SMBC_errno(ocontext, targetcli1);
1932 if (eno != EEXIST ||
1933 !cli_unlink(targetcli1, targetpath2) ||
1934 !cli_rename(targetcli1, targetpath1, targetpath2)) {
1936 errno = eno;
1937 TALLOC_FREE(frame);
1938 return -1;
1943 TALLOC_FREE(frame);
1944 return 0; /* Success */