/** * Tries to find a match for hostname in the certificate's Subject Alternative Name extension. * * Returns MatchFound if a match was found. * Returns MatchNotFound if no matches were found. * Returns MalformedCertificate if any of the hostnames had a NUL character embedded in it. * Returns NoSANPresent if the SAN extension was not present in the certificate. */ static HostnameValidationResult matches_subject_alternative_name(const char *hostname, const X509 *server_cert) { HostnameValidationResult result = MatchNotFound; int i; int san_names_nb = -1; STACK_OF(GENERAL_NAME) *san_names = NULL; // Try to extract the names within the SAN extension from the certificate san_names = X509_get_ext_d2i((X509 *) server_cert, NID_subject_alt_name, NULL, NULL); if (san_names == NULL) { return NoSANPresent; } san_names_nb = sk_GENERAL_NAME_num(san_names); // Check each name within the extension for (i=0; i<san_names_nb; i++) { const GENERAL_NAME *current_name = sk_GENERAL_NAME_value(san_names, i); if (current_name->type == GEN_DNS) { // Current name is a DNS name, let's check it result = validate_name(hostname, current_name->d.dNSName); if (result != MatchNotFound) { break; } } } sk_GENERAL_NAME_pop_free(san_names, GENERAL_NAME_free); return result; }
int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv) { const char *vg_name = NULL; if (argc == 1) { vg_name = skip_dev_dir(cmd, argv[0], NULL); if (!validate_name(vg_name)) { log_error("Volume group name \"%s\" is invalid", vg_name); return ECMD_FAILED; } } else if (!(arg_count(cmd, list_ARG) && arg_count(cmd, file_ARG))) { log_error("Please specify a *single* volume group to restore."); return ECMD_FAILED; } /* * FIXME: overloading the -l arg for now to display a * list of archive files for a particular vg */ if (arg_count(cmd, list_ARG)) { if (!(arg_count(cmd,file_ARG) ? archive_display_file(cmd, arg_str_value(cmd, file_ARG, "")) : archive_display(cmd, vg_name))) { stack; return ECMD_FAILED; } return ECMD_PROCESSED; } if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) { log_error("Unable to lock volume group %s", vg_name); return ECMD_FAILED; } if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) { log_error("Unable to lock orphans"); unlock_vg(cmd, vg_name); return ECMD_FAILED; } cmd->handles_unknown_segments = 1; if (!(arg_count(cmd, file_ARG) ? backup_restore_from_file(cmd, vg_name, arg_str_value(cmd, file_ARG, "")) : backup_restore(cmd, vg_name))) { unlock_vg(cmd, VG_ORPHANS); unlock_vg(cmd, vg_name); log_error("Restore failed."); return ECMD_FAILED; } log_print("Restored volume group %s", vg_name); unlock_vg(cmd, VG_ORPHANS); unlock_vg(cmd, vg_name); return ECMD_PROCESSED; }
//------------------------------------------------------------------------- PyObject *py_validate_name(const char *name, nametype_t type, int flags=0) { qstring qname(name); if ( validate_name(&qname, type, flags) ) return PyString_FromStringAndSize(qname.c_str(), qname.length()); else Py_RETURN_NONE; }
static inline void validate_name ( wrapper_type const& array ) { CharDecoderT<UnitT> decoder(array); return validate_name(decoder); }
void DynExceptImpl::_read(TIDorb::portable::InputStream& in) { DynStructImpl::_read(in); if (!validate_name()) { throw CORBA::MARSHAL("Unexpected exception id in any"); } }
/* vg.remove(string group, string name) */ xmlrpc_value *m_vg_remove(xmlrpc_env *env, xmlrpc_value *p, void *c) { LOG_TRACEME xmlrpc_value *params; char *group, *name; int rc, gid = 0; xid_t xid; params = method_init(env, p, c, VCD_CAP_AUTH, 0); method_return_if_fault(env); xmlrpc_decompose_value(env, params, "{s:s,s:s,*}", "group", &group, "name", &name); method_return_if_fault(env); if (!validate_group(group)) method_return_faultf(env, MEINVAL, "invalid group value: %s", group); if (str_equal(group, "all")) method_return_faultf(env, MEINVAL, "cannot remove reserved group '%s'", group); if (!(gid = vxdb_getgid(group))) method_return_fault(env, MENOVG); if (!str_isempty(name)) { if (!validate_name(name)) method_return_faultf(env, MEINVAL, "invalid name value: %s", name); if (!(xid = vxdb_getxid(name))) method_return_fault(env, MENOVPS); rc = vxdb_exec( "DELETE FROM xid_gid_map WHERE xid = %d AND gid = %d", xid, gid); } else { rc = vxdb_exec( "BEGIN EXCLUSIVE TRANSACTION;" "DELETE FROM xid_gid_map WHERE gid = %d;" "DELETE FROM groups WHERE gid = %d;" "COMMIT TRANSACTION;", gid, gid); } if (rc != VXDB_OK) method_return_vxdb_fault(env); return xmlrpc_nil_new(env); }
GstEncodingTarget * gst_encoding_target_new (const gchar * name, const gchar * category, const gchar * description, const GList * profiles) { GstEncodingTarget *res; g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (category != NULL, NULL); g_return_val_if_fail (description != NULL, NULL); /* Validate name */ if (!validate_name (name)) goto invalid_name; if (category && !validate_name (category)) goto invalid_category; res = (GstEncodingTarget *) g_object_new (GST_TYPE_ENCODING_TARGET, NULL); res->name = g_strdup (name); res->category = g_strdup (category); res->description = g_strdup (description); while (profiles) { GstEncodingProfile *prof = (GstEncodingProfile *) profiles->data; res->profiles = g_list_append (res->profiles, gst_encoding_profile_ref (prof)); profiles = profiles->next; } return res; invalid_name: { GST_ERROR ("Invalid name for encoding target : '%s'", name); return NULL; } invalid_category: { GST_ERROR ("Invalid name for encoding category : '%s'", category); return NULL; } }
void DynExceptImpl::from_any(const CORBA::Any& value) throw(DynamicAny::DynAny::TypeMismatch, DynamicAny::DynAny::InvalidValue,CORBA::SystemException) { DynStructImpl::from_any(value); if (!validate_name()) { throw CORBA::MARSHAL("Unexpected exception id in any"); } }
explicit variable(boost::iterator_range<Iterator> const& token) : _position(token.begin().position()) { // Remove the $ from the name auto it = token.begin(); ++it; _name.assign(it, token.end()); validate_name(); }
//int tag_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a) int tag_arg(struct cmd_context *cmd, struct arg *a) { char *pos = a->value; if (*pos == '@') pos++; if (!validate_name(pos)) return 0; return 1; }
DynExceptImpl::DynExceptImpl(DynamicAny::DynAnyFactory_ptr factory, TIDorb::core::TIDORB* orb, const CORBA::Any& any, CORBA::TypeCode_ptr real_type) throw(CORBA::SystemException) : DynStructImpl(factory, orb, any, real_type) { if (! validate_name()) { throw CORBA::MARSHAL("Unexpected exception id in any"); } }
/*! * \brief Calls the appropriate functions to validate a counter metric. * * \param statistic_name The statistic name to be sent to StatsD. * \param value The value to be sent to StatsD. * * This function calls other validating functions to correctly validate each * input based on allowable input for a counter metric. * * \retval zero on success. * \retval 1 on error. */ static int validate_metric_type_counter(const char *statistic_name, const char *value) { if (ast_strlen_zero(value)) { ast_log(AST_LOG_ERROR, "Missing value argument.\n"); return 1; } if (validate_name(statistic_name) || determine_actual_value(value) || value_in_range(value)) { return 1; } return 0; }
/*! * \brief Calls the appropriate functions to validate a timer metric. * * \param statistic_name The statistic name to be sent to StatsD. * \param value The value to be sent to StatsD. * * This function calls other validating functions to correctly validate each * input based on allowable input for a timer metric. * * \retval zero on success. * \retval 1 on error. */ static int validate_metric_type_timer(const char *statistic_name, const char *value) { if (ast_strlen_zero(value)) { ast_log(AST_LOG_ERROR, "Missing value argument.\n"); return 1; } if (validate_name(statistic_name) || validate_numeric(value) || non_neg_value_range(value)) { return 1; } return 0; }
static void create_object(confdb_handle_t handle, char * name_pt) { char * obj_name_pt; char * save_pt; hdb_handle_t obj_handle; hdb_handle_t parent_object_handle = OBJECT_PARENT_HANDLE; char tmp_name[OBJ_NAME_SIZE]; cs_error_t res; strncpy (tmp_name, name_pt, sizeof (tmp_name)); tmp_name[sizeof (tmp_name) - 1] = '\0'; obj_name_pt = strtok_r(tmp_name, SEPERATOR_STR, &save_pt); while (obj_name_pt != NULL) { res = confdb_object_find_start(handle, parent_object_handle); if (res != CS_OK) { fprintf (stderr, "Could not start object_find %d\n", res); exit (EXIT_FAILURE); } res = confdb_object_find(handle, parent_object_handle, obj_name_pt, strlen (obj_name_pt), &obj_handle); if (res != CS_OK) { if (validate_name(obj_name_pt) != CS_OK) { fprintf(stderr, "Incorrect object name \"%s\", \"=\" not allowed.\n", obj_name_pt); exit(EXIT_FAILURE); } if (debug) printf ("%s:%d: %s\n", __func__,__LINE__, obj_name_pt); res = confdb_object_create (handle, parent_object_handle, obj_name_pt, strlen (obj_name_pt), &obj_handle); if (res != CS_OK) fprintf(stderr, "Failed to create object \"%s\". Error %d.\n", obj_name_pt, res); } parent_object_handle = obj_handle; obj_name_pt = strtok_r (NULL, SEPERATOR_STR, &save_pt); } }
/*! * \brief Calls the appropriate functions to validate a set metric. * * \param statistic_name The statistic name to be sent to StatsD. * \param value The value to be sent to StatsD. * * This function calls other validating functions to correctly validate each * input based on allowable input for a set metric. * * \retval zero on success. * \retval 1 on error. */ static int validate_metric_type_set(const char *statistic_name, const char *value) { if (ast_strlen_zero(value)) { ast_log(AST_LOG_ERROR, "Missing value argument.\n"); return 1; } if (validate_name(statistic_name)) { return 1; } if (strstr(value, "|") != NULL) { ast_log(AST_LOG_ERROR, "Pipe (|) character is not allowed for value %s" " in a set metric.\n", value); return 1; } return 0; }
/** * Tries to find a match for hostname in the certificate's Common Name field. * * Returns MatchFound if a match was found. * Returns MatchNotFound if no matches were found. * Returns MalformedCertificate if the Common Name had a NUL character embedded in it. * Returns Error if the Common Name could not be extracted. */ static HostnameValidationResult matches_common_name(const char *hostname, const X509 *server_cert) { int common_name_loc = -1; X509_NAME_ENTRY *common_name_entry = NULL; ASN1_STRING *common_name_asn1 = NULL; // Find the position of the CN field in the Subject field of the certificate common_name_loc = X509_NAME_get_index_by_NID(X509_get_subject_name((X509 *) server_cert), NID_commonName, -1); if (common_name_loc < 0) { return Error; } // Extract the CN field common_name_entry = X509_NAME_get_entry(X509_get_subject_name((X509 *) server_cert), common_name_loc); if (common_name_entry == NULL) { return Error; } common_name_asn1 = X509_NAME_ENTRY_get_data(common_name_entry); if (common_name_asn1 == NULL) { return Error; } // validate the names return validate_name(hostname, common_name_asn1); }
static void create_object_key(confdb_handle_t handle, char *name_pt) { char * obj_name_pt; char * new_obj_name_pt; char * save_pt; hdb_handle_t obj_handle; hdb_handle_t parent_object_handle = OBJECT_PARENT_HANDLE; char tmp_name[OBJ_NAME_SIZE]; cs_error_t res; char parent_name[OBJ_NAME_SIZE]; char key_name[OBJ_NAME_SIZE]; char key_value[OBJ_NAME_SIZE]; get_parent_name(name_pt, parent_name); get_key(name_pt, key_name, key_value); strncpy (tmp_name, parent_name, sizeof (tmp_name)); tmp_name[sizeof (tmp_name) - 1] = '\0'; obj_name_pt = strtok_r(tmp_name, SEPERATOR_STR, &save_pt); /* * Create parent object tree */ while (obj_name_pt != NULL) { res = confdb_object_find_start(handle, parent_object_handle); if (res != CS_OK) { fprintf (stderr, "Could not start object_find %d\n", res); exit (EXIT_FAILURE); } new_obj_name_pt = strtok_r (NULL, SEPERATOR_STR, &save_pt); res = confdb_object_find(handle, parent_object_handle, obj_name_pt, strlen (obj_name_pt), &obj_handle); if (res != CS_OK || new_obj_name_pt == NULL) { if (validate_name(obj_name_pt) != CS_OK) { fprintf(stderr, "Incorrect object name \"%s\", \"=\" not allowed.\n", obj_name_pt); exit(EXIT_FAILURE); } if (debug) printf ("%s:%d: %s\n", __func__,__LINE__, obj_name_pt); res = confdb_object_create (handle, parent_object_handle, obj_name_pt, strlen (obj_name_pt), &obj_handle); if (res != CS_OK) { fprintf(stderr, "Failed to create object \"%s\". Error %d.\n", obj_name_pt, res); } } parent_object_handle = obj_handle; obj_name_pt = new_obj_name_pt; } /* * Create key */ res = confdb_key_create_typed (handle, obj_handle, key_name, key_value, strlen(key_value), CONFDB_VALUETYPE_STRING); if (res != CS_OK) { fprintf(stderr, "Failed to create the key %s=%s. Error %d\n", key_name, key_value, res); } }
int main(int argc, char **argv) { bool non_batch = false; bool batch = false; bool employee = false; bool guest = false; bool arrival = false; bool departure = false; int32_t timestamp = -1; const char *token = NULL; const char *name = NULL; int32_t room = -1; const char *filename = NULL; struct log_entry l; int opt; static const char *optstr = "T:K:E:G:ALR:B"; opterr = 0; while((opt = getopt(argc, argv, optstr)) != -1) { switch(opt) { case 'T': non_batch = true; if (!parse_num(optarg, ×tamp)) invalid(true); if (!validate_int_range(timestamp, TIMESTAMP_MIN, TIMESTAMP_MAX)) invalid(true); break; case 'K': non_batch = true; token = optarg; if (!validate_token(token)) invalid(true); break; case 'E': non_batch = true; if (guest) invalid(true); employee = true; name = optarg; if (!validate_name(name)) invalid(true); break; case 'G': non_batch = true; if (employee) invalid(true); guest = true; name = optarg; if (!validate_name(name)) invalid(true); break; case 'A': non_batch = true; if (departure) invalid(true); arrival = true; break; case 'L': non_batch = true; if (arrival) invalid(true); departure = true; break; case 'R': non_batch = true; if (!parse_num(optarg, &room)) invalid(true); if (!validate_int_range(room, ROOM_MIN, ROOM_MAX)) invalid(true); break; case 'B': if (non_batch) invalid(true); batch = true; break; default: invalid(true); break; } } if (optind >= argc) invalid(true); else filename = argv[optind]; if (filename && !validate_filename(filename)) invalid(true); if (batch && non_batch) invalid(true); if (batch) { batch_mode(filename); } else { int ret; if (!timestamp || !token || !(employee || guest) || !(arrival || departure)) invalid(true); if (employee && guest) invalid(true); l.timestamp = (uint32_t) timestamp; l.room = room; l.action = arrival ? ARRIVAL : DEPARTURE; l.type = guest ? GUEST : EMPLOYEE; l.name = strdup(name); ret = append_log_entry(&l, filename, token); free((void *)l.name); l.name = NULL; if (ret != CAPSTONE_EXIT_SUCCESS) { invalid(true); } } exit(CAPSTONE_EXIT_SUCCESS); }
/** * gst_encoding_target_load: * @name: the name of the #GstEncodingTarget to load (automatically * converted to lower case internally as capital letters are not * valid for target names). * @category: (allow-none): the name of the target category, like * #GST_ENCODING_CATEGORY_DEVICE. Can be %NULL * @error: If an error occured, this field will be filled in. * * Searches for the #GstEncodingTarget with the given name, loads it * and returns it. * * If the category name is specified only targets from that category will be * searched for. * * Returns: (transfer full): The #GstEncodingTarget if available, else %NULL. */ GstEncodingTarget * gst_encoding_target_load (const gchar * name, const gchar * category, GError ** error) { gint i; gchar *p, *lname, *lfilename = NULL, *tldir, **encoding_target_dirs; const gchar *envvar; GstEncodingTarget *target = NULL; g_return_val_if_fail (name != NULL, NULL); p = lname = g_str_to_ascii (name, NULL); for (; *p; ++p) *p = g_ascii_tolower (*p); if (!validate_name (lname)) goto invalid_name; if (category && !validate_name (category)) goto invalid_category; lfilename = g_strdup_printf ("%s" GST_ENCODING_TARGET_SUFFIX, lname); envvar = g_getenv ("GST_ENCODING_TARGET_PATH"); if (envvar) { encoding_target_dirs = g_strsplit (envvar, G_SEARCHPATH_SEPARATOR_S, -1); for (i = 0; encoding_target_dirs[i]; i++) { target = gst_encoding_target_subload (encoding_target_dirs[i], category, lfilename, error); if (target) break; } g_strfreev (encoding_target_dirs); if (target) goto done; } /* Try from local profiles */ tldir = g_build_filename (g_get_user_data_dir (), "gstreamer-" GST_API_VERSION, GST_ENCODING_TARGET_DIRECTORY, NULL); target = gst_encoding_target_subload (tldir, category, lfilename, error); g_free (tldir); if (target == NULL) { /* Try from system-wide profiles */ tldir = g_build_filename (GST_DATADIR, "gstreamer-" GST_API_VERSION, GST_ENCODING_TARGET_DIRECTORY, NULL); target = gst_encoding_target_subload (tldir, category, lfilename, error); g_free (tldir); } if (!target) { GList *tmp, *targets = gst_encoding_list_all_targets (NULL); for (tmp = targets; tmp; tmp = tmp->next) { gint i; GstEncodingTarget *tmptarget = tmp->data; gchar **names = g_strsplit (tmptarget->name, ";", -1); for (i = 0; names[i]; i++) { if (!g_strcmp0 (names[i], lname) && (!category || !g_strcmp0 (tmptarget->category, category))) { target = gst_object_ref (tmptarget); break; } } g_strfreev (names); if (target) break; } g_list_free_full (targets, gst_object_unref); } done: g_free (lfilename); g_free (lname); return target; invalid_name: { GST_ERROR ("Invalid name for encoding target : '%s'", name); goto done; } invalid_category: { GST_ERROR ("Invalid name for encoding category : '%s'", category); goto done; } }
static void write_key(confdb_handle_t handle, char * path_pt) { hdb_handle_t obj_handle; char parent_name[OBJ_NAME_SIZE]; char key_name[OBJ_NAME_SIZE]; char key_value[OBJ_NAME_SIZE]; char old_key_value[OBJ_NAME_SIZE]; size_t old_key_value_len; cs_error_t res; confdb_value_types_t type; /* find the parent object */ get_parent_name(path_pt, parent_name); get_key(path_pt, key_name, key_value); if (debug == 1) printf ("%d: key:\"%s\", value:\"%s\"\n", __LINE__, key_name, key_value); if (validate_name(key_name) != CS_OK) { fprintf(stderr, "Incorrect key name, can not have \"=\" or \"%c\"\n", SEPERATOR); exit(EXIT_FAILURE); } res = find_object (handle, parent_name, FIND_OBJECT_ONLY, &obj_handle); if (res != CS_OK) { fprintf(stderr, "Can't find parent object of \"%s\"\n", path_pt); exit(EXIT_FAILURE); } /* get the current key */ res = confdb_key_get_typed (handle, obj_handle, key_name, old_key_value, &old_key_value_len, &type); if (res == CS_OK) { /* replace the current value */ res = confdb_key_replace (handle, obj_handle, key_name, strlen(key_name), old_key_value, old_key_value_len, key_value, strlen(key_value)); if (res != CS_OK) fprintf(stderr, "Failed to replace the key %s=%s. Error %d\n", key_name, key_value, res); } else { /* not there, create a new key */ res = confdb_key_create_typed (handle, obj_handle, key_name, key_value, strlen(key_value), CONFDB_VALUETYPE_STRING); if (res != CS_OK) fprintf(stderr, "Failed to create the key %s=%s. Error %d\n", key_name, key_value, res); } }
static int _lvcreate_name_params(struct lvcreate_params *lp, struct cmd_context *cmd, int *pargc, char ***pargv) { int argc = *pargc; char **argv = *pargv, *ptr; char *vg_name; lp->lv_name = arg_str_value(cmd, name_ARG, NULL); if (lp->snapshot && !arg_count(cmd, virtualsize_ARG)) { if (!argc) { log_error("Please specify a logical volume to act as " "the snapshot origin."); return 0; } lp->origin = argv[0]; (*pargv)++, (*pargc)--; if (!(lp->vg_name = extract_vgname(cmd, lp->origin))) { log_error("The origin name should include the " "volume group."); return 0; } /* Strip the volume group from the origin */ if ((ptr = strrchr(lp->origin, (int) '/'))) lp->origin = ptr + 1; } else { /* * If VG not on command line, try -n arg and then * environment. */ if (!argc) { if (!(lp->vg_name = extract_vgname(cmd, lp->lv_name))) { log_error("Please provide a volume group name"); return 0; } } else { vg_name = skip_dev_dir(cmd, argv[0], NULL); if (strrchr(vg_name, '/')) { log_error("Volume group name expected " "(no slash)"); return 0; } /* * Ensure lv_name doesn't contain a * different VG. */ if (lp->lv_name && strchr(lp->lv_name, '/')) { if (!(lp->vg_name = extract_vgname(cmd, lp->lv_name))) return 0; if (strcmp(lp->vg_name, vg_name)) { log_error("Inconsistent volume group " "names " "given: \"%s\" and \"%s\"", lp->vg_name, vg_name); return 0; } } lp->vg_name = vg_name; (*pargv)++, (*pargc)--; } } if (!validate_name(lp->vg_name)) { log_error("Volume group name %s has invalid characters", lp->vg_name); return 0; } if (lp->lv_name) { if ((ptr = strrchr(lp->lv_name, '/'))) lp->lv_name = ptr + 1; if (!apply_lvname_restrictions(lp->lv_name)) return_0; if (!validate_name(lp->lv_name)) { log_error("Logical volume name \"%s\" is invalid", lp->lv_name); return 0; } } return 1; }
/* * lvrename command implementation. * Check arguments and call lv_rename() to execute the request. */ int lvrename(struct cmd_context *cmd, int argc, char **argv) { size_t maxlen; char *lv_name_old, *lv_name_new; const char *vg_name, *vg_name_new, *vg_name_old; char *st; int r = ECMD_FAILED; struct volume_group *vg = NULL; struct lv_list *lvl; if (argc == 3) { vg_name = skip_dev_dir(cmd, argv[0], NULL); lv_name_old = argv[1]; lv_name_new = argv[2]; if (strchr(lv_name_old, '/') && (vg_name_old = extract_vgname(cmd, lv_name_old)) && strcmp(vg_name_old, vg_name)) { log_error("Please use a single volume group name " "(\"%s\" or \"%s\")", vg_name, vg_name_old); return EINVALID_CMD_LINE; } } else if (argc == 2) { lv_name_old = argv[0]; lv_name_new = argv[1]; vg_name = extract_vgname(cmd, lv_name_old); } else { log_error("Old and new logical volume names required"); return EINVALID_CMD_LINE; } if (!validate_name(vg_name)) { log_error("Please provide a valid volume group name"); return EINVALID_CMD_LINE; } if (strchr(lv_name_new, '/') && (vg_name_new = extract_vgname(cmd, lv_name_new)) && strcmp(vg_name, vg_name_new)) { log_error("Logical volume names must " "have the same volume group (\"%s\" or \"%s\")", vg_name, vg_name_new); return EINVALID_CMD_LINE; } if ((st = strrchr(lv_name_old, '/'))) lv_name_old = st + 1; if ((st = strrchr(lv_name_new, '/'))) lv_name_new = st + 1; /* Check sanity of new name */ maxlen = NAME_LEN - strlen(vg_name) - strlen(cmd->dev_dir) - 3; if (strlen(lv_name_new) > maxlen) { log_error("New logical volume path exceeds maximum length " "of %" PRIsize_t "!", maxlen); return ECMD_FAILED; } if (!*lv_name_new) { log_error("New logical volume name may not be blank"); return ECMD_FAILED; } if (!apply_lvname_restrictions(lv_name_new)) { stack; return ECMD_FAILED; } if (!validate_name(lv_name_new)) { log_error("New logical volume name \"%s\" is invalid", lv_name_new); return EINVALID_CMD_LINE; } if (!strcmp(lv_name_old, lv_name_new)) { log_error("Old and new logical volume names must differ"); return EINVALID_CMD_LINE; } log_verbose("Checking for existing volume group \"%s\"", vg_name); vg = vg_read_for_update(cmd, vg_name, NULL, 0); if (vg_read_error(vg)) { release_vg(vg); stack; return ECMD_FAILED; } if (!(lvl = find_lv_in_vg(vg, lv_name_old))) { log_error("Existing logical volume \"%s\" not found in " "volume group \"%s\"", lv_name_old, vg_name); goto error; } if (!lv_rename(cmd, lvl->lv, lv_name_new)) goto error; log_print("Renamed \"%s\" to \"%s\" in volume group \"%s\"", lv_name_old, lv_name_new, vg_name); r = ECMD_PROCESSED; error: unlock_and_release_vg(cmd, vg, vg_name); return r; }
int main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { int i; /* Looping var */ http_t *http; /* Connection to server */ char *printer, /* Destination printer */ *pclass, /* Printer class name */ *val; /* Pointer to allow/deny value */ int num_options; /* Number of options */ cups_option_t *options; /* Options */ char *file; /* New PPD file/interface script */ _cupsSetLocale(argv); http = NULL; printer = NULL; num_options = 0; options = NULL; file = NULL; for (i = 1; i < argc; i ++) if (argv[i][0] == '-') switch (argv[i][1]) { case 'c' : /* Add printer to class */ if (!http) { http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); if (http == NULL) { _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno)); return (1); } } if (printer == NULL) { _cupsLangPuts(stderr, _("lpadmin: Unable to add a printer to the class:\n" " You must specify a printer name " "first.")); return (1); } if (argv[i][2]) pclass = argv[i] + 2; else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected class name after \"-c\" " "option.")); return (1); } pclass = argv[i]; } if (!validate_name(pclass)) { _cupsLangPuts(stderr, _("lpadmin: Class name can only contain printable " "characters.")); return (1); } if (add_printer_to_class(http, printer, pclass)) return (1); break; case 'd' : /* Set as default destination */ if (!http) { http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); if (http == NULL) { _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno)); return (1); } } if (argv[i][2]) printer = argv[i] + 2; else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected printer name after \"-d\" " "option.")); return (1); } printer = argv[i]; } if (!validate_name(printer)) { _cupsLangPuts(stderr, _("lpadmin: Printer name can only contain " "printable characters.")); return (1); } if (default_printer(http, printer)) return (1); i = argc; break; case 'h' : /* Connect to host */ if (http) { httpClose(http); http = NULL; } if (argv[i][2] != '\0') cupsSetServer(argv[i] + 2); else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected hostname after \"-h\" " "option.")); return (1); } cupsSetServer(argv[i]); } break; case 'i' : /* Use the specified interface script */ if (argv[i][2]) file = argv[i] + 2; else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected interface after \"-i\" " "option.")); return (1); } file = argv[i]; } break; case 'E' : /* Enable the printer */ if (printer == NULL) { #ifdef HAVE_SSL cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); if (http) httpEncryption(http, HTTP_ENCRYPT_REQUIRED); #else _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); #endif /* HAVE_SSL */ break; } if (!http) { http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); if (http == NULL) { _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno)); return (1); } } if (enable_printer(http, printer)) return (1); break; case 'm' : /* Use the specified standard script/PPD file */ if (argv[i][2]) num_options = cupsAddOption("ppd-name", argv[i] + 2, num_options, &options); else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected model after \"-m\" " "option.")); return (1); } num_options = cupsAddOption("ppd-name", argv[i], num_options, &options); } break; case 'o' : /* Set option */ if (argv[i][2]) num_options = cupsParseOptions(argv[i] + 2, num_options, &options); else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected name=value after \"-o\" " "option.")); return (1); } num_options = cupsParseOptions(argv[i], num_options, &options); } break; case 'p' : /* Add/modify a printer */ if (argv[i][2]) printer = argv[i] + 2; else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected printer after \"-p\" " "option.")); return (1); } printer = argv[i]; } if (!validate_name(printer)) { _cupsLangPuts(stderr, _("lpadmin: Printer name can only contain " "printable characters.")); return (1); } break; case 'r' : /* Remove printer from class */ if (!http) { http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); if (http == NULL) { _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno)); return (1); } } if (printer == NULL) { _cupsLangPuts(stderr, _("lpadmin: Unable to remove a printer from the " "class:\n" " You must specify a printer name " "first.")); return (1); } if (argv[i][2]) pclass = argv[i] + 2; else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected class after \"-r\" " "option.")); return (1); } pclass = argv[i]; } if (!validate_name(pclass)) { _cupsLangPuts(stderr, _("lpadmin: Class name can only contain printable " "characters.")); return (1); } if (delete_printer_from_class(http, printer, pclass)) return (1); break; case 'R' : /* Remove option */ if (!http) { http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); if (http == NULL) { _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno)); return (1); } } if (printer == NULL) { _cupsLangPuts(stderr, _("lpadmin: Unable to delete option:\n" " You must specify a printer name " "first.")); return (1); } if (argv[i][2]) val = argv[i] + 2; else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected name after \"-R\" " "option.")); return (1); } val = argv[i]; } if (delete_printer_option(http, printer, val)) return (1); break; case 'U' : /* Username */ if (argv[i][2] != '\0') cupsSetUser(argv[i] + 2); else { i ++; if (i >= argc) { _cupsLangPrintf(stderr, _("%s: Error - expected username after " "\"-U\" option."), argv[0]); return (1); } cupsSetUser(argv[i]); } break; case 'u' : /* Allow/deny users */ if (argv[i][2]) val = argv[i] + 2; else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected allow/deny:userlist after " "\"-u\" option.")); return (1); } val = argv[i]; } if (!_cups_strncasecmp(val, "allow:", 6)) num_options = cupsAddOption("requesting-user-name-allowed", val + 6, num_options, &options); else if (!_cups_strncasecmp(val, "deny:", 5)) num_options = cupsAddOption("requesting-user-name-denied", val + 5, num_options, &options); else { _cupsLangPrintf(stderr, _("lpadmin: Unknown allow/deny option \"%s\"."), val); return (1); } break; case 'v' : /* Set the device-uri attribute */ if (argv[i][2]) num_options = cupsAddOption("device-uri", argv[i] + 2, num_options, &options); else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected device URI after \"-v\" " "option.")); return (1); } num_options = cupsAddOption("device-uri", argv[i], num_options, &options); } break; case 'x' : /* Delete a printer */ if (!http) { http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); if (http == NULL) { _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno)); return (1); } } if (argv[i][2]) printer = argv[i] + 2; else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected printer or class after " "\"-x\" option.")); return (1); } printer = argv[i]; } if (!validate_name(printer)) { _cupsLangPuts(stderr, _("lpadmin: Printer name can only contain " "printable characters.")); return (1); } if (delete_printer(http, printer)) return (1); i = argc; break; case 'D' : /* Set the printer-info attribute */ if (argv[i][2]) num_options = cupsAddOption("printer-info", argv[i] + 2, num_options, &options); else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected description after " "\"-D\" option.")); return (1); } num_options = cupsAddOption("printer-info", argv[i], num_options, &options); } break; case 'I' : /* Set the supported file types (ignored) */ i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected file type(s) after \"-I\" " "option.")); return (1); } _cupsLangPuts(stderr, _("lpadmin: Warning - content type list ignored.")); break; case 'L' : /* Set the printer-location attribute */ if (argv[i][2]) num_options = cupsAddOption("printer-location", argv[i] + 2, num_options, &options); else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected location after \"-L\" " "option.")); return (1); } num_options = cupsAddOption("printer-location", argv[i], num_options, &options); } break; case 'P' : /* Use the specified PPD file */ if (argv[i][2]) file = argv[i] + 2; else { i ++; if (i >= argc) { _cupsLangPuts(stderr, _("lpadmin: Expected PPD after \"-P\" option.")); return (1); } file = argv[i]; } break; default : _cupsLangPrintf(stderr, _("lpadmin: Unknown option \"%c\"."), argv[i][1]); return (1); } else { _cupsLangPrintf(stderr, _("lpadmin: Unknown argument \"%s\"."), argv[i]); return (1); } /* * Set options as needed... */ if (num_options || file) { if (!http) { http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); if (http == NULL) { _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno)); return (1); } } if (printer == NULL) { _cupsLangPuts(stderr, _("lpadmin: Unable to set the printer options:\n" " You must specify a printer name first.")); return (1); } if (set_printer_options(http, printer, num_options, options, file)) return (1); } if (printer == NULL) { _cupsLangPuts(stdout, _("Usage:\n" "\n" " lpadmin [-h server] -d destination\n" " lpadmin [-h server] -x destination\n" " lpadmin [-h server] -p printer [-c add-class] " "[-i interface] [-m model]\n" " [-r remove-class] [-v device] " "[-D description]\n" " [-P ppd-file] [-o name=value]\n" " [-u allow:user,user] " "[-u deny:user,user]")); } if (http) httpClose(http); return (0); }
static int _lvcreate_name_params(struct lvcreate_params *lp, struct cmd_context *cmd, int *pargc, char ***pargv) { int argc = *pargc; char **argv = *pargv, *ptr; const char *vg_name; lp->pool = arg_str_value(cmd, thinpool_ARG, NULL); /* If --thinpool contains VG name, extract it. */ if (lp->pool && strchr(lp->pool, '/')) { if (!(lp->vg_name = extract_vgname(cmd, lp->pool))) return 0; /* Strip VG from pool */ if ((ptr = strrchr(lp->pool, (int) '/'))) lp->pool = ptr + 1; } lp->lv_name = arg_str_value(cmd, name_ARG, NULL); /* If --name contains VG name, extract it. */ if (lp->lv_name && strchr(lp->lv_name, '/')) { if (!_set_vg_name(lp, extract_vgname(cmd, lp->lv_name))) return_0; /* Strip VG from lv_name */ if ((ptr = strrchr(lp->lv_name, (int) '/'))) lp->lv_name = ptr + 1; } /* Need an origin? */ if (lp->snapshot && !arg_count(cmd, virtualsize_ARG)) { /* argv[0] might be origin or vg/origin */ if (!argc) { log_error("Please specify a logical volume to act as " "the snapshot origin."); return 0; } lp->origin = skip_dev_dir(cmd, argv[0], NULL); if (strrchr(lp->origin, '/')) { if (!_set_vg_name(lp, extract_vgname(cmd, lp->origin))) return_0; /* Strip the volume group from the origin */ if ((ptr = strrchr(lp->origin, (int) '/'))) lp->origin = ptr + 1; } if (!lp->vg_name && !_set_vg_name(lp, extract_vgname(cmd, NULL))) return_0; if (!lp->vg_name) { log_error("The origin name should include the " "volume group."); return 0; } (*pargv)++, (*pargc)--; } else if (seg_is_thin(lp) && !lp->pool && argc) { /* argv[0] might be vg or vg/Pool */ vg_name = skip_dev_dir(cmd, argv[0], NULL); if (!strrchr(vg_name, '/')) { if (!_set_vg_name(lp, vg_name)) return_0; } else { lp->pool = vg_name; if (!_set_vg_name(lp, extract_vgname(cmd, lp->pool))) return_0; if (!lp->vg_name && !_set_vg_name(lp, extract_vgname(cmd, NULL))) return_0; if (!lp->vg_name) { log_error("The pool name should include the " "volume group."); return 0; } /* Strip the volume group */ if ((ptr = strrchr(lp->pool, (int) '/'))) lp->pool = ptr + 1; } (*pargv)++, (*pargc)--; } else { /* * If VG not on command line, try environment default. */ if (!argc) { if (!lp->vg_name && !(lp->vg_name = extract_vgname(cmd, NULL))) { log_error("Please provide a volume group name"); return 0; } } else { vg_name = skip_dev_dir(cmd, argv[0], NULL); if (strrchr(vg_name, '/')) { log_error("Volume group name expected " "(no slash)"); return 0; } if (!_set_vg_name(lp, vg_name)) return_0; (*pargv)++, (*pargc)--; } } if (!validate_name(lp->vg_name)) { log_error("Volume group name %s has invalid characters", lp->vg_name); return 0; } if (lp->lv_name) { if (!apply_lvname_restrictions(lp->lv_name)) return_0; if (!validate_name(lp->lv_name)) { log_error("Logical volume name \"%s\" is invalid", lp->lv_name); return 0; } } if (lp->pool) { if (!apply_lvname_restrictions(lp->pool)) return_0; if (!validate_name(lp->pool)) { log_error("Logical volume name \"%s\" is invalid", lp->pool); return 0; } if (lp->lv_name && !strcmp(lp->lv_name, lp->pool)) { log_error("Logical volume name %s and pool name %s must be different.", lp->lv_name, lp->pool); return 0; } } return 1; }
char * build_header(const dumpfile_t * file, size_t *size, size_t max_size) { GString *rval, *split_data; char *qname; char *program; size_t min_size; min_size = size? *size : max_size; dbprintf(_("Building type %s header of %zu-%zu bytes with name='%s' disk='%s' dumplevel=%d and blocksize=%zu\n"), filetype2str(file->type), min_size, max_size, file->name, file->disk, file->dumplevel, file->blocksize); rval = g_string_sized_new(min_size); split_data = g_string_sized_new(10); switch (file->type) { case F_TAPESTART: validate_name(file->name); validate_datestamp(file->datestamp); g_string_printf(rval, "AMANDA: TAPESTART DATE %s TAPE %s\n\014\n", file->datestamp, file->name); break; case F_SPLIT_DUMPFILE: validate_parts(file->partnum, file->totalparts); g_string_printf(split_data, " part %d/%d ", file->partnum, file->totalparts); /* FALLTHROUGH */ case F_CONT_DUMPFILE: case F_DUMPFILE : validate_name(file->name); validate_datestamp(file->datestamp); qname = quote_string(file->disk); program = stralloc(file->program); if (match("^.*[.][Ee][Xx][Ee]$", program)) { /* Trim ".exe" from program name */ program[strlen(program) - strlen(".exe")] = '\0'; } g_string_printf(rval, "AMANDA: %s %s %s %s %s lev %d comp %s program %s", filetype2str(file->type), file->datestamp, file->name, qname, split_data->str, file->dumplevel, file->comp_suffix, program); amfree(program); amfree(qname); /* only output crypt if it's enabled */ if (strcmp(file->encrypt_suffix, "enc") == 0) { g_string_append_printf(rval, " crypt %s", file->encrypt_suffix); } if (*file->srvcompprog) { g_string_append_printf(rval, " server_custom_compress %s", file->srvcompprog); } else if (*file->clntcompprog) { g_string_append_printf(rval, " client_custom_compress %s", file->clntcompprog); } if (*file->srv_encrypt) { g_string_append_printf(rval, " server_encrypt %s", file->srv_encrypt); } else if (*file->clnt_encrypt) { g_string_append_printf(rval, " client_encrypt %s", file->clnt_encrypt); } if (*file->srv_decrypt_opt) { g_string_append_printf(rval, " server_decrypt_option %s", file->srv_decrypt_opt); } else if (*file->clnt_decrypt_opt) { g_string_append_printf(rval, " client_decrypt_option %s", file->clnt_decrypt_opt); } g_string_append_printf(rval, "\n"); if (file->cont_filename[0] != '\0') { g_string_append_printf(rval, "CONT_FILENAME=%s\n", file->cont_filename); } if (file->application[0] != '\0') { g_string_append_printf(rval, "APPLICATION=%s\n", file->application); } if (file->is_partial != 0) { g_string_append_printf(rval, "PARTIAL=YES\n"); } if (file->dle_str && strlen(file->dle_str) < max_size-2048) { char *heredoc = quote_heredoc(file->dle_str, "ENDDLE"); g_string_append_printf(rval, "DLE=%s\n", heredoc); amfree(heredoc); } g_string_append_printf(rval, _("To restore, position tape at start of file and run:\n")); g_string_append_printf(rval, "\tdd if=<tape> "); if (file->blocksize) g_string_append_printf(rval, "bs=%zuk ", file->blocksize / 1024); g_string_append_printf(rval, "skip=1 | "); if (*file->decrypt_cmd) g_string_append_printf(rval, "%s ", file->decrypt_cmd); if (*file->uncompress_cmd) g_string_append_printf(rval, "%s ", file->uncompress_cmd); if (*file->recover_cmd) g_string_append_printf(rval, "%s ", file->recover_cmd); /* \014 == ^L == form feed */ g_string_append_printf(rval, "\n\014\n"); break; case F_TAPEEND: validate_datestamp(file->datestamp); g_string_printf(rval, "AMANDA: TAPEEND DATE %s\n\014\n", file->datestamp); break; case F_NOOP: g_string_printf(rval, "AMANDA: NOOP\n\014\n"); break; case F_UNKNOWN: case F_EMPTY: case F_WEIRD: default: error(_("Invalid header type: %d (%s)"), file->type, filetype2str(file->type)); /*NOTREACHED*/ } g_string_free(split_data, TRUE); /* is it too big? */ if (rval->len > max_size) { g_debug("header is larger than %zu bytes -- cannot create", max_size); g_string_free(rval, TRUE); return NULL; } /* Clear extra bytes. */ if (rval->len < min_size) { bzero(rval->str + rval->len, rval->allocated_len - rval->len); } if (size) { *size = MAX(min_size, (size_t)rval->len); } return g_string_free(rval, FALSE); }
int main(int argc, const char *argv[]) { const char *name; struct sockaddr_name addr; int domain, type, protocol; unsigned short port = 0; int fd; /* Look for options */ if (argc > 1) { int i; for (i = 1; i < argc; i++) { if ((*argv[i] == '-' || *argv[i] == '/') && (argv[i][1] == 'p' || argv[i][1] == 'P') && i < argc - 1) { port = atoi(argv[i + 1]); if (argc - i > 2) memmove(argv + i, argv + i + 2, (argc - i - 2) * sizeof(char *)); argc -= 2; } } } /* Now that options are removed, look for name arguments */ if (argc > 1) { if (!validate_name(argv[1], &addr)) { fprintf(stderr, "name too long\n"); usage(argv[0]); } } else usage(argv[0]); domain = PF_NAME; type = SOCK_STREAM; protocol = 0; printf("creating a socket with domain = %d, type = %d, protocol = %d\n", domain, type, protocol); fd = socket(domain, type, protocol); if (fd >= 0) { int ret; printf("got a socket!\n"); if (port) addr.sname_port = htons(port); printf("binding to %s:%d\n", addr.sname_addr.name, ntohs(addr.sname_port)); ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) perror("bind"); else { printf("bind succeeded!\n"); ret = listen(fd, 0); if (ret < 0) perror("listen"); else do_accept_loop(fd); } close(fd); } else { perror("socket"); fprintf(stderr, "errno = %d\n", errno); } return 0; }