6dcde6ca366549264b23e191ff01162f9dd03350David Lawrence/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2004, 2005, 2007, 2012, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6dcde6ca366549264b23e191ff01162f9dd03350David Lawrence */
6dcde6ca366549264b23e191ff01162f9dd03350David Lawrence
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: fsaccess_test.c,v 1.13 2007/06/19 23:46:59 tbox Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
ae302c18c296f31c02efb613887f206894caa749David Lawrence
ae302c18c296f31c02efb613887f206894caa749David Lawrence#include <config.h>
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence#include <stdio.h>
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews#include <stdlib.h>
cb761bbd5f9c73473327ff6e1b9626b02b4e51f8Mark Andrews#include <errno.h>
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence
0a7a0e19c46131526531ee0c60b34ccd1792fab0David Lawrence#include <sys/types.h> /* Non-portable. */
0a7a0e19c46131526531ee0c60b34ccd1792fab0David Lawrence#include <sys/stat.h> /* Non-portable. */
0a7a0e19c46131526531ee0c60b34ccd1792fab0David Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence#include <isc/fsaccess.h>
3759f10fc543747668b1ca4b4671f35b0dea8445Francis Dupont#include <isc/print.h>
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence#include <isc/result.h>
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence#define PATH "/tmp/fsaccess"
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrenceint
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrencemain(void) {
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence isc_fsaccess_t access;
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence isc_result_t result;
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews FILE *fp;
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews int n;
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews n = remove(PATH);
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews if (n != 0 && errno != ENOENT) {
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews fprintf(stderr, "unable to remove(%s)\n", PATH);
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews exit(1);
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews }
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews fp = fopen(PATH, "w");
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews if (fp == NULL) {
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews fprintf(stderr, "unable to fopen(%s)\n", PATH);
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews exit(1);
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews }
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews n = chmod(PATH, 0);
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews if (n != 0) {
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews fprintf(stderr, "unable chmod(%s, 0)\n", PATH);
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews exit(1);
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews }
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence access = 0;
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence isc_fsaccess_add(ISC_FSACCESS_OWNER | ISC_FSACCESS_GROUP,
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence ISC_FSACCESS_READ | ISC_FSACCESS_WRITE,
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence &access);
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence printf("fsaccess=%d\n", access);
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence isc_fsaccess_add(ISC_FSACCESS_OTHER, ISC_FSACCESS_READ, &access);
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence printf("fsaccess=%d\n", access);
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence result = isc_fsaccess_set(PATH, access);
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence if (result != ISC_R_SUCCESS)
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence fprintf(stderr, "result = %s\n", isc_result_totext(result));
f83542787f882444d2abf9fcaf47a34c29e4fec2Mark Andrews (void)fclose(fp);
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence return (0);
a904de0bc85cc3974a87a32deedb69d6a68ec36cDavid Lawrence}