diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h index 3b909d1..38c6d4b 100644 --- a/source3/include/libsmb_internal.h +++ b/source3/include/libsmb_internal.h @@ -151,6 +151,14 @@ struct SMBC_internal_data { bool full_time_names; /* + * Enable POSIX extensions before opening files/directories + * Will silently ignore if the server does not support the POSIX + * extensions + */ + + bool posix_extensions; + + /* * The share mode of a file being opened. To match POSIX semantics * (and maintain backward compatibility), DENY_NONE is the default. */ diff --git a/source3/include/libsmbclient.h b/source3/include/libsmbclient.h index a8b27b7..59fee70 100644 --- a/source3/include/libsmbclient.h +++ b/source3/include/libsmbclient.h @@ -694,7 +694,13 @@ smbc_getOptionNoAutoAnonymousLogin(SMBCCTX *c); void smbc_setOptionNoAutoAnonymousLogin(SMBCCTX *c, smbc_bool b); +/** Get whether to enable POSIX extensions if available */ +smbc_bool +smbc_getOptionPosixExtensions(SMBCCTX *c); +/** Set whether to enable POSIX extensions if available */ +void +smbc_setOptionPosixExtensions(SMBCCTX *c, smbc_bool b); /************************************* * Getters and setters for FUNCTIONS * diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c index 1984338..3bb7e36 100644 --- a/source3/libsmb/libsmb_context.c +++ b/source3/libsmb/libsmb_context.c @@ -72,6 +72,7 @@ smbc_new_context(void) smbc_setOptionBrowseMaxLmbCount(context, 3); /* # LMBs to query */ smbc_setOptionUrlEncodeReaddirEntries(context, False); smbc_setOptionOneSharePerServer(context, False); + smbc_setOptionPosixExtensions(context, True); smbc_setFunctionAuthData(context, SMBC_get_auth_data); smbc_setFunctionCheckServer(context, SMBC_check_server); diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c index aa313f2..f2f0244 100644 --- a/source3/libsmb/libsmb_dir.c +++ b/source3/libsmb/libsmb_dir.c @@ -760,7 +760,8 @@ SMBC_opendir_ctx(SMBCCTX *context, /* Now, list the files ... */ p = path + strlen(path); - path = talloc_asprintf_append(path, "\\*"); + if (!context->internal->posix_extensions) + path = talloc_asprintf_append(path, "\\*"); if (!path) { if (dir) { SAFE_FREE(dir->fname); @@ -769,7 +770,7 @@ SMBC_opendir_ctx(SMBCCTX *context, TALLOC_FREE(frame); return NULL; } - + d_printf("path %s\n",path); if (!cli_resolve_path(frame, "", srv->cli, path, &targetcli, &targetpath)) { d_printf("Could not resolve %s\n", path); @@ -780,6 +781,7 @@ SMBC_opendir_ctx(SMBCCTX *context, TALLOC_FREE(frame); return NULL; } + d_printf("targetpath %s\n",targetpath); if (cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN, diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c index ece056d..d748f37 100644 --- a/source3/libsmb/libsmb_file.c +++ b/source3/libsmb/libsmb_file.c @@ -123,7 +123,8 @@ SMBC_open_ctx(SMBCCTX *context, return NULL; } /*d_printf(">>>open: resolved %s as %s\n", path, targetpath);*/ - + + if ((fd = cli_open(targetcli, targetpath, flags, context->internal->share_mode)) < 0) { @@ -539,7 +540,7 @@ SMBC_getatr(SMBCCTX * context, trim_string(fixedpath, NULL, "\\.."); trim_string(fixedpath, NULL, "\\."); } - DEBUG(4,("SMBC_getatr: sending qpathinfo\n")); + DEBUG(4,("SMBC_getatr: sending qpathinfo for %s (%s)\n",fixedpath,path)); if (!cli_resolve_path(frame, "", srv->cli, fixedpath, &targetcli, &targetpath)) { diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c index aeec255..a83cfe3 100644 --- a/source3/libsmb/libsmb_server.c +++ b/source3/libsmb/libsmb_server.c @@ -216,6 +216,98 @@ check_server_cache: return NULL; } +static smbc_bool +SMBC_enable_posix(SMBCCTX *smbctx, TALLOC_CTX *ctx, struct cli_state *cli) +{ + uint16 major, minor; + uint32 caplow, caphigh; + char *caps; + + if (!SERVER_HAS_UNIX_CIFS(cli)) { + d_printf("Server doesn't support UNIX CIFS extensions.\n"); + return 1; + } + + if (!cli_unix_extensions_version(cli, &major, &minor, &caplow, &caphigh)) { + d_printf("Can't get UNIX CIFS extensions version from server.\n"); + return 1; + } + + //d_printf("Server supports CIFS extensions %u.%u\n", (unsigned int)major, (unsigned int)minor); + + caps = talloc_strdup(ctx, ""); + if (!caps) { + return 1; + } + if (caplow & CIFS_UNIX_FCNTL_LOCKS_CAP) { + caps = talloc_asprintf_append(caps, "locks "); + if (!caps) { + return 1; + } + } + if (caplow & CIFS_UNIX_POSIX_ACLS_CAP) { + caps = talloc_asprintf_append(caps, "acls "); + if (!caps) { + return 1; + } + } + if (caplow & CIFS_UNIX_XATTTR_CAP) { + caps = talloc_asprintf_append(caps, "eas "); + if (!caps) { + return 1; + } + } + if (caplow & CIFS_UNIX_POSIX_PATHNAMES_CAP) { + caps = talloc_asprintf_append(caps, "pathnames "); + if (!caps) { + return 1; + } + } + if (caplow & CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP) { + caps = talloc_asprintf_append(caps, "posix_path_operations "); + if (!caps) { + return 1; + } + } + if (caplow & CIFS_UNIX_LARGE_READ_CAP) { + caps = talloc_asprintf_append(caps, "large_read "); + if (!caps) { + return 1; + } + } + if (caplow & CIFS_UNIX_LARGE_WRITE_CAP) { + caps = talloc_asprintf_append(caps, "large_write "); + if (!caps) { + return 1; + } + } + if (caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP) { + caps = talloc_asprintf_append(caps, "posix_encrypt "); + if (!caps) { + return 1; + } + } + if (caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP) { + caps = talloc_asprintf_append(caps, "mandatory_posix_encrypt "); + if (!caps) { + return 1; + } + } + + if (*caps && caps[strlen(caps)-1] == ' ') { + caps[strlen(caps)-1] = '\0'; + } + + //d_printf("Server supports CIFS capabilities %s\n", caps); + + if (!cli_set_unix_extensions_capabilities(cli, major, minor, caplow, caphigh)) { + d_printf("Can't set UNIX CIFS extensions capabilities. %s.\n", cli_errstr(cli)); + return 1; + } + + return 0; +} + /* * Connect to a server, possibly on an existing connection * @@ -364,7 +456,7 @@ again: c->fallback_after_kerberos = True; } - c->timeout = smbc_getTimeout(context); + c->timeout = smbc_getTimeout(context); /* * Force use of port 139 for first try if share is $IPC, empty, or @@ -534,6 +626,9 @@ again: DEBUG(2, ("Server connect ok: //%s/%s: %p\n", server, share, srv)); + + if (context->internal->posix_extensions) + SMBC_enable_posix(context, ctx, srv->cli); DLIST_ADD(context->internal->servers, srv); return srv; diff --git a/source3/libsmb/libsmb_setget.c b/source3/libsmb/libsmb_setget.c index d0823bd..c9a6bd5 100644 --- a/source3/libsmb/libsmb_setget.c +++ b/source3/libsmb/libsmb_setget.c @@ -385,6 +385,20 @@ smbc_setOptionNoAutoAnonymousLogin(SMBCCTX *c, smbc_bool b) } } +/** Get whether to enable POSIX extensions if available */ +smbc_bool +smbc_getOptionPosixExtensions(SMBCCTX *c) +{ + return c->internal->posix_extensions; +} + +/** Set whether to enable POSIX extensions if available */ +void +smbc_setOptionPosixExtensions(SMBCCTX *c, smbc_bool b) +{ + c->internal->posix_extensions = b; +} + /** Get the function for obtaining authentication data */ smbc_get_auth_data_fn smbc_getFunctionAuthData(SMBCCTX *c) diff --git a/source3/libsmb/libsmb_stat.c b/source3/libsmb/libsmb_stat.c index 27546f6..3a4e387 100644 --- a/source3/libsmb/libsmb_stat.c +++ b/source3/libsmb/libsmb_stat.c @@ -153,9 +153,12 @@ SMBC_stat_ctx(SMBCCTX *context, NULL)) { errno = EINVAL; TALLOC_FREE(frame); + d_printf("path parse failure for '%s'!\n",fname); return -1; } - + DEBUG(4, ("parsed path: fname='%s' server='%s' share='%s' " + "path='%s'\n", + fname, server, share, path)); if (!user || user[0] == (char)0) { user = talloc_strdup(frame, smbc_getUser(context)); if (!user) {