X-Git-Url: http://git.madism.org/?a=blobdiff_plain;ds=sidebyside;f=dotlock.c;h=19e2ad6c6b89ef371bf173e11b46c8c6a706be43;hb=3c3c535e5ed1d651c6024b5acf670e217af473f7;hp=eb4ba30e1db13d3baf8e1ed4504fb87490f91ff8;hpb=df70e07e24add1869bcc9b7af2277d9d0c09a281;p=apps%2Fmadmutt.git diff --git a/dotlock.c b/dotlock.c index eb4ba30..19e2ad6 100644 --- a/dotlock.c +++ b/dotlock.c @@ -1,27 +1,11 @@ /* + * Copyright notice from original mutt: * Copyright (C) 1996-2000 Michael R. Elkins * Copyright (C) 1998-2000 Thomas Roessler - * - * 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, USA. - */ - -/* - * This module either be compiled into Mutt, or it can be - * built as a separate program. For building it - * separately, define the DL_STANDALONE preprocessor - * macro. + * + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. */ #if HAVE_CONFIG_H @@ -53,19 +37,11 @@ #include #endif -#ifdef DL_STANDALONE -# include "reldate.h" -#endif - #define MAXLINKS 1024 /* maximum link depth */ -#ifdef DL_STANDALONE - # define LONG_STRING 1024 # define MAXLOCKATTEMPT 5 -# define strfcpy(A,B,C) strncpy (A,B,C), *(A+(C)-1)=0 - # ifdef USE_SETGID # ifdef HAVE_SETEGID @@ -83,23 +59,12 @@ extern int snprintf (char *, size_t, const char *, ...); # endif -#else /* DL_STANDALONE */ - -# ifdef USE_SETGID -# error Do not try to compile dotlock as a mutt module when requiring egid switching! -# endif - -# include "mutt.h" -# include "mx.h" - -#endif /* DL_STANDALONE */ +#include static int DotlockFlags; static int Retry = MAXLOCKATTEMPT; -#ifdef DL_STANDALONE static char *Hostname; -#endif #ifdef USE_SETGID static gid_t UserGid; @@ -111,10 +76,8 @@ static int dotlock_prepare (char *, size_t, const char *, int fd); static int dotlock_check_stats (struct stat *, struct stat *); static int dotlock_dispatch (const char *, int fd); -#ifdef DL_STANDALONE static int dotlock_init_privs (void); static void usage (const char *); -#endif static void dotlock_expand_link (char *, const char *, const char *); static void BEGIN_PRIVILEGED (void); @@ -131,8 +94,6 @@ static int dotlock_unlink (const char *); static int dotlock_lock (const char *); -#ifdef DL_STANDALONE - #define check_flags(a) if (a & DL_FL_ACTIONS) usage (argv[0]) int main (int argc, char **argv) @@ -228,39 +189,6 @@ static int dotlock_init_privs (void) } -#else /* DL_STANDALONE */ - -/* - * This function is intended to be invoked from within - * mutt instead of mx.c's invoke_dotlock (). - */ - -int dotlock_invoke (const char *path, int fd, int flags, int retry) -{ - int currdir; - int r; - - DotlockFlags = flags; - - if ((currdir = open (".", O_RDONLY)) == -1) - return DL_EX_ERROR; - - if (!(DotlockFlags & DL_FL_RETRY) || retry) - Retry = MAXLOCKATTEMPT; - else - Retry = 0; - - r = dotlock_dispatch (path, fd); - - fchdir (currdir); - close (currdir); - - return r; -} - -#endif /* DL_STANDALONE */ - - static int dotlock_dispatch (const char *f, int fd) { char realpath[_POSIX_PATH_MAX]; @@ -336,8 +264,6 @@ static void END_PRIVILEGED (void) #endif } -#ifdef DL_STANDALONE - /* * Usage information. * @@ -347,7 +273,7 @@ static void END_PRIVILEGED (void) static void usage (const char *av0) { - fprintf (stderr, "dotlock [Mutt-ng %s (%s)]\n", VERSION, ReleaseDate); + fprintf (stderr, "dotlock [Mutt-ng %s]\n", VERSION); fprintf (stderr, "usage: %s [-t|-f|-u|-d] [-p] [-r ] file\n", av0); fputs ("\noptions:" @@ -362,8 +288,6 @@ static void usage (const char *av0) exit (DL_EX_ERROR); } -#endif - /* * Access checking: Let's avoid to lock other users' mail * spool files if we aren't permitted to read them. @@ -458,10 +382,10 @@ static int dotlock_prepare (char *bn, size_t l, const char *f, int _fd) dirname = "."; } - if (strlen (basename) + 1 > l) + if (m_strlen(basename) + 1 > l) return -1; - strfcpy (bn, basename, l); + m_strcpy(bn, l, basename); if (chdir (dirname) == -1) return -1; @@ -504,19 +428,19 @@ dotlock_expand_link (char *newpath, const char *path, const char *link) /* link is full path */ if (*link == '/') { - strfcpy (newpath, link, _POSIX_PATH_MAX); + m_strcpy(newpath, _POSIX_PATH_MAX, link); return; } if ((lb = strrchr (path, '/')) == NULL) { /* no path in link */ - strfcpy (newpath, link, _POSIX_PATH_MAX); + m_strcpy(newpath, _POSIX_PATH_MAX, link); return; } len = lb - path + 1; memcpy (newpath, path, len); - strfcpy (newpath + len, link, _POSIX_PATH_MAX - len); + m_strcpy(newpath + len, _POSIX_PATH_MAX - len, link); } @@ -552,14 +476,14 @@ static int dotlock_deference_symlink (char *d, size_t l, const char *path) linkfile[len] = '\0'; dotlock_expand_link (linkpath, pathptr, linkfile); - strfcpy (realpath, linkpath, sizeof (realpath)); + m_strcpy(realpath, sizeof(realpath), linkpath); pathptr = realpath; } else break; } - strfcpy (d, pathptr, l); + m_strcpy(d, l, pathptr); return 0; }