File indexing completed on 2023-09-24 04:08:38
0001 /* 0002 SPDX-FileCopyrightText: 2010 Rodrigo Belem <rclbelem@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef ksambasharedata_h 0008 #define ksambasharedata_h 0009 0010 #include "kiocore_export.h" 0011 #include <QExplicitlySharedDataPointer> 0012 0013 class QString; 0014 class KSambaShare; 0015 class KSambaSharePrivate; 0016 class KSambaShareDataPrivate; 0017 0018 /** 0019 * @class KSambaShareData ksambasharedata.h <KSambaShareData> 0020 * 0021 * This class represents a Samba user share. It is possible to share a directory with one or more 0022 * different names, update the share details or remove. 0023 * 0024 * @author Rodrigo Belem <rclbelem@gmail.com> 0025 * @since 4.7 0026 */ 0027 class KIOCORE_EXPORT KSambaShareData 0028 { 0029 public: 0030 enum GuestPermission { 0031 GuestsNotAllowed, 0032 GuestsAllowed, 0033 }; 0034 0035 enum UserShareError { 0036 UserShareOk, 0037 UserShareExceedMaxShares, 0038 UserShareNameOk, 0039 UserShareNameInvalid, 0040 UserShareNameInUse, 0041 UserSharePathOk, 0042 UserSharePathInvalid, 0043 UserSharePathNotExists, 0044 UserSharePathNotDirectory, 0045 UserSharePathNotAbsolute, 0046 UserSharePathNotAllowed, 0047 UserShareAclOk, 0048 UserShareAclInvalid, 0049 UserShareAclUserNotValid, 0050 UserShareCommentOk, 0051 UserShareGuestsOk, 0052 UserShareGuestsInvalid, 0053 UserShareGuestsNotAllowed, 0054 UserShareSystemError, /* < A system error occurred; check KSambaShare::lastSystemErrorString */ 0055 }; 0056 0057 KSambaShareData(); 0058 KSambaShareData(const KSambaShareData &other); 0059 0060 ~KSambaShareData(); 0061 0062 /** 0063 * @return @c the share name. 0064 */ 0065 QString name() const; 0066 0067 /** 0068 * @return @c the share path. 0069 */ 0070 QString path() const; 0071 0072 /** 0073 * @return @c the share comment. 0074 */ 0075 QString comment() const; 0076 0077 /** 0078 * Returns a @c containing a string describing the permission added to the users, such as 0079 * "[DOMAIN\]username1:X,[DOMAIN\]username2:X,...". X stands for "F" (full control), "R" 0080 * (read-only) and "D" (deny). By default the acl is Everyone:R. 0081 * 0082 * @return @c the share acl. 0083 */ 0084 QString acl() const; 0085 0086 /** 0087 * @return @c whether guest access to the share is allowed or not. 0088 */ 0089 KSambaShareData::GuestPermission guestPermission() const; 0090 0091 /** 0092 * Sets the share name. If the share name is changed and valid it will remove the existing 0093 * share and will create a new share. 0094 * The share name cannot use a name of a system user or containing the forbidden characters 0095 * '%, <, >, *, ?, |, /, \, +, =, ;, :, ",,. To check if the name is available or valid use 0096 * the method KSambaShare::isShareNameAvailable(). 0097 * 0098 * @param name the name that will be given to the share. 0099 * 0100 * @return @c UserShareNameOk if the name is valid. 0101 * @return @c UserShareNameInvalid if the name contains invalid characters. 0102 * @return @c UserShareNameInUse if the name is already in use by another shared folder or a 0103 * by a system user. 0104 */ 0105 KSambaShareData::UserShareError setName(const QString &name); 0106 0107 /** 0108 * Set the path for the share. 0109 * 0110 * @param path the path that will be given to the share. 0111 * 0112 * @return @c UserSharePathOk if valid. 0113 * @return @c UserSharePathInvalid if the path is in invalid format. 0114 * @return @c UserSharePathNotExists if the path does not exists. 0115 * @return @c UserSharePathNotDirectory if the path points to file instead of a directory. 0116 * @return @c UserSharePathNotAbsolute if the path is not is absolute form. 0117 * @return @c UserSharePathNotAllowed if the path is not owner by the user. 0118 */ 0119 KSambaShareData::UserShareError setPath(const QString &path); 0120 0121 /** 0122 * Sets the comment for the share. 0123 * 0124 * @param comment the comment that will be given to the share. 0125 * 0126 * @return @c UserShareCommentOk always. 0127 */ 0128 KSambaShareData::UserShareError setComment(const QString &comment); 0129 0130 /** 0131 * Sets the acl to the share. 0132 * 0133 * @param acl the acl that will be given to the share. 0134 * 0135 * @return @c UserShareAclOk if the acl is valid. 0136 * @return @c UserShareAclInvalid if the acl has invalid format. 0137 * @return @c UserShareAclUserNotValid if one of the users in the acl is invalid. 0138 */ 0139 KSambaShareData::UserShareError setAcl(const QString &acl); 0140 0141 /** 0142 * Flags if guest is allowed or not to access the share. 0143 * 0144 * @param permission the permission that will be given to the share. 0145 * 0146 * @return @c UserShareGuestsOk if the permission was set. 0147 * @return @c UserShareGuestsNotAllowed if the system does not allow guest access to the 0148 * shares. 0149 */ 0150 KSambaShareData::UserShareError setGuestPermission(const GuestPermission &permission = KSambaShareData::GuestsNotAllowed); 0151 0152 /** 0153 * Share the folder with the information that has been set. 0154 * 0155 * @return @c UserShareOk if the share was added or other errors as applicable. Also see UserShareSystemError. 0156 */ 0157 KSambaShareData::UserShareError save(); 0158 0159 /** 0160 * Unshare the folder held by the object. 0161 * 0162 * @return @c UserShareOk if the share was removed or other errors as applicable. Also see UserShareSystemError. 0163 */ 0164 KSambaShareData::UserShareError remove(); 0165 0166 KSambaShareData &operator=(const KSambaShareData &other); 0167 bool operator==(const KSambaShareData &other) const; 0168 bool operator!=(const KSambaShareData &other) const; 0169 0170 private: 0171 QExplicitlySharedDataPointer<KSambaShareDataPrivate> dd; 0172 0173 friend class KSambaSharePrivate; 0174 }; 0175 0176 #endif