From: John Darrington Date: Tue, 16 Nov 2004 05:25:48 +0000 (+0000) Subject: Added the permissions command. X-Git-Tag: v0.4.0~229 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=b016884ff112ca57e89f9d0298eb70079fece20d Added the permissions command. --- diff --git a/doc/ChangeLog b/doc/ChangeLog index 69ae8331..c674017b 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,10 @@ +Tue Nov 16 13:18:53 WST 2004 John Darrington + + * utilities.texi Added documentation for the PERMISSIONS command. + + * pspp.texinfo Makefile.am @included version.texi (Autogenerated) to + keep the EDITION, VERSION and UPDATED flags up to date. + Tue Nov 9 09:38:43 WST 2004 John Darrington * Made Makefile.am aware of pspp.texi dependencies diff --git a/doc/Makefile.am b/doc/Makefile.am index d7b1dd08..eb2aabc6 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -2,7 +2,7 @@ info_TEXINFOS = pspp.texinfo -pspp_TEXINFOS = \ +pspp_TEXINFOS = version.texi \ bugs.texi \ command-index.texi \ concept-index.texi \ diff --git a/doc/pspp.texinfo b/doc/pspp.texinfo index ebf0381d..5d989e0b 100644 --- a/doc/pspp.texinfo +++ b/doc/pspp.texinfo @@ -3,8 +3,6 @@ @setfilename pspp.info @settitle PSPP @set TIMESTAMP Time-stamp: Sat Oct 30 17:30:39 WST 2004 -@set EDITION 0.21 -@set VERSION 0.31 @c For double-sided printing, uncomment: @c @setchapternewpage odd @c %**end of header @@ -56,6 +54,8 @@ versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. @end ifinfo +@include version.texi + @titlepage @title PSPP @subtitle A System for Statistical Analysis @@ -84,6 +84,7 @@ approved by the Foundation. @contents + @node Top, Introduction, (dir), (dir) @ifinfo @top PSPP diff --git a/doc/utilities.texi b/doc/utilities.texi index db7daa36..1d279f57 100644 --- a/doc/utilities.texi +++ b/doc/utilities.texi @@ -20,6 +20,7 @@ encountered in the input. * FINISH:: Terminate the PSPP session. * HOST:: Temporarily return to the operating system. * INCLUDE:: Include a file within the current one. +* PERMISSIONS:: Change permissions on a file. * QUIT:: Terminate the PSPP session. * SET:: Adjust PSPP runtime parameters. * SHOW:: Display runtime parameters. @@ -169,7 +170,7 @@ to the operating system. This command cannot be used if the SAFER setting is active. -@node INCLUDE, QUIT, HOST, Utilities +@node INCLUDE, PERMISSIONS, HOST, Utilities @section INCLUDE @vindex INCLUDE @vindex @@ @@ -187,7 +188,31 @@ command file. Include files may be nested to any depth, up to the limit of available memory. -@node QUIT, SET, INCLUDE, Utilities +@node PERMISSIONS, QUIT, INCLUDE, Utilities +@comment node-name, next, previous, up +@section PERMISSIONS +@vindex PERMISSIONS +@cindex mode +@cindex file mode +@cindex changing file permissions + +@display +PERMISSIONS + FILE='filename' + /PERMISSIONS = @{READONLY,WRITEABLE@}. +@end display + +@cmd{PERMISSIONS} changes the permissions of a file. +There is one mandatory subcommand which specifies the permissions to +which the file should be changed. +If you set a file's permission to READONLY, then the file will become +unwritable either by you or anyone else on the system. +If you set the permission to WRITEABLE, then the file will become +writeable by you; the permissions afforded to others will be +unchanged. + + +@node QUIT, SET, PERMISSIONS, Utilities @section QUIT @vindex QUIT diff --git a/src/ChangeLog b/src/ChangeLog index 1ba99e1a..e4c9c91d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +Tue Nov 16 13:19:18 WST 2004 John Darrington + + * permissions.c command.def Added the PERMISSIONS command + Mon Nov 15 01:33:32 2004 Ben Pfaff * q2c.c: (dump_header) Don't try to emit #includes at very top of diff --git a/src/Makefile.am b/src/Makefile.am index ec5ce0ae..9176897d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -64,7 +64,8 @@ groff-font.c group.c group.h group_proc.h \ hash.c hash.h html.c htmlP.h include.c inpt-pgm.c lexer.c \ lexer.h levene.c levene.h log.h loop.c magic.c magic.h main.c main.h \ matrix-data.c mis-val.c misc.c misc.h modify-vars.c \ -moments.c moments.h numeric.c output.c output.h pfm-read.c pfm-read.h \ +moments.c moments.h numeric.c output.c output.h permissions.c \ +pfm-read.c pfm-read.h \ pfm-write.c pfm-write.h \ pool.c pool.h postscript.c print.c random.c random.h recode.c \ rename-vars.c repeat.c repeat.h sample.c sel-if.c settings.h \ diff --git a/src/cartesian.c b/src/cartesian.c index 34e1a3dd..a2e9fbff 100644 --- a/src/cartesian.c +++ b/src/cartesian.c @@ -160,7 +160,7 @@ write_legend(struct chart *chart, const char *heading, /* Plot a data point */ void -chart_datum(struct chart *ch, int dataset, double x, double y) +chart_datum(struct chart *ch, int dataset UNUSED, double x, double y) { const double x_pos = (x - ch->x_min) * ch->abscissa_scale + ch->data_left ; diff --git a/src/command.def b/src/command.def index b769a838..08eac3ce 100644 --- a/src/command.def +++ b/src/command.def @@ -95,6 +95,7 @@ UNIMPL ("NUMBERED", INIT, INPU, TRAN, PROC) DEFCMD ("NUMERIC", ERRO, INPU, TRAN, TRAN, cmd_numeric) UNIMPL ("UNNUMBERED", INIT, INPU, TRAN, PROC) DEFCMD ("ONEWAY", ERRO, ERRO, PROC, PROC, cmd_oneway) +DEFCMD ("PERMISSIONS", INIT, INPU, TRAN, PROC, cmd_permissions) DEFCMD ("PEARSON CORRELATIONS", ERRO, ERRO, PROC, PROC, cmd_correlations) UNIMPL ("POINT", ERRO, INPU, ERRO, ERRO) UNIMPL ("PRESERVE", INIT, INPU, TRAN, PROC) diff --git a/src/permissions.c b/src/permissions.c new file mode 100644 index 00000000..8737e631 --- /dev/null +++ b/src/permissions.c @@ -0,0 +1,119 @@ +/* PSPP - computes sample statistics. + Copyright (C) 2004 Free Software Foundation, Inc. + Author: John Darrington + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +#include +#include "error.h" +#include +#include +#include +#include +#include + +#include "command.h" +#include "error.h" +#include "lexer.h" +#include "misc.h" +#include "str.h" + + + +enum PER {PER_RO, PER_RW}; + +int change_permissions(const char *filename, enum PER per); + + +/* Parses the PERMISSIONS command. */ +int +cmd_permissions (void) +{ + char *fn = 0; + + lex_match ('/'); + + if (lex_match_id ("FILE")) + lex_match ('='); + + fn = strdup(ds_c_str(&tokstr)); + lex_force_match(T_STRING); + + + lex_match ('/'); + + if ( ! lex_match_id ("PERMISSIONS")) + goto error; + + lex_match('='); + + if ( lex_match_id("READONLY")) + { + if ( ! change_permissions(fn, PER_RO ) ) + goto error; + } + else if ( lex_match_id("WRITEABLE")) + { + if ( ! change_permissions(fn, PER_RW ) ) + goto error; + } + else + { + msg(ME, _("Expecting %s or %s."), "WRITEABLE", "READONLY"); + goto error; + } + + free(fn); + + return CMD_SUCCESS; + + error: + + free(fn); + + return CMD_FAILURE; +} + + + +int +change_permissions(const char *filename, enum PER per) +{ + struct stat buf; + mode_t mode; + + if ( -1 == stat(filename, &buf) ) + { + const int errnum = errno; + msg(ME,_("Cannot stat %s: %s"), filename, strerror(errnum)); + return 0; + } + + if ( per == PER_RW ) + mode = buf.st_mode | S_IWUSR ; + else + mode = buf.st_mode & ~( S_IWOTH | S_IWUSR | S_IWGRP ); + + if ( -1 == chmod(filename, mode)) + + { + const int errnum = errno; + msg(ME,_("Cannot change mode of %s: %s"), filename, strerror(errnum)); + return 0; + } + + return 1; +} diff --git a/tests/Makefile.am b/tests/Makefile.am index a4aa0706..2736d5f2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -18,6 +18,7 @@ TESTS = \ command/oneway.sh \ command/oneway-missing.sh \ command/oneway-with-splits.sh \ + command/permissions.sh \ command/print.sh \ command/sample.sh \ command/sort.sh \ diff --git a/tests/command/permissions.sh b/tests/command/permissions.sh new file mode 100755 index 00000000..960a04ca --- /dev/null +++ b/tests/command/permissions.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +# This program tests the PERMISSIONS command + +TEMPDIR=/tmp/pspp-tst-$$ + +here=`pwd`; + +# ensure that top_srcdir is absolute +cd $top_srcdir; top_srcdir=`pwd` + +export STAT_CONFIG_PATH=$top_srcdir/config + + +cleanup() +{ + rm -rf $TEMPDIR +} + + +fail() +{ + echo $activity + echo FAILED + cleanup; + exit 1; +} + + +no_result() +{ + echo $activity + echo NO RESULT; + cleanup; + exit 2; +} + +pass() +{ + cleanup; + exit 0; +} + +mkdir -p $TEMPDIR + +cd $TEMPDIR + + +activity="Create file" +echo HEllo > foobar +chmod 777 foobar +if [ $? -ne 0 ] ; then no_result ; fi + +activity="Create program" +cat > per.sps < /dev/null +if [ $? -ne 0 ] ; then fail ; fi + + +activity="Create program" +cat > per.sps < /dev/null +if [ $? -ne 0 ] ; then fail ; fi + + + +pass;