void TestAuth::testIPVersionFiltering() { // prepare exports const char *correct_exports[] = { "/home ::/0", // 0 "/dev 0.0.0.0/0" , // 1 }; const size_t correct_count = sizeof(correct_exports) / sizeof(correct_exports[0]); std::ofstream stream; stream.open(exportsfile, std::ios_base::out | std::ios_base::trunc); CPPUNIT_ASSERT(stream.is_open()); for (size_t i = 0; i < correct_count; ++i) { stream << correct_exports[i] << std::endl; } stream.close(); CPPUNIT_ASSERT(!stream.fail()); CPPUNIT_ASSERT(parse_exports(exportsfile, &m_instance.exports.list, 0) == 0); const struct rfs_list *export_rec = m_instance.exports.list; unsigned export_no = 0; while (export_rec != NULL) { const struct rfs_export *info = static_cast<const struct rfs_export *>(export_rec->data); switch (export_no) { // /home ::/0 case 0: CPPUNIT_ASSERT(check_permissions(&m_instance, info, "::1") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") != 0); break; // /dev 0.0.0.0/0 case 1: CPPUNIT_ASSERT(check_permissions(&m_instance, info, "::1") != 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") == 0); break; } ++export_no; export_rec = export_rec->next; } }
int lua_apr_file_open(lua_State *L) { apr_status_t status; lua_apr_file *file; apr_int32_t flags; const char *path; apr_fileperms_t perm; # if defined(WIN32) || defined(OS2) || defined(NETWARE) /* On Windows apr_os_file_t isn't an integer: it's a HANDLE. */ if (0) ; # else /* On UNIX like systems apr_os_file_t is an integer. */ if (lua_isnumber(L, 1)) { apr_os_file_t fd = (apr_os_file_t) lua_tonumber(L, 1); flags = parse_mode_str(luaL_optstring(L, 2, "r")); file = file_alloc(L, NULL, NULL); status = apr_os_file_put(&file->handle, &fd, flags, file->pool->ptr); } # endif else { path = luaL_checkstring(L, 1); perm = check_permissions(L, 3, 0); flags = parse_mode_str(luaL_optstring(L, 2, "r")); file = file_alloc(L, path, NULL); status = apr_file_open(&file->handle, path, flags, perm, file->pool->ptr); } if (status != APR_SUCCESS) return push_file_error(L, file, status); init_file_buffers(L, file, !(flags & APR_FOPEN_BINARY)); return 1; }
int main(int argc, char **argv) { if(!check_permissions()) { exit(EXIT_FAILURE); } if((argc != 3) && (argc != 4)) { printf("usage: %s iface ttl\n", argv[0]); exit(EXIT_FAILURE); } char *iface = argv[1]; int ttl = atoi(argv[2]); int ipversion;// ipversion = 4 to IPv4; ipversion = 6 to IPv6; if(argc == 4){ ipversion = atoi(argv[3]); } else{ ipversion = 4; } log_init(LOG_EXTRA, "log.txt", 1, 1024*1024*16); struct packet *pkt; struct sender4 *s; if (ipversion == 4){ s = sender4_create(iface); pkt = sender4_send_icmp(s, 2, ttl, 1, 1, 1, 1, 1000); sender4_destroy(s); } else if (ipversion == 6){ struct sender6 *s6 = sender6_create(iface); struct libnet_in6_addr ipv6_dst; struct sockaddr_in6 sa; inet_pton(AF_INET6, "2800:3f0:4004:803::1012", &(sa.sin6_addr)); memcpy(&ipv6_dst, &sa.sin6_addr, sizeof(struct libnet_in6_addr)); pkt = sender6_send_icmp(s6, ipv6_dst, ttl, 1, 1, 1, 1, 1, 1000); sender6_destroy(s6); } char *str = packet_tostr(pkt); logd(LOG_DEBUG, "%s\n", str); free(str); packet_destroy(pkt); sleep(2); if (ipversion == 4){ pkt = sender4_send_icmp_fixrev(s, 2, ttl, 1, 1, 1, 1, 1000); } /*else if (ipversion == 6){ struct libnet_in6_addr dst_ipv6; dst_ipv6 = nameToAddr6WithSender(s, "::2"); pkt = sender_send_icmp6_fixrev(s, dst_ipv6, ttl, 1, 1, 1, 1, 1000); } str = packet_tostr(pkt); logd(LOG_DEBUG, "%s\n", str); free(str); packet_destroy(pkt);*/ log_destroy(); exit(EXIT_SUCCESS); }
static void process_read_by_type(struct async_read_op *op) { struct bt_gatt_server *server = op->server; uint8_t ecode; struct gatt_db_attribute *attr; attr = queue_pop_head(op->db_data); if (op->done || !attr) { bt_att_send(server->att, BT_ATT_OP_READ_BY_TYPE_RSP, op->pdu, op->pdu_len, NULL, NULL, NULL); async_read_op_destroy(op); return; } ecode = check_permissions(server, attr, BT_ATT_PERM_READ | BT_ATT_PERM_READ_AUTHEN | BT_ATT_PERM_READ_ENCRYPT); if (ecode) goto error; if (gatt_db_attribute_read(attr, 0, op->opcode, server->att, read_by_type_read_complete_cb, op)) return; ecode = BT_ATT_ERROR_UNLIKELY; error: bt_att_send_error_rsp(server->att, BT_ATT_OP_READ_BY_TYPE_REQ, gatt_db_attribute_get_handle(attr), ecode); async_read_op_destroy(op); }
/* * SQL function for creating a new physical (streaming replication) * replication slot. */ Datum pg_create_physical_replication_slot(PG_FUNCTION_ARGS) { Name name = PG_GETARG_NAME(0); Datum values[2]; bool nulls[2]; TupleDesc tupdesc; HeapTuple tuple; Datum result; Assert(!MyReplicationSlot); if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); check_permissions(); CheckSlotRequirements(); /* acquire replication slot, this will check for conflicting names */ ReplicationSlotCreate(NameStr(*name), false, RS_PERSISTENT); values[0] = NameGetDatum(&MyReplicationSlot->data.name); nulls[0] = false; nulls[1] = true; tuple = heap_form_tuple(tupdesc, values, nulls); result = HeapTupleGetDatum(tuple); ReplicationSlotRelease(); PG_RETURN_DATUM(result); }
void TestAuth::testCheckUGOPermissions() { // prepare exports const char *correct_exports[] = { "/dev * (ugo)", // 0 }; const size_t correct_count = sizeof(correct_exports) / sizeof(correct_exports[0]); std::ofstream stream; stream.open(exportsfile, std::ios_base::out | std::ios_base::trunc); CPPUNIT_ASSERT(stream.is_open()); for (size_t i = 0; i < correct_count; ++i) { stream << correct_exports[i] << std::endl; } stream.close(); CPPUNIT_ASSERT(!stream.fail()); CPPUNIT_ASSERT(parse_exports(exportsfile, &m_instance.exports.list, 0) == 0); const struct rfs_list *export_rec = m_instance.exports.list; unsigned export_no = 0; while (export_rec != NULL) { const struct rfs_export *info = static_cast<const struct rfs_export *>(export_rec->data); switch (export_no) { // /dev * (ugo) case 0: CPPUNIT_ASSERT(check_permissions(&m_instance, info, "") == 0); // break server's auth to check if login will fail char *auth_user = m_instance.server.auth_user; m_instance.server.auth_user = NULL; CPPUNIT_ASSERT(check_permissions(&m_instance, info, "") != 0); m_instance.server.auth_user = auth_user; break; } ++export_no; export_rec = export_rec->next; } }
static void write_cb(uint8_t opcode, const void *pdu, uint16_t length, void *user_data) { struct bt_gatt_server *server = user_data; struct gatt_db_attribute *attr; uint16_t handle = 0; struct async_write_op *op = NULL; uint8_t ecode; if (length < 2) { ecode = BT_ATT_ERROR_INVALID_PDU; goto error; } handle = get_le16(pdu); attr = gatt_db_get_attribute(server->db, handle); if (!attr) { ecode = BT_ATT_ERROR_INVALID_HANDLE; goto error; } util_debug(server->debug_callback, server->debug_data, "Write %s - handle: 0x%04x", (opcode == BT_ATT_OP_WRITE_REQ) ? "Req" : "Cmd", handle); ecode = check_permissions(server, attr, BT_ATT_PERM_WRITE | BT_ATT_PERM_WRITE_AUTHEN | BT_ATT_PERM_WRITE_ENCRYPT); if (ecode) goto error; if (server->pending_write_op) { ecode = BT_ATT_ERROR_UNLIKELY; goto error; } op = new0(struct async_write_op, 1); op->server = server; op->opcode = opcode; server->pending_write_op = op; if (gatt_db_attribute_write(attr, 0, pdu + 2, length - 2, opcode, server->att, write_complete_cb, op)) return; if (op) async_write_op_destroy(op); ecode = BT_ATT_ERROR_UNLIKELY; error: if (opcode == BT_ATT_OP_WRITE_CMD) return; bt_att_send_error_rsp(server->att, opcode, handle, ecode); }
/* * SQL function for creating a new logical replication slot. */ Datum pg_create_logical_replication_slot(PG_FUNCTION_ARGS) { Name name = PG_GETARG_NAME(0); Name plugin = PG_GETARG_NAME(1); LogicalDecodingContext *ctx = NULL; TupleDesc tupdesc; HeapTuple tuple; Datum result; Datum values[2]; bool nulls[2]; Assert(!MyReplicationSlot); if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); check_permissions(); CheckLogicalDecodingRequirements(); /* * Acquire a logical decoding slot, this will check for conflicting names. * Initially create it as ephemeral - that allows us to nicely handle * errors during initialization because it'll get dropped if this * transaction fails. We'll make it persistent at the end. */ ReplicationSlotCreate(NameStr(*name), true, RS_EPHEMERAL); /* * Create logical decoding context, to build the initial snapshot. */ ctx = CreateInitDecodingContext( NameStr(*plugin), NIL, logical_read_local_xlog_page, NULL, NULL); /* build initial snapshot, might take a while */ DecodingContextFindStartpoint(ctx); values[0] = CStringGetTextDatum(NameStr(MyReplicationSlot->data.name)); values[1] = LSNGetDatum(MyReplicationSlot->data.confirmed_flush); /* don't need the decoding context anymore */ FreeDecodingContext(ctx); memset(nulls, 0, sizeof(nulls)); tuple = heap_form_tuple(tupdesc, values, nulls); result = HeapTupleGetDatum(tuple); /* ok, slot is now fully created, mark it as persistent */ ReplicationSlotPersist(); ReplicationSlotRelease(); PG_RETURN_DATUM(result); }
static void prep_write_cb(uint8_t opcode, const void *pdu, uint16_t length, void *user_data) { struct bt_gatt_server *server = user_data; uint16_t handle = 0; uint16_t offset; struct gatt_db_attribute *attr; struct prep_write_complete_data *pwcd; uint8_t ecode, status; if (length < 4) { ecode = BT_ATT_ERROR_INVALID_PDU; goto error; } if (queue_length(server->prep_queue) >= server->max_prep_queue_len) { ecode = BT_ATT_ERROR_PREPARE_QUEUE_FULL; goto error; } handle = get_le16(pdu); offset = get_le16(pdu + 2); attr = gatt_db_get_attribute(server->db, handle); if (!attr) { ecode = BT_ATT_ERROR_INVALID_HANDLE; goto error; } util_debug(server->debug_callback, server->debug_data, "Prep Write Req - handle: 0x%04x", handle); ecode = check_permissions(server, attr, BT_ATT_PERM_WRITE | BT_ATT_PERM_WRITE_AUTHEN | BT_ATT_PERM_WRITE_ENCRYPT); if (ecode) goto error; pwcd = new0(struct prep_write_complete_data, 1); pwcd->pdu = malloc(length); memcpy(pwcd->pdu, pdu, length); pwcd->length = length; pwcd->server = server; status = gatt_db_attribute_write(attr, offset, NULL, 0, BT_ATT_OP_PREP_WRITE_REQ, server->att, prep_write_complete_cb, pwcd); if (status) return; ecode = BT_ATT_ERROR_UNLIKELY; error: bt_att_send_error_rsp(server->att, opcode, handle, ecode); }
int main(int argc, char **argv) { if(!check_permissions()) { exit(EXIT_FAILURE); } if((argc != 3) && (argc != 4)) { printf("usage: %s iface ttl\n", argv[0]); exit(EXIT_FAILURE); } char *iface = argv[1]; int ttl = atoi(argv[2]); int ipversion; // ipversion = 4 to IPv4; ipversion = 6 to IPv6; if(argc == 4){ ipversion = atoi(argv[3]); } else{ ipversion = 4; } demux_init(iface); struct confirm *conf = confirm_create(iface); struct confirm_query *q; struct sockaddr_storage dst; if (ipversion == 4){ struct sockaddr_in ipv4_dst; ipv4_dst.sin_family = AF_INET; inet_pton(AF_INET, "200.149.119.183", &(ipv4_dst.sin_addr)); dst = *((struct sockaddr_storage *) &ipv4_dst); dst.ss_family = AF_INET; q = confirm_query_create4(&dst, ttl, 1, 1, 1, 0, querycb); confirm_submit(conf, q); q = confirm_query_create4(&dst, ttl+1, 1, 1, 1, 0, querycb); confirm_submit(conf, q); } else if (ipversion == 6){ struct sockaddr_in6 sa; sa.sin6_family = AF_INET6; inet_pton(AF_INET6, "2800:3F0:4004:800:0:0:0:1012", &(sa.sin6_addr)); dst = *((struct sockaddr_storage *) &sa); dst.ss_family = AF_INET6; q = confirm_query_create6(&dst, ttl, 1, 1, 0, 0, querycb); confirm_submit(conf, q); q = confirm_query_create6(&dst, ttl+1, 1, 1, 0, 0, querycb); confirm_submit(conf, q); } sleep(10); confirm_destroy(conf); demux_destroy(); log_destroy(); exit(EXIT_SUCCESS); }
int lua_apr_file_perms_set(lua_State *L) { const char *path; apr_status_t status; apr_fileperms_t perms; path = luaL_checkstring(L, 1); perms = check_permissions(L, 2, 0); status = apr_file_perms_set(path, perms); return push_status(L, status); }
/* * SQL function for dropping a replication slot. */ Datum pg_drop_replication_slot(PG_FUNCTION_ARGS) { Name name = PG_GETARG_NAME(0); check_permissions(); CheckSlotRequirements(); ReplicationSlotDrop(NameStr(*name)); PG_RETURN_VOID(); }
int lua_apr_file_append(lua_State *L) { const char *source, *target; apr_fileperms_t permissions; apr_status_t status; source = luaL_checkstring(L, 1); target = luaL_checkstring(L, 2); permissions = check_permissions(L, 3, 1); status = apr_file_append(source, target, permissions, to_pool(L)); return push_status(L, status); }
/* * SQL function for creating a new physical (streaming replication) * replication slot. */ Datum pg_create_physical_replication_slot(PG_FUNCTION_ARGS) { Name name = PG_GETARG_NAME(0); bool immediately_reserve = PG_GETARG_BOOL(1); Datum values[2]; bool nulls[2]; TupleDesc tupdesc; HeapTuple tuple; Datum result; Assert(!MyReplicationSlot); if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); check_permissions(); CheckSlotRequirements(); /* acquire replication slot, this will check for conflicting names */ ReplicationSlotCreate(NameStr(*name), false, RS_PERSISTENT); values[0] = NameGetDatum(&MyReplicationSlot->data.name); nulls[0] = false; if (immediately_reserve) { /* Reserve WAL as the user asked for it */ ReplicationSlotReserveWal(); /* Write this slot to disk */ ReplicationSlotMarkDirty(); ReplicationSlotSave(); values[1] = LSNGetDatum(MyReplicationSlot->data.restart_lsn); nulls[1] = false; } else { values[0] = NameGetDatum(&MyReplicationSlot->data.name); nulls[1] = true; } tuple = heap_form_tuple(tupdesc, values, nulls); result = HeapTupleGetDatum(tuple); ReplicationSlotRelease(); PG_RETURN_DATUM(result); }
static void handle_read_req(struct bt_gatt_server *server, uint8_t opcode, uint16_t handle, uint16_t offset) { struct gatt_db_attribute *attr; uint8_t ecode; struct async_read_op *op = NULL; ecode = authorize_req(server, opcode, handle); if (ecode) goto error; attr = gatt_db_get_attribute(server->db, handle); if (!attr) { ecode = BT_ATT_ERROR_INVALID_HANDLE; goto error; } util_debug(server->debug_callback, server->debug_data, "Read %sReq - handle: 0x%04x", opcode == BT_ATT_OP_READ_BLOB_REQ ? "Blob " : "", handle); ecode = check_permissions(server, attr, BT_ATT_PERM_READ | BT_ATT_PERM_READ_AUTHEN | BT_ATT_PERM_READ_ENCRYPT); if (ecode) goto error; if (server->pending_read_op) { ecode = BT_ATT_ERROR_UNLIKELY; goto error; } op = new0(struct async_read_op, 1); op->opcode = opcode; op->server = server; server->pending_read_op = op; if (gatt_db_attribute_read(attr, offset, opcode, server->att, read_complete_cb, op)) return; ecode = BT_ATT_ERROR_UNLIKELY; error: if (op) async_read_op_destroy(op); bt_att_send_error_rsp(server->att, opcode, handle, ecode); }
int lua_apr_dir_make_recursive(lua_State *L) { apr_status_t status; apr_pool_t *memory_pool; const char *filepath; apr_fileperms_t permissions; memory_pool = to_pool(L); filepath = luaL_checkstring(L, 1); permissions = check_permissions(L, 2, 0); status = apr_dir_make_recursive(filepath, permissions, memory_pool); return push_status(L, status); }
static void prep_write_cb(uint8_t opcode, const void *pdu, uint16_t length, void *user_data) { struct bt_gatt_server *server = user_data; uint16_t handle = 0; uint16_t offset; struct gatt_db_attribute *attr; uint8_t ecode; if (length < 4) { ecode = BT_ATT_ERROR_INVALID_PDU; goto error; } if (queue_length(server->prep_queue) >= server->max_prep_queue_len) { ecode = BT_ATT_ERROR_PREPARE_QUEUE_FULL; goto error; } handle = get_le16(pdu); offset = get_le16(pdu + 2); attr = gatt_db_get_attribute(server->db, handle); if (!attr) { ecode = BT_ATT_ERROR_INVALID_HANDLE; goto error; } util_debug(server->debug_callback, server->debug_data, "Prep Write Req - handle: 0x%04x", handle); ecode = check_permissions(server, attr, BT_ATT_PERM_WRITE | BT_ATT_PERM_WRITE_AUTHEN | BT_ATT_PERM_WRITE_ENCRYPT); if (ecode) goto error; if (!store_prep_data(server, handle, offset, length - 4, &((uint8_t *) pdu)[4])) { ecode = BT_ATT_ERROR_INSUFFICIENT_RESOURCES; goto error; } bt_att_send(server->att, BT_ATT_OP_PREP_WRITE_RSP, pdu, length, NULL, NULL, NULL); return; error: bt_att_send_error_rsp(server->att, opcode, handle, ecode); }
bool Filesystem::rm( const QString& path, bool recursive ) { if ( check_permissions( path, is_file, true ) ) { QFile file( path ); bool ret = file.remove(); if( !ret ) { ERRORLOG( QString( "unable to remove file %1" ).arg( path ) ); } return ret; } if ( !check_permissions( path, is_dir, true ) ) { ERRORLOG( QString( "%1 is neither a file nor a directory ?!?!" ).arg( path ) ); return false; } if ( !recursive ) { QDir dir; bool ret = dir.rmdir( path ); if( !ret ) { ERRORLOG( QString( "unable to remove dir %1 without recursive argument, maybe it is not empty?" ).arg( path ) ); } return ret; } return rm_fr( path ); }
void logical_file_cpi_impl::sync_update_location(saga::impl::void_t& ret, saga::url oldlocation, saga::url newlocation) { adaptor_data_t adaptorData(this); instance_data instanceData (this); saga::url lfn_url(instanceData->location_); this->check_if_open ("logical_file_cpi_impl::sync_update_location", instanceData->location_); check_permissions(saga::replica::Write, "update_location", lfn_url.get_url()); bool oldExists = false; // worst case - update will fail bool newExists = true; // SAGA_OSSTREAM strm; strm << "Could not update location for logical file [" << instanceData->location_ << "]. "; try { RLSConnection * RLSHandle = adaptorData->getConnectionHandle(instanceData->location_); oldExists = RLSHandle->LFNtoPFNMappingExists(lfn_url.get_path(), oldlocation.get_url()); newExists = RLSHandle->LFNtoPFNMappingExists(lfn_url.get_path(), newlocation.get_url()); } catch(globus_rls_replica_adaptor::exception const & e) { strm << e.RLSErrorText(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), e.SAGAError()); } if(!oldExists) { strm << "PFN: [" << oldlocation << "] doesn't exist!"; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::DoesNotExist); } if(newExists) { strm << "PFN: [" << newlocation << "] already exist!"; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::AlreadyExists); } // everyting seems to be ok. let's update the LFN sync_add_location(ret, newlocation); sync_remove_location(ret, oldlocation); }
static dbus_bool_t check_dbus_user (BusConfigParser *parser, DBusError *error) { const char *dbus_user; dbus_user = bus_config_parser_get_user (parser); if (dbus_user == NULL) { dbus_set_error (error, DBUS_ERROR_SPAWN_CONFIG_INVALID, "could not get user from config file\n"); return FALSE; } /* check to see if permissions are correct */ if (!check_permissions (dbus_user, error)) return FALSE; return TRUE; }
void logical_file_cpi_impl::sync_remove_location(saga::impl::void_t&, saga::url location) { adaptor_data_t adaptorData(this); instance_data instanceData (this); saga::url lfn_url(instanceData->location_); this->check_if_open ("logical_file_cpi_impl::sync_remove_location", instanceData->location_); check_permissions(saga::replica::Write, "remove_location", lfn_url.get_url()); try { RLSConnection * RLSHandle = adaptorData->getConnectionHandle(instanceData->location_); RLSHandle->LFNRemovePFN(lfn_url.get_path(), location.get_url()); } catch(globus_rls_replica_adaptor::exception const & e) { SAGA_OSSTREAM strm; strm << "Could not remove location from logical file [" << instanceData->location_ << "]. " << e.RLSErrorText(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), e.SAGAError()); } }
/* * Helper function for the various SQL callable logical decoding functions. */ static Datum pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool binary) { Name name; XLogRecPtr upto_lsn; int32 upto_nchanges; ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; MemoryContext per_query_ctx; MemoryContext oldcontext; XLogRecPtr end_of_wal; XLogRecPtr startptr; LogicalDecodingContext *ctx; ResourceOwner old_resowner = CurrentResourceOwner; ArrayType *arr; Size ndim; List *options = NIL; DecodingOutputState *p; check_permissions(); CheckLogicalDecodingRequirements(); if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("slot name must not be null"))); name = PG_GETARG_NAME(0); if (PG_ARGISNULL(1)) upto_lsn = InvalidXLogRecPtr; else upto_lsn = PG_GETARG_LSN(1); if (PG_ARGISNULL(2)) upto_nchanges = InvalidXLogRecPtr; else upto_nchanges = PG_GETARG_INT32(2); if (PG_ARGISNULL(3)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("options array must not be null"))); arr = PG_GETARG_ARRAYTYPE_P(3); /* check to see if caller supports us returning a tuplestore */ if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("set-valued function called in context that cannot accept a set"))); if (!(rsinfo->allowedModes & SFRM_Materialize)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("materialize mode required, but it is not allowed in this context"))); /* state to write output to */ p = palloc0(sizeof(DecodingOutputState)); p->binary_output = binary; /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &p->tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); per_query_ctx = rsinfo->econtext->ecxt_per_query_memory; oldcontext = MemoryContextSwitchTo(per_query_ctx); /* Deconstruct options array */ ndim = ARR_NDIM(arr); if (ndim > 1) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array must be one-dimensional"))); } else if (array_contains_nulls(arr)) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array must not contain nulls"))); } else if (ndim == 1) { int nelems; Datum *datum_opts; int i; Assert(ARR_ELEMTYPE(arr) == TEXTOID); deconstruct_array(arr, TEXTOID, -1, false, 'i', &datum_opts, NULL, &nelems); if (nelems % 2 != 0) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array must have even number of elements"))); for (i = 0; i < nelems; i += 2) { char *name = TextDatumGetCString(datum_opts[i]); char *opt = TextDatumGetCString(datum_opts[i + 1]); options = lappend(options, makeDefElem(name, (Node *) makeString(opt), -1)); } } p->tupstore = tuplestore_begin_heap(true, false, work_mem); rsinfo->returnMode = SFRM_Materialize; rsinfo->setResult = p->tupstore; rsinfo->setDesc = p->tupdesc; /* * Compute the current end-of-wal and maintain ThisTimeLineID. * RecoveryInProgress() will update ThisTimeLineID on promotion. */ if (!RecoveryInProgress()) end_of_wal = GetFlushRecPtr(); else end_of_wal = GetXLogReplayRecPtr(&ThisTimeLineID); ReplicationSlotAcquire(NameStr(*name), true); PG_TRY(); { /* restart at slot's confirmed_flush */ ctx = CreateDecodingContext(InvalidXLogRecPtr, options, false, logical_read_local_xlog_page, LogicalOutputPrepareWrite, LogicalOutputWrite, NULL); MemoryContextSwitchTo(oldcontext); /* * Check whether the output plugin writes textual output if that's * what we need. */ if (!binary && ctx->options.output_type !=OUTPUT_PLUGIN_TEXTUAL_OUTPUT) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("logical decoding output plugin \"%s\" produces binary output, but function \"%s\" expects textual data", NameStr(MyReplicationSlot->data.plugin), format_procedure(fcinfo->flinfo->fn_oid)))); ctx->output_writer_private = p; /* * Decoding of WAL must start at restart_lsn so that the entirety of * xacts that committed after the slot's confirmed_flush can be * accumulated into reorder buffers. */ startptr = MyReplicationSlot->data.restart_lsn; CurrentResourceOwner = ResourceOwnerCreate(CurrentResourceOwner, "logical decoding"); /* invalidate non-timetravel entries */ InvalidateSystemCaches(); /* Decode until we run out of records */ while ((startptr != InvalidXLogRecPtr && startptr < end_of_wal) || (ctx->reader->EndRecPtr != InvalidXLogRecPtr && ctx->reader->EndRecPtr < end_of_wal)) { XLogRecord *record; char *errm = NULL; record = XLogReadRecord(ctx->reader, startptr, &errm); if (errm) elog(ERROR, "%s", errm); /* * Now that we've set up the xlog reader state, subsequent calls * pass InvalidXLogRecPtr to say "continue from last record" */ startptr = InvalidXLogRecPtr; /* * The {begin_txn,change,commit_txn}_wrapper callbacks above will * store the description into our tuplestore. */ if (record != NULL) LogicalDecodingProcessRecord(ctx, ctx->reader); /* check limits */ if (upto_lsn != InvalidXLogRecPtr && upto_lsn <= ctx->reader->EndRecPtr) break; if (upto_nchanges != 0 && upto_nchanges <= p->returned_rows) break; CHECK_FOR_INTERRUPTS(); } tuplestore_donestoring(tupstore); CurrentResourceOwner = old_resowner; /* * Next time, start where we left off. (Hunting things, the family * business..) */ if (ctx->reader->EndRecPtr != InvalidXLogRecPtr && confirm) { LogicalConfirmReceivedLocation(ctx->reader->EndRecPtr); /* * If only the confirmed_flush_lsn has changed the slot won't get * marked as dirty by the above. Callers on the walsender * interface are expected to keep track of their own progress and * don't need it written out. But SQL-interface users cannot * specify their own start positions and it's harder for them to * keep track of their progress, so we should make more of an * effort to save it for them. * * Dirty the slot so it's written out at the next checkpoint. * We'll still lose its position on crash, as documented, but it's * better than always losing the position even on clean restart. */ ReplicationSlotMarkDirty(); } /* free context, call shutdown callback */ FreeDecodingContext(ctx); ReplicationSlotRelease(); InvalidateSystemCaches(); } PG_CATCH(); { /* clear all timetravel entries */ InvalidateSystemCaches(); PG_RE_THROW(); } PG_END_TRY(); return (Datum) 0; }
/* return the fd of a local copy, to operate on */ int dfs_get_local_copy(pentry_t *pe, const char * const remote, int flags) { int fd; dpl_dict_t *metadata = NULL; dpl_dict_t *headers = NULL; struct get_data get_data = { .fd = -1, .buf = NULL }; dpl_status_t rc = DPL_FAILURE; char *local = NULL; unsigned encryption = 0; local = tmpstr_printf("%s%s", conf->cache_dir, remote); LOG(LOG_DEBUG, "bucket=%s, path=%s, local=%s", ctx->cur_bucket, remote, local); if (-1 == download_headers((char *)remote, &headers)) { LOG(LOG_NOTICE, "%s: can't download headers", remote); fd = -1; goto end; } metadata = dpl_dict_new(13); if (! metadata) { LOG(LOG_ERR, "dpl_dict_new: can't allocate memory"); fd = -1; goto end; } if (DPL_FAILURE == dpl_get_metadata_from_headers( #if defined(DPL_VERSION_MAJOR) && defined(DPL_VERSION_MINOR) && (DPL_VERSION_MAJOR == 0 && DPL_VERSION_MINOR >= 2) || (DPL_VERSION_MAJOR > 0) ctx, #endif headers, metadata)) { LOG(LOG_ERR, "%s: metadata extraction failed", remote); fd = -1; goto end; } if (-1 == pentry_set_metadata(pe, metadata)) { LOG(LOG_ERR, "can't update metadata"); fd = -1; goto end; } if (-1 == check_permissions(pe, metadata)) { LOG(LOG_NOTICE, "permission denied"); fd = -1; goto end; } /* If the remote MD5 matches a cache file, we don't have to download * it again, just return the (open) file descriptor of the cache file */ if (0 == compare_digests(pe, headers)) { fd = pentry_get_fd(pe); goto end; } /* a cache file already exists, its MD5 digest is different, so * just remove it */ if (0 == access(local, F_OK)) { LOG(LOG_DEBUG, "removing cache file '%s'", local); if (-1 == unlink(local)) LOG(LOG_ERR, "unlink(%s): %s", local, strerror(errno)); } get_data.fd = open(local, O_RDWR|O_CREAT|O_TRUNC, 0600); if (-1 == get_data.fd) { LOG(LOG_ERR, "open: %s: %s (%d)", local, strerror(errno), errno); fd = -1; goto end; } encryption = check_encryption_flag(metadata); rc = dpl_openread(ctx, (char *)remote, encryption, NULL, cb_get_buffered, &get_data, &metadata); if (DPL_SUCCESS != rc) { LOG(LOG_ERR, "dpl_openread: %s", dpl_status_str(rc)); close(get_data.fd); fd = -1; goto end; } /* If the file is compressed, uncompress it! */ if(-1 == handle_compression(remote, local, &get_data, metadata)) { fd = -1; goto end; } if (-1 == close(get_data.fd)) { LOG(LOG_ERR, "close(path=%s, fd=%d): %s", local, get_data.fd, strerror(errno)); fd = -1; goto end; } fd = open(local, flags, 0600); if (-1 == fd) { LOG(LOG_ERR, "open(path=%s, fd=%d): %s", local, fd, strerror(errno)); fd = -1; goto end; } end: if (metadata) dpl_dict_free(metadata); if (headers) dpl_dict_free(headers); return fd; }
bool FileRingBuffer::OpenFile(const QString &lfilename, uint retry_ms) { LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("OpenFile(%1, %2 ms)") .arg(lfilename).arg(retry_ms)); rwlock.lockForWrite(); filename = lfilename; if (remotefile) { delete remotefile; remotefile = NULL; } if (fd2 >= 0) { close(fd2); fd2 = -1; } bool is_local = (filename.left(4) != "/dev") && ((filename.left(1) == "/") || QFile::exists(filename)); if (is_local) { char buf[kReadTestSize]; int lasterror = 0; MythTimer openTimer; openTimer.start(); uint openAttempts = 0; do { openAttempts++; lasterror = 0; fd2 = open(filename.toLocal8Bit().constData(), O_RDONLY|O_LARGEFILE|O_STREAMING|O_BINARY); if (fd2 < 0) { if (!check_permissions(filename)) { lasterror = 3; break; } lasterror = 1; usleep(10 * 1000); } else { int ret = read(fd2, buf, kReadTestSize); if (ret != (int)kReadTestSize) { lasterror = 2; close(fd2); fd2 = -1; if (oldfile) break; // if it's an old file it won't grow.. usleep(10 * 1000); } else { if (0 == lseek(fd2, 0, SEEK_SET)) { posix_fadvise(fd2, 0, 0, POSIX_FADV_SEQUENTIAL); posix_fadvise(fd2, 0, 128*1024, POSIX_FADV_WILLNEED); lasterror = 0; break; } lasterror = 4; close(fd2); fd2 = -1; } } } while ((uint)openTimer.elapsed() < retry_ms); switch (lasterror) { case 0: { QFileInfo fi(filename); oldfile = fi.lastModified() .secsTo(QDateTime::currentDateTime()) > 60; QString extension = fi.completeSuffix().toLower(); if (is_subtitle_possible(extension)) subtitlefilename = local_sub_filename(fi); break; } case 1: LOG(VB_GENERAL, LOG_ERR, LOC + QString("OpenFile(): Could not open.")); break; case 2: LOG(VB_GENERAL, LOG_ERR, LOC + QString("OpenFile(): File too small (%1B).") .arg(QFileInfo(filename).size())); break; case 3: LOG(VB_GENERAL, LOG_ERR, LOC + "OpenFile(): Improper permissions."); break; case 4: LOG(VB_GENERAL, LOG_ERR, LOC + "OpenFile(): Cannot seek in file."); break; default: break; } LOG(VB_FILE, LOG_INFO, LOC + QString("OpenFile() made %1 attempts in %2 ms") .arg(openAttempts).arg(openTimer.elapsed())); } else { QString tmpSubName = filename; QString dirName = "."; int dirPos = filename.lastIndexOf(QChar('/')); if (dirPos > 0) { tmpSubName = filename.mid(dirPos + 1); dirName = filename.left(dirPos); } QString baseName = tmpSubName; QString extension = tmpSubName; QStringList auxFiles; int suffixPos = tmpSubName.lastIndexOf(QChar('.')); if (suffixPos > 0) { baseName = tmpSubName.left(suffixPos); extension = tmpSubName.right(suffixPos-1); if (is_subtitle_possible(extension)) { QMutexLocker locker(&subExtLock); QStringList::const_iterator eit = subExt.begin(); for (; eit != subExt.end(); ++eit) auxFiles += baseName + *eit; } } remotefile = new RemoteFile(filename, false, true, retry_ms, &auxFiles); if (!remotefile->isOpen()) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("RingBuffer::RingBuffer(): Failed to open remote " "file (%1)").arg(filename)); delete remotefile; remotefile = NULL; } else { QStringList aux = remotefile->GetAuxiliaryFiles(); if (aux.size()) subtitlefilename = dirName + "/" + aux[0]; } } setswitchtonext = false; ateof = false; commserror = false; numfailures = 0; rawbitrate = 8000; CalcReadAheadThresh(); bool ok = fd2 >= 0 || remotefile; rwlock.unlock(); return ok; }
static void read_multiple_complete_cb(struct gatt_db_attribute *attr, int err, const uint8_t *value, size_t len, void *user_data) { struct read_multiple_resp_data *data = user_data; struct gatt_db_attribute *next_attr; uint16_t handle = gatt_db_attribute_get_handle(attr); uint8_t ecode; if (err != 0) { bt_att_send_error_rsp(data->server->att, BT_ATT_OP_READ_MULT_REQ, handle, err); read_multiple_resp_data_free(data); return; } ecode = check_permissions(data->server, attr, BT_ATT_PERM_READ | BT_ATT_PERM_READ_AUTHEN | BT_ATT_PERM_READ_ENCRYPT); if (ecode) { bt_att_send_error_rsp(data->server->att, BT_ATT_OP_READ_MULT_REQ, handle, ecode); read_multiple_resp_data_free(data); return; } len = MIN(len, data->mtu - data->length - 1); memcpy(data->rsp_data + data->length, value, len); data->length += len; data->cur_handle++; if ((data->length >= data->mtu - 1) || (data->cur_handle == data->num_handles)) { bt_att_send(data->server->att, BT_ATT_OP_READ_MULT_RSP, data->rsp_data, data->length, NULL, NULL, NULL); read_multiple_resp_data_free(data); return; } util_debug(data->server->debug_callback, data->server->debug_data, "Read Multiple Req - #%zu of %zu: 0x%04x", data->cur_handle + 1, data->num_handles, data->handles[data->cur_handle]); next_attr = gatt_db_get_attribute(data->server->db, data->handles[data->cur_handle]); if (!next_attr) { bt_att_send_error_rsp(data->server->att, BT_ATT_OP_READ_MULT_REQ, data->handles[data->cur_handle], BT_ATT_ERROR_INVALID_HANDLE); read_multiple_resp_data_free(data); return; } if (!gatt_db_attribute_read(next_attr, 0, BT_ATT_OP_READ_MULT_REQ, data->server->att, read_multiple_complete_cb, data)) { bt_att_send_error_rsp(data->server->att, BT_ATT_OP_READ_MULT_REQ, data->handles[data->cur_handle], BT_ATT_ERROR_UNLIKELY); read_multiple_resp_data_free(data); } }
bool Filesystem::dir_writable( const QString& path, bool silent ) { return check_permissions( path, is_dir|is_writable, silent ); }
static int extract_cb (GtkWidget *w, DialogData *data) { FrWindow *window = data->window; gboolean do_not_extract = FALSE; char *extract_to_dir; gboolean overwrite; gboolean skip_newer; gboolean selected_files; gboolean pattern_files; gboolean junk_paths; GList *file_list; char *base_dir = NULL; GError *error = NULL; data->extract_clicked = TRUE; /* collect extraction options. */ extract_to_dir = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (data->dialog)); /* check directory existence. */ if (! uri_is_dir (extract_to_dir)) { if (! ForceDirectoryCreation) { GtkWidget *d; int r; char *folder_name; char *msg; folder_name = g_filename_display_name (extract_to_dir); msg = g_strdup_printf (_("Destination folder \"%s\" does not exist.\n\nDo you want to create it?"), folder_name); g_free (folder_name); d = _gtk_message_dialog_new (GTK_WINDOW (data->dialog), GTK_DIALOG_MODAL, GTK_STOCK_DIALOG_QUESTION, msg, NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("Create _Folder"), GTK_RESPONSE_YES, NULL); gtk_dialog_set_default_response (GTK_DIALOG (d), GTK_RESPONSE_YES); r = gtk_dialog_run (GTK_DIALOG (d)); gtk_widget_destroy (GTK_WIDGET (d)); g_free (msg); if (r != GTK_RESPONSE_YES) do_not_extract = TRUE; } if (! do_not_extract && ! ensure_dir_exists (extract_to_dir, 0755, &error)) { GtkWidget *d; d = _gtk_error_dialog_new (GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, NULL, _("Extraction not performed"), _("Could not create the destination folder: %s."), error->message); gtk_dialog_run (GTK_DIALOG (d)); gtk_widget_destroy (GTK_WIDGET (d)); g_error_free (error); return FALSE; } } if (do_not_extract) { GtkWidget *d; d = _gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_DIALOG_WARNING, _("Extraction not performed"), NULL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (d), GTK_RESPONSE_OK); gtk_dialog_run (GTK_DIALOG (d)); gtk_widget_destroy (GTK_WIDGET (d)); if (fr_window_is_batch_mode (data->window)) gtk_widget_destroy (data->dialog); return FALSE; } /* check extraction directory permissions. */ if (uri_is_dir (extract_to_dir) && ! check_permissions (extract_to_dir, R_OK | W_OK)) { GtkWidget *d; char *utf8_path; utf8_path = g_filename_display_name (extract_to_dir); d = _gtk_error_dialog_new (GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, NULL, _("Extraction not performed"), _("You don't have the right permissions to extract archives in the folder \"%s\""), utf8_path); gtk_dialog_run (GTK_DIALOG (d)); gtk_widget_destroy (GTK_WIDGET (d)); g_free (utf8_path); g_free (extract_to_dir); return FALSE; } fr_window_set_extract_default_dir (window, extract_to_dir, TRUE); overwrite = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->e_overwrite_checkbutton)); skip_newer = ! gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (data->e_not_newer_checkbutton)) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->e_not_newer_checkbutton)); junk_paths = ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->e_recreate_dir_checkbutton)); g_settings_set_boolean (data->settings, PREF_EXTRACT_OVERWRITE, overwrite); if (! gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (data->e_not_newer_checkbutton))) g_settings_set_boolean (data->settings, PREF_EXTRACT_SKIP_NEWER, skip_newer); g_settings_set_boolean (data->settings, PREF_EXTRACT_RECREATE_FOLDERS, ! junk_paths); selected_files = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->e_selected_radiobutton)); pattern_files = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->e_files_radiobutton)); /* create the file list. */ file_list = NULL; if (selected_files) { file_list = data->selected_files; data->selected_files = NULL; /* do not the list when destroying the dialog. */ } else if (pattern_files) { const char *pattern; pattern = gtk_entry_get_text (GTK_ENTRY (data->e_files_entry)); file_list = fr_window_get_file_list_pattern (window, pattern); if (file_list == NULL) { gtk_widget_destroy (data->dialog); g_free (extract_to_dir); return FALSE; } } if (selected_files) { base_dir = data->base_dir_for_selection; data->base_dir_for_selection = NULL; } else base_dir = NULL; /* close the dialog. */ gtk_widget_destroy (data->dialog); /* extract ! */ fr_window_archive_extract (window, file_list, extract_to_dir, base_dir, skip_newer, overwrite ? FR_OVERWRITE_YES : FR_OVERWRITE_NO, junk_paths, TRUE); path_list_free (file_list); g_free (extract_to_dir); g_free (base_dir); return TRUE; }
int main(int argc, char *argv[]) { ext2_ino_t inode; struct ext2_inode *inode_buf; struct ext2_inode_large *large_inode; int retval; char *fs; if (argc != 2) { fprintf(stderr, "Usage: crtime <file>\n"); return -1; } retval = check_permissions(argv[1]); if (retval) { return retval; } retval = get_inode(argv[1], &inode); if (retval) { return retval; } retval = get_fs_name(argv[1], &fs); if (retval) { return retval; } retval = open_filesystem(fs); if (retval) { free(fs); return retval; } inode_buf = (struct ext2_inode *)malloc(EXT2_INODE_SIZE(current_fs->super)); if (!inode_buf) { free(fs); fprintf(stderr, "Failed to allocate memory\n"); return -1; } retval = ext2fs_read_inode_full(current_fs, inode, inode_buf, EXT2_INODE_SIZE(current_fs->super)); if (retval) { fprintf(stderr, "Failed to read inode\n"); free(fs); free(inode_buf); return retval; } if (EXT2_INODE_SIZE(current_fs->super) <= EXT2_GOOD_OLD_INODE_SIZE) { free(fs); free(inode_buf); fprintf(stderr, "Create time unavailable"); return -1; } large_inode = (struct ext2_inode_large *)inode_buf; if (large_inode->i_extra_isize < 24) { free(fs); free(inode_buf); fprintf(stderr, "Create time unavailable"); return -1; } printf("%d\n", large_inode->i_crtime); free(fs); free(inode_buf); ext2fs_close(current_fs); return 0; }
static int file_sel_response_cb (GtkWidget *widget, int response, DialogData *data) { GtkFileChooser *file_sel = GTK_FILE_CHOOSER (widget); FrWindow *window = data->window; char *selected_folder; gboolean update, UNUSED_VARIABLE recursive, follow_links; const char *include_files; const char *exclude_files; const char *exclude_folders; char *dest_dir; char *local_filename; dlg_add_folder_save_last_options (data); if ((response == GTK_RESPONSE_CANCEL) || (response == GTK_RESPONSE_DELETE_EVENT)) { gtk_widget_destroy (data->dialog); return TRUE; } if (response == GTK_RESPONSE_HELP) { show_help_dialog (GTK_WINDOW (data->dialog), "engrampa-add-options"); return TRUE; } selected_folder = gtk_file_chooser_get_uri (file_sel); /* check folder permissions. */ if (! check_permissions (selected_folder, R_OK)) { GtkWidget *d; char *utf8_path; utf8_path = g_filename_display_name (selected_folder); d = _gtk_error_dialog_new (GTK_WINDOW (window), GTK_DIALOG_MODAL, NULL, _("Could not add the files to the archive"), _("You don't have the right permissions to read files from folder \"%s\""), utf8_path); gtk_dialog_run (GTK_DIALOG (d)); gtk_widget_destroy (GTK_WIDGET (d)); g_free (utf8_path); g_free (selected_folder); return FALSE; } update = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->add_if_newer_checkbutton)); recursive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->include_subfold_checkbutton)); follow_links = ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->exclude_symlinks)); include_files = gtk_entry_get_text (GTK_ENTRY (data->include_files_entry)); if (utf8_only_spaces (include_files)) include_files = "*"; exclude_files = gtk_entry_get_text (GTK_ENTRY (data->exclude_files_entry)); if (utf8_only_spaces (exclude_files)) exclude_files = NULL; exclude_folders = gtk_entry_get_text (GTK_ENTRY (data->exclude_folders_entry)); if (utf8_only_spaces (exclude_folders)) exclude_folders = NULL; local_filename = g_filename_from_uri (selected_folder, NULL, NULL); dest_dir = build_uri (fr_window_get_current_location (window), file_name_from_path (local_filename), NULL); fr_window_archive_add_with_wildcard (window, include_files, exclude_files, exclude_folders, selected_folder, dest_dir, update, follow_links); g_free (local_filename); g_free (dest_dir); g_free (selected_folder); gtk_widget_destroy (data->dialog); return TRUE; }
void TestAuth::testCheckPermissions() { // prepare exports const char *correct_exports[] = { "/dev *", // 0 "/var 127.0.0.1", // 1 "/etc root", // 2 "/mnt 127.0.0.1, root", // 3 "/boot 127.0.0.0/24", // 4 "/tmp [email protected]/24" // 5 "/tmp *@127.0.0.1/24" // 6 #ifdef WITH_IPV6 "/home ::/0", // 7 #endif }; const size_t correct_count = sizeof(correct_exports) / sizeof(correct_exports[0]); std::ofstream stream; stream.open(exportsfile, std::ios_base::out | std::ios_base::trunc); CPPUNIT_ASSERT(stream.is_open()); for (size_t i = 0; i < correct_count; ++i) { stream << correct_exports[i] << std::endl; } stream.close(); CPPUNIT_ASSERT(!stream.fail()); CPPUNIT_ASSERT(parse_exports(exportsfile, &m_instance.exports.list, 0) == 0); const struct rfs_list *export_rec = m_instance.exports.list; unsigned export_no = 0; while (export_rec != NULL) { const struct rfs_export *info = static_cast<const struct rfs_export *>(export_rec->data); switch (export_no) { // /dev * case 0: #ifdef WITH_IPV6 CPPUNIT_ASSERT(check_permissions(&m_instance, info, "::1") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "::ffff:127.0.0.1") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "::ffff:192.168.0.1") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "::ffff:8.8.8.8") == 0); #endif CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "192.168.0.1") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "8.8.8.8") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "root") == 0); break; // /var root, 127.0.0.1 case 1: CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.0") != 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.2") != 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") == 0); #ifdef WITH_IPV6 CPPUNIT_ASSERT(check_permissions(&m_instance, info, "::ffff:127.0.0.2") != 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "::ffff:127.0.0.1") == 0); #endif break; // /etc root case 2: CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") == 0); { char *old_user = m_instance.server.auth_user; m_instance.server.auth_user = strdup("notroot"); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") != 0); free(m_instance.server.auth_user); m_instance.server.auth_user = old_user; } break; // /mnt 127.0.0.1, root case 3: CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") == 0); { char *old_user = m_instance.server.auth_user; m_instance.server.auth_user = strdup("notroot"); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") == 0); // user is different, but still can pass by netmask free(m_instance.server.auth_user); m_instance.server.auth_user = old_user; } break; // /boot 127.0.0.0/24 case 4: CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.0") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.2") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.1.1") != 0); break; // /tmp [email protected]/24 case 5: CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.1.1") != 0); { char *old_user = m_instance.server.auth_user; m_instance.server.auth_user = strdup("notroot"); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") != 0); free(m_instance.server.auth_user); m_instance.server.auth_user = old_user; } break; // /tmp *@127.0.0.1/24 case 6: CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.0.1") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "127.0.1.1") != 0); break; #ifdef WITH_IPV6 // /home ::/0" case 7: CPPUNIT_ASSERT(check_permissions(&m_instance, info, "::ffff:127.0.0.1") == 0); CPPUNIT_ASSERT(check_permissions(&m_instance, info, "::1") == 0); break; #endif default: CPPUNIT_ASSERT(false); } ++export_no; export_rec = export_rec->next; } }