static gboolean modify_share (const char *old_path, ShareInfo *info, GError **error) { ShareInfo *old_info; /* g_message ("modify_share() start"); */ old_info = lookup_share_by_path (old_path); if (old_info == NULL) { /*g_message ("modify_share() end; calling add_share() instead");*/ return add_share (info, error); } g_assert (old_info != NULL); if (strcmp (info->path, old_info->path) != 0) { g_set_error (error, SHARES_ERROR, SHARES_ERROR_FAILED, _("Cannot change the path of an existing share; please remove the old share first and add a new one")); g_message ("modify_share() end FAIL: tried to change the path in a share!"); return FALSE; } if (throw_error_on_modify) { g_set_error (error, SHARES_ERROR, SHARES_ERROR_FAILED, "Failed"); g_message ("modify_share() end FAIL"); return FALSE; } /* Although "net usershare add" will modify an existing share if it has the same share name * as the one that gets passed in, our semantics are different. We have a one-to-one mapping * between paths and share names; "net usershare" supports a one-to-many mapping from paths * to share names. So, we must first remove the old share and then add the new/modified one. */ if (!remove_share (old_path, error)) { g_message ("modify_share() end FAIL: error when removing old share"); return FALSE; } /* g_message ("modify_share() end: will call add_share() with the new share info"); */ return add_share (info, error); }
/** * shares_modify_share: * @old_path: Path of the share to modify, or %NULL. * @info: Info of the share to modify/add, or %NULL to delete a share. * @error: Location to store error, or #NULL. * * Can add, modify, or delete shares. To add a share, pass %NULL for @old_path, * and a non-null @info. To modify a share, pass a non-null @old_path and * non-null @info; in this case, @info->path must have the same contents as * @old_path. To remove a share, pass a non-NULL @old_path and a %NULL @info. * * Return value: TRUE if the share could be modified, FALSE otherwise. If this returns * FALSE, then the error information will be placed in @error. **/ gboolean shares_modify_share (const char *old_path, ShareInfo *info, GError **error) { g_assert ((old_path == NULL && info != NULL) || (old_path != NULL && info == NULL) || (old_path != NULL && info != NULL)); g_assert (error == NULL || *error == NULL); if (!refresh_if_needed (error)) return FALSE; if (old_path == NULL) return add_share (info, error); else if (info == NULL) return remove_share (old_path, error); else return modify_share (old_path, info, error); }
// main int main(int argc, char** argv) { BApplication app("application/x-vnd.antares-netfs_server_prefs"); // parse first argument int argi = 1; const char* arg = next_arg(argc, argv, argi); if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) print_usage_and_exit(false); if (strcmp(arg, "launch") == 0) { // launch no_more_args(argc, argi); launch_server(); } else if (strcmp(arg, "terminate") == 0) { // terminate no_more_args(argc, argi); terminate_server(); } else if (strcmp(arg, "save") == 0) { // save no_more_args(argc, argi); save_server_setttings(); } else if (strcmp(arg, "l") == 0 || strcmp(arg, "list") == 0) { // list no_more_args(argc, argi); list(); } else if (strcmp(arg, "add") == 0) { // add arg = next_arg(argc, argv, argi); if (strcmp(arg, "share") == 0) { // share const char* name = next_arg(argc, argv, argi); const char* path = next_arg(argc, argv, argi); no_more_args(argc, argi); add_share(name, path); } else if (strcmp(arg, "user") == 0) { // user const char* name = next_arg(argc, argv, argi); const char* password = next_arg(argc, argv, argi, true); no_more_args(argc, argi); add_user(name, password); } else print_usage_and_exit(true); } else if (strcmp(arg, "remove") == 0) { // remove arg = next_arg(argc, argv, argi); if (strcmp(arg, "share") == 0) { // share const char* name = next_arg(argc, argv, argi); no_more_args(argc, argi); remove_share(name); } else if (strcmp(arg, "user") == 0) { // user const char* name = next_arg(argc, argv, argi); no_more_args(argc, argi); remove_user(name); } else print_usage_and_exit(true); } else if (strcmp(arg, "permissions") == 0) { // permissions const char* user = next_arg(argc, argv, argi); const char* share = next_arg(argc, argv, argi); uint32 permissions = 0; while (argi < argc) { uint32 perms = 0; arg = next_arg(argc, argv, argi); if (!get_permissions(arg, &perms)) print_usage_and_exit(true); permissions |= perms; } set_user_permissions(user, share, permissions); } else { print_usage_and_exit(true); } return 0; }