#include <stdlib.h>#include <string.h>#include <errno.h>#include <popt.h>#include "libsmbclient.h"#include "get_auth_data_fn.h"Go to the source code of this file.
Enumerations | |
| enum | acl_mode { SMB_ACL_GET, SMB_ACL_SET, SMB_ACL_DELETE, SMB_ACL_MODIFY, SMB_ACL_ADD, SMB_ACL_CHOWN, SMB_ACL_CHGRP } |
Functions | |
| int | main (int argc, const char *argv[]) |
|
|
Definition at line 8 of file testacl.c. 00009 { 00010 SMB_ACL_GET, 00011 SMB_ACL_SET, 00012 SMB_ACL_DELETE, 00013 SMB_ACL_MODIFY, 00014 SMB_ACL_ADD, 00015 SMB_ACL_CHOWN, 00016 SMB_ACL_CHGRP 00017 };
|
|
||||||||||||
|
Definition at line 20 of file testacl.c. References errno, flags, get_auth_data_fn, mode, numeric, POPT_ARG_INT, POPT_ARG_NONE, POPT_ARG_STRING, POPT_AUTOHELP, poptGetArg(), poptGetContext(), poptGetNextOpt(), poptGetOptArg(), poptPeekArg(), poptPrintUsage(), poptSetOtherOptionHelp(), printf(), SMB_ACL_ADD, SMB_ACL_CHGRP, SMB_ACL_CHOWN, SMB_ACL_DELETE, SMB_ACL_GET, SMB_ACL_MODIFY, SMB_ACL_SET, smbc_getxattr(), smbc_init(), smbc_option_set(), smbc_removexattr(), smbc_set_context(), smbc_setxattr(), SMBC_XATTR_FLAG_CREATE, SMBC_XATTR_FLAG_REPLACE, snprintf, strcpy, strdup, and strerror. 00021 { 00022 int opt; 00023 int flags; 00024 int debug = 0; 00025 int numeric = 0; 00026 int full_time_names = 0; 00027 enum acl_mode mode = SMB_ACL_GET; 00028 static char *the_acl = NULL; 00029 int ret; 00030 char *p; 00031 char *debugstr; 00032 char path[1024]; 00033 char value[1024]; 00034 poptContext pc; 00035 struct poptOption long_options[] = 00036 { 00037 POPT_AUTOHELP 00038 { 00039 "numeric", 'n', POPT_ARG_NONE, &numeric, 00040 1, "Don't resolve sids or masks to names" 00041 }, 00042 { 00043 "debug", 'd', POPT_ARG_INT, &debug, 00044 0, "Set debug level (0-100)" 00045 }, 00046 { 00047 "full_time_names", 'f', POPT_ARG_NONE, &full_time_names, 00048 1, 00049 "Use new style xattr names, which include CREATE_TIME" 00050 }, 00051 { 00052 "delete", 'D', POPT_ARG_STRING, NULL, 00053 'D', "Delete an acl", "ACL" 00054 }, 00055 { 00056 "modify", 'M', POPT_ARG_STRING, NULL, 00057 'M', "Modify an acl", "ACL" 00058 }, 00059 { 00060 "add", 'a', POPT_ARG_STRING, NULL, 00061 'a', "Add an acl", "ACL" 00062 }, 00063 { 00064 "set", 'S', POPT_ARG_STRING, NULL, 00065 'S', "Set acls", "ACLS" 00066 }, 00067 { 00068 "chown", 'C', POPT_ARG_STRING, NULL, 00069 'C', "Change ownership of a file", "USERNAME" 00070 }, 00071 { 00072 "chgrp", 'G', POPT_ARG_STRING, NULL, 00073 'G', "Change group ownership of a file", "GROUPNAME" 00074 }, 00075 { 00076 "get", 'g', POPT_ARG_STRING, NULL, 00077 'g', "Get a specific acl attribute", "ACL" 00078 }, 00079 { 00080 NULL 00081 } 00082 }; 00083 00084 setbuf(stdout, NULL); 00085 00086 pc = poptGetContext("smbcacls", argc, argv, long_options, 0); 00087 00088 poptSetOtherOptionHelp(pc, "smb://server1/share1/filename"); 00089 00090 while ((opt = poptGetNextOpt(pc)) != -1) { 00091 switch (opt) { 00092 case 'S': 00093 the_acl = strdup(poptGetOptArg(pc)); 00094 mode = SMB_ACL_SET; 00095 break; 00096 00097 case 'D': 00098 the_acl = strdup(poptGetOptArg(pc)); 00099 mode = SMB_ACL_DELETE; 00100 break; 00101 00102 case 'M': 00103 the_acl = strdup(poptGetOptArg(pc)); 00104 mode = SMB_ACL_MODIFY; 00105 break; 00106 00107 case 'a': 00108 the_acl = strdup(poptGetOptArg(pc)); 00109 mode = SMB_ACL_ADD; 00110 break; 00111 00112 case 'g': 00113 the_acl = strdup(poptGetOptArg(pc)); 00114 mode = SMB_ACL_GET; 00115 break; 00116 00117 case 'C': 00118 the_acl = strdup(poptGetOptArg(pc)); 00119 mode = SMB_ACL_CHOWN; 00120 break; 00121 00122 case 'G': 00123 the_acl = strdup(poptGetOptArg(pc)); 00124 mode = SMB_ACL_CHGRP; 00125 break; 00126 } 00127 } 00128 00129 /* Make connection to server */ 00130 if(!poptPeekArg(pc)) { 00131 poptPrintUsage(pc, stderr, 0); 00132 return 1; 00133 } 00134 00135 strcpy(path, poptGetArg(pc)); 00136 00137 if (smbc_init(get_auth_data_fn, debug) != 0) 00138 { 00139 printf("Could not initialize smbc_ library\n"); 00140 return 1; 00141 } 00142 00143 if (full_time_names) { 00144 SMBCCTX *context = smbc_set_context(NULL); 00145 smbc_option_set(context, "full_time_names", 1); 00146 } 00147 00148 /* Perform requested action */ 00149 00150 switch(mode) 00151 { 00152 case SMB_ACL_GET: 00153 if (the_acl == NULL) 00154 { 00155 if (numeric) 00156 { 00157 the_acl = "system.*"; 00158 } 00159 else 00160 { 00161 the_acl = "system.*+"; 00162 } 00163 } 00164 ret = smbc_getxattr(path, the_acl, value, sizeof(value)); 00165 if (ret < 0) 00166 { 00167 printf("Could not get attributes for [%s] %d: %s\n", 00168 path, errno, strerror(errno)); 00169 return 1; 00170 } 00171 00172 printf("Attributes for [%s] are:\n%s\n", path, value); 00173 break; 00174 00175 case SMB_ACL_ADD: 00176 flags = SMBC_XATTR_FLAG_CREATE; 00177 debugstr = "add attributes"; 00178 goto do_set; 00179 00180 case SMB_ACL_MODIFY: 00181 flags = SMBC_XATTR_FLAG_REPLACE; 00182 debugstr = "modify attributes"; 00183 goto do_set; 00184 00185 case SMB_ACL_CHOWN: 00186 snprintf(value, sizeof(value), 00187 "system.nt_sec_desc.owner%s:%s", 00188 numeric ? "" : "+", the_acl); 00189 the_acl = value; 00190 debugstr = "chown owner"; 00191 goto do_set; 00192 00193 case SMB_ACL_CHGRP: 00194 snprintf(value, sizeof(value), 00195 "system.nt_sec_desc.group%s:%s", 00196 numeric ? "" : "+", the_acl); 00197 the_acl = value; 00198 debugstr = "change group"; 00199 goto do_set; 00200 00201 case SMB_ACL_SET: 00202 flags = 0; 00203 debugstr = "set attributes"; 00204 00205 do_set: 00206 if ((p = strchr(the_acl, ':')) == NULL) 00207 { 00208 printf("Missing value. ACL must be name:value pair\n"); 00209 return 1; 00210 } 00211 00212 *p++ = '\0'; 00213 00214 ret = smbc_setxattr(path, the_acl, p, strlen(p), flags); 00215 if (ret < 0) 00216 { 00217 printf("Could not %s for [%s] %d: %s\n", 00218 debugstr, path, errno, strerror(errno)); 00219 return 1; 00220 } 00221 break; 00222 00223 case SMB_ACL_DELETE: 00224 ret = smbc_removexattr(path, the_acl); 00225 if (ret < 0) 00226 { 00227 printf("Could not remove attribute %s for [%s] %d:%s\n", 00228 the_acl, path, errno, strerror(errno)); 00229 return 1; 00230 } 00231 break; 00232 00233 default: 00234 printf("operation not yet implemented\n"); 00235 break; 00236 } 00237 00238 return 0; 00239 }
|