From 8daa83a594a2e98f39d764422bfbdbc62c9efd44 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 19:20:00 +0200 Subject: Adding upstream version 2:4.20.0+dfsg. Signed-off-by: Daniel Baumann --- source3/utils/net_usershare.c | 1172 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1172 insertions(+) create mode 100644 source3/utils/net_usershare.c (limited to 'source3/utils/net_usershare.c') diff --git a/source3/utils/net_usershare.c b/source3/utils/net_usershare.c new file mode 100644 index 0000000..e5826ee --- /dev/null +++ b/source3/utils/net_usershare.c @@ -0,0 +1,1172 @@ +/* + Samba Unix/Linux SMB client library + Distributed SMB/CIFS Server Management Utility + + Copyright (C) Jeremy Allison (jra@samba.org) 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "system/passwd.h" +#include "system/filesys.h" +#include "utils/net.h" +#include "../libcli/security/security.h" +#include "lib/util/string_wrappers.h" + +struct { + const char *us_errstr; + enum usershare_err us_err; +} us_errs [] = { + {"",USERSHARE_OK}, + {N_("Malformed usershare file"), USERSHARE_MALFORMED_FILE}, + {N_("Bad version number"), USERSHARE_BAD_VERSION}, + {N_("Malformed path entry"), USERSHARE_MALFORMED_PATH}, + {N_("Malformed comment entryfile"), USERSHARE_MALFORMED_COMMENT_DEF}, + {N_("Malformed acl definition"), USERSHARE_MALFORMED_ACL_DEF}, + {N_("Acl parse error"), USERSHARE_ACL_ERR}, + {N_("Path not absolute"), USERSHARE_PATH_NOT_ABSOLUTE}, + {N_("Path is denied"), USERSHARE_PATH_IS_DENIED}, + {N_("Path not allowed"), USERSHARE_PATH_NOT_ALLOWED}, + {N_("Path is not a directory"), USERSHARE_PATH_NOT_DIRECTORY}, + {N_("System error"), USERSHARE_POSIX_ERR}, + {N_("Malformed sharename definition"), USERSHARE_MALFORMED_SHARENAME_DEF}, + {N_("Bad sharename (doesn't match filename)"), USERSHARE_BAD_SHARENAME}, + {NULL,(enum usershare_err)-1} +}; + +static const char *get_us_error_code(enum usershare_err us_err) +{ + char *result; + int idx = 0; + + while (us_errs[idx].us_errstr != NULL) { + if (us_errs[idx].us_err == us_err) { + return us_errs[idx].us_errstr; + } + idx++; + } + + result = talloc_asprintf(talloc_tos(), _("Usershare error code (0x%x)"), + (unsigned int)us_err); + SMB_ASSERT(result != NULL); + return result; +} + +/* The help subsystem for the USERSHARE subcommand */ + +static int net_usershare_add_usage(struct net_context *c, int argc, const char **argv) +{ + char chr = *lp_winbind_separator(); + d_printf(_( + "net usershare add [--long] [] [] []\n" + "\tAdds the specified share name for this user.\n" + "\t is the new share name.\n" + "\t is the path on the filesystem to export.\n" + "\t is the optional comment for the new share.\n" + "\t is an optional share acl in the format \"DOMAIN%cname:X,DOMAIN%cname:X,....\"\n" + "\t if present sets \"guest ok = yes\" on this usershare.\n" + "\t\t\"X\" represents a permission and can be any one of the characters f, r or d\n" + "\t\twhere \"f\" means full control, \"r\" means read-only, \"d\" means deny access.\n" + "\t\tname may be a domain user or group. For local users use the local server name " + "instead of \"DOMAIN\"\n" + "\t\tThe default acl is \"Everyone:r\" which allows everyone read-only access.\n" + "\tAdd --long to print the info on the newly added share.\n"), + chr, chr ); + return -1; +} + +static int net_usershare_delete_usage(struct net_context *c, int argc, const char **argv) +{ + d_printf(_( + "net usershare delete \n" + "\tdeletes the specified share name for this user.\n")); + return -1; +} + +static int net_usershare_info_usage(struct net_context *c, int argc, const char **argv) +{ + d_printf(_( + "net usershare info [--long] [wildcard sharename]\n" + "\tPrints out the path, comment and acl elements of shares that match the wildcard.\n" + "\tBy default only gives info on shares owned by the current user\n" + "\tAdd --long to apply this to all shares\n" + "\tOmit the sharename or use a wildcard of '*' to see all shares\n")); + return -1; +} + +static int net_usershare_list_usage(struct net_context *c, int argc, const char **argv) +{ + d_printf(_( + "net usershare list [--long] [wildcard sharename]\n" + "\tLists the names of all shares that match the wildcard.\n" + "\tBy default only lists shares owned by the current user\n" + "\tAdd --long to apply this to all shares\n" + "\tOmit the sharename or use a wildcard of '*' to see all shares\n")); + return -1; +} + +int net_usershare_usage(struct net_context *c, int argc, const char **argv) +{ + d_printf(_("net usershare add [] [] [] to " + "add or change a user defined share.\n" + "net usershare delete to delete a user defined share.\n" + "net usershare info [--long] [wildcard sharename] to print info about a user defined share.\n" + "net usershare list [--long] [wildcard sharename] to list user defined shares.\n" + "net usershare help\n" + "\nType \"net usershare help