aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-lock-helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'camel/camel-lock-helper.c')
-rw-r--r--camel/camel-lock-helper.c390
1 files changed, 0 insertions, 390 deletions
diff --git a/camel/camel-lock-helper.c b/camel/camel-lock-helper.c
deleted file mode 100644
index 9e5dc012a3..0000000000
--- a/camel/camel-lock-helper.c
+++ /dev/null
@@ -1,390 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2001 Ximian Inc.
- *
- * Authors: Michael Zucchi <notzed@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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
- */
-
-/* lock helper process */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <errno.h>
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <signal.h>
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <utime.h>
-
-#include <time.h>
-
-#include <string.h>
-
-#define SETEUID_SAVES (1)
-
-/* we try and include as little as possible */
-
-#include "camel-lock-helper.h"
-#include "camel-lock.h"
-
-#define d(x)
-
-/* keeps track of open locks */
-struct _lock_info {
- struct _lock_info *next;
- uid_t uid;
- int id;
- int depth;
- time_t stamp; /* when last updated */
- char path[1];
-};
-
-static int lock_id = 0;
-static struct _lock_info *lock_info_list;
-static uid_t lock_root_uid = -1;
-static uid_t lock_real_uid = -1;
-
-/* utility functions */
-
-static int read_n(int fd, void *buffer, int inlen)
-{
- char *p = buffer;
- int len, left = inlen;
-
- do {
- len = read(fd, p, left);
- if (len == -1) {
- if (errno != EINTR)
- return -1;
- } else {
- left -= len;
- p += len;
- }
- } while (left > 0 && len != 0);
-
- return inlen - left;
-}
-
-static int write_n(int fd, void *buffer, int inlen)
-{
- char *p = buffer;
- int len, left = inlen;
-
- do {
- len = write(fd, p, left);
- if (len == -1) {
- if (errno != EINTR)
- return -1;
- } else {
- left -= len;
- p += len;
- }
- } while (left > 0);
-
- return inlen;
-}
-
-void
-camel_exception_setv (CamelException *ex, ExceptionId id, const char *format, ...)
-{
- ;
-}
-
-void
-camel_exception_clear (CamelException *exception)
-{
- ;
-}
-
-char *gettext (const char *msgid);
-
-char *
-gettext (const char *msgid)
-{
- return NULL;
-}
-
-static int lock_path(const char *path, guint32 *lockid)
-{
- struct _lock_info *info = NULL;
- int res = CAMEL_LOCK_HELPER_STATUS_OK;
- struct stat st;
-
- d(fprintf(stderr, "locking path '%s' id = %d\n", path, lock_id));
-
- /* check to see if we have it locked already, make the lock 'recursive' */
- /* we could also error i suppose, but why bother */
- info = lock_info_list;
- while (info) {
- if (!strcmp(info->path, path)) {
- info->depth++;
- return CAMEL_LOCK_HELPER_STATUS_OK;
- }
- info = info->next;
- }
-
- /* check we are allowed to lock it, we must own it, be able to write to it, and it has to exist */
- if (stat(path, &st) == -1
- || st.st_uid != getuid()
- || !S_ISREG(st.st_mode)
- || (st.st_mode & 0400) == 0) {
- return CAMEL_LOCK_HELPER_STATUS_INVALID;
- }
-
- info = malloc(sizeof(*info) + strlen(path));
- if (info == NULL) {
- res = CAMEL_LOCK_HELPER_STATUS_NOMEM;
- goto fail;
- }
-
- /* we try the real uid first, and if that fails, try the 'root id' */
- if (camel_lock_dot(path, NULL) == -1) {
-#ifdef SETEUID_SAVES
- if (lock_real_uid != lock_root_uid) {
- if (seteuid(lock_root_uid) != -1) {
- if (camel_lock_dot(path, NULL) == -1) {
- seteuid(lock_real_uid);
- res = CAMEL_LOCK_HELPER_STATUS_SYSTEM;
- goto fail;
- }
- seteuid(lock_real_uid);
- } else {
- res = CAMEL_LOCK_HELPER_STATUS_SYSTEM;
- goto fail;
- }
- } else {
- res = CAMEL_LOCK_HELPER_STATUS_SYSTEM;
- goto fail;
- }
-#else
- res = CAMEL_LOCK_HELPER_STATUS_SYSTEM;
- goto fail;
-#endif
- } else {
- info->uid = lock_real_uid;
- }
-
- strcpy(info->path, path);
- info->id = lock_id;
- info->depth = 1;
- info->next = lock_info_list;
- info->stamp = time(0);
- lock_info_list = info;
-
- if (lockid)
- *lockid = lock_id;
-
- lock_id++;
-
- d(fprintf(stderr, "lock ok\n"));
-
- return res;
-fail:
- d(fprintf(stderr, "lock failed\n"));
-
- if (info)
- free(info);
-
- return res;
-}
-
-static int unlock_id(guint32 lockid)
-{
- struct _lock_info *info, *p;
-
- d(fprintf(stderr, "unlocking id '%d'\n", lockid));
-
- p = (struct _lock_info *)&lock_info_list;
- info = p->next;
- while (info) {
- if (info->id == lockid) {
- d(fprintf(stderr, "found id %d path '%s'\n", lockid, info->path));
- info->depth--;
- if (info->depth <= 0) {
-#ifdef SETEUID_SAVES
- if (info->uid != lock_real_uid) {
- seteuid(lock_root_uid);
- camel_unlock_dot(info->path);
- seteuid(lock_real_uid);
- } else
-#endif
- camel_unlock_dot(info->path);
-
- p->next = info->next;
- free(info);
- }
-
- return CAMEL_LOCK_HELPER_STATUS_OK;
- }
- p = info;
- info = info->next;
- }
-
- d(fprintf(stderr, "unknown id asked to be unlocked %d\n", lockid));
- return CAMEL_LOCK_HELPER_STATUS_PROTOCOL;
-}
-
-static void lock_touch(const char *path)
-{
- char *name;
-
- /* we could also check that we haven't had our lock stolen from us here */
-
- name = alloca(strlen(path) + 10);
- sprintf(name, "%s.lock", path);
-
- d(fprintf(stderr, "Updating lock %s\n", name));
- utime(name, NULL);
-}
-
-static void setup_process(void)
-{
- struct sigaction sa;
- sigset_t sigset;
-
- /* ignore sigint/sigio */
- sa.sa_handler = SIG_IGN;
- sigemptyset (&sa.sa_mask);
- sa.sa_flags = 0;
-
- sigemptyset(&sigset);
- sigaddset(&sigset, SIGIO);
- sigaddset(&sigset, SIGINT);
- sigprocmask(SIG_UNBLOCK, &sigset, NULL);
-
- sigaction (SIGIO, &sa, NULL);
- sigaction (SIGINT, &sa, NULL);
-
- /* FIXME: add more sanity checks/setup here */
-
-#ifdef SETEUID_SAVES
- /* here we change to the real user id, this is probably not particularly
- portable so may need configure checks */
- lock_real_uid = getuid();
- lock_root_uid = geteuid();
- if (lock_real_uid != lock_root_uid)
- seteuid(lock_real_uid);
-#endif
-}
-
-int main(int argc, char **argv)
-{
- struct _CamelLockHelperMsg msg;
- int len;
- int res;
- char *path;
- fd_set rset;
- struct timeval tv;
- struct _lock_info *info;
-
- setup_process();
-
- do {
- /* do a poll/etc, so we can refresh the .locks as required ... */
- FD_ZERO(&rset);
- FD_SET(STDIN_FILENO, &rset);
-
- /* check the minimum timeout we need to refresh the next oldest lock */
- if (lock_info_list) {
- time_t now = time(0);
- time_t left;
- time_t delay = CAMEL_DOT_LOCK_REFRESH;
-
- info = lock_info_list;
- while (info) {
- left = CAMEL_DOT_LOCK_REFRESH - (now - info->stamp);
- left = MAX(left, 0);
- delay = MIN(left, delay);
- info = info->next;
- }
-
- tv.tv_sec = delay;
- tv.tv_usec = 0;
- }
-
- d(fprintf(stderr, "lock helper waiting for input\n"));
- if (select(STDIN_FILENO+1, &rset, NULL, NULL, lock_info_list?&tv:NULL) == -1) {
- if (errno == EINTR)
- break;
-
- continue;
- }
-
- /* did we get a timeout? scan for any locks that need updating */
- if (!FD_ISSET(STDIN_FILENO, &rset)) {
- time_t now = time(0);
- time_t left;
-
- d(fprintf(stderr, "Got a timeout, checking locks\n"));
-
- info = lock_info_list;
- while (info) {
- left = (now - info->stamp);
- if (left >= CAMEL_DOT_LOCK_REFRESH) {
- lock_touch(info->path);
- info->stamp = now;
- }
- info = info->next;
- }
-
- continue;
- }
-
-
- len = read_n(STDIN_FILENO, &msg, sizeof(msg));
- if (len == 0)
- break;
-
- res = CAMEL_LOCK_HELPER_STATUS_PROTOCOL;
- if (len == sizeof(msg) && msg.magic == CAMEL_LOCK_HELPER_MAGIC) {
- switch(msg.id) {
- case CAMEL_LOCK_HELPER_LOCK:
- res = CAMEL_LOCK_HELPER_STATUS_NOMEM;
- path = malloc(msg.data+1);
- if (path != NULL) {
- res = CAMEL_LOCK_HELPER_STATUS_PROTOCOL;
- len = read_n(STDIN_FILENO, path, msg.data);
- if (len == msg.data) {
- path[len] = 0;
- res = lock_path(path, &msg.data);
- }
- free(path);
- }
- break;
- case CAMEL_LOCK_HELPER_UNLOCK:
- res = unlock_id(msg.data);
- break;
- }
- }
- d(fprintf(stderr, "returning result %d\n", res));
- msg.id = res;
- msg.magic = CAMEL_LOCK_HELPER_RETURN_MAGIC;
- write_n(STDOUT_FILENO, &msg, sizeof(msg));
- } while (1);
-
- d(fprintf(stderr, "parent exited, clsoing down remaining id's\n"));
- while (lock_info_list)
- unlock_id(lock_info_list->id);
-
- return 0;
-}
deletions'>-8/+8 * - Fix typos in COMMENTcs2012-08-021-1/+1 * - Update LibreOffice and the language packs to 3.5.5.jkim2012-07-182-8/+8 * - Update to 20120711sunpoet2012-07-132-3/+3 * - Update Calligra to 2.4.3.avilla2012-07-052-4/+4 * - The FreeBSD Office team is proud to announce LibreOffice.org 3.5.4 releasefluffy2012-07-012-8/+8 * - Update to 20120611sunpoet2012-06-182-3/+3 * KDE/FreeBSD team presents KDE SC 4.8.4, probably the last release in 4.8.x se...makc2012-06-155-6/+18 * - update png to 1.5.10dinoex2012-06-014-2/+4 * - Remove koffice-i18n ports, as they are not very useful withoutavilla2012-05-319-794/+0 * The KDE/FreeBSD team is pleased to announce Calligra Suite 2.4.2, KDEavilla2012-05-3117-502/+151 * KDE/FreeBSD team presents long awaited KDE SC 4.8.3!makc2012-05-258-56/+206 * - Update to 20120503sunpoet2012-05-062-3/+3 * - upgrade to 3.5.2bapt2012-04-237-0/+44 * - Update to 20120312sunpoet2012-03-142-3/+3 * - Bump PORTREVISION to chase the update of multimedia/libvpxashish2012-02-162-0/+2 * The KDE/FreeBSD team is pleased to announce KDE SC 4.7.4, whichavilla2012-01-253-5/+5 * - Update to 20120118sunpoet2012-01-222-3/+3 * - Update to 20120112sunpoet2012-01-132-3/+3 * - Update to 20111225sunpoet2011-12-282-3/+3 * - Update to 20111207sunpoet2011-12-082-3/+3 * - Update to 20111204sunpoet2011-12-072-3/+3 * - Pass maintainership to office@FreeBSD.orgsunpoet2011-11-292-2/+2 * - Update to 20111126sunpoet2011-11-282-3/+3 * - Update to 20111119sunpoet2011-11-212-3/+3 * The KDE on FreeBSD team is pleased to update the KDE4 ports to 4.7.3.rakuco2011-11-142-4/+4 * - Update to 20111102sunpoet2011-11-072-3/+3 * - Update to 20111025sunpoet2011-10-302-3/+3 * The vast majority of pkg-descr files had the following format when theydougb2011-10-241-2/+0 * The KDE/FreeBSD team is pleased to announce KDE Software Compilationavilla2011-10-175-37/+270 * - Update to 20110928sunpoet2011-10-032-3/+3 * - Update to 20110909sunpoet2011-09-192-3/+3 * - Set DIST_SUBDIR: move dist files to DISTDIR/mythessunpoet2011-08-182-2/+3 * - Set DIST_SUBDIR: move dist files to DISTDIR/hyphensunpoet2011-08-182-2/+3 * - Set DIST_SUBDIR: move dist files to DISTDIR/hunspellsunpoet2011-08-182-4/+5 * - Change MASTER_SITES to my LOCAL to avoid implicit change of non-versionedsunpoet2011-08-184-8/+8 * - Update to 20110814sunpoet2011-08-162-3/+3 * - Update to 20110813sunpoet2011-08-152-4/+3 * - Set WRKSRCsunpoet2011-08-131-1/+2 * - Unify COMMENT and pkg-descrsunpoet2011-08-132-2/+2 * - Use WRKSRCsunpoet2011-08-121-1/+1 * Remove WWW entries from unmaintained ports that return 404 or where the domainehaupt2011-08-031-2/+0 * - Move language prefix to PKGNAMEPREFIXsunpoet2011-07-293-29/+29 * - Fix typosunpoet2011-07-251-1/+1 * Pass matainership to the new office teambapt2011-07-223-3/+3 * Add some locales thesaurusbapt2011-07-214-0/+41 * Add Portuguese hyphenation rulesbapt2011-07-214-0/+35 * Add portuguese and bresilian hunspell dictionnarybapt2011-07-204-0/+49 * Reset maintainership de jure. In fact KDE 3 has not been maintained by our teammakc2011-07-084-4/+4 * Update KDE Software Compilation ports to 4.6.5makc2011-07-085-5/+195 * - remove MD5ohauer2011-07-031-1/+0 * The FreeBSD KDE Team is pleased to announce KDE SC 4.6.4. Read fullavilla2011-06-142-4/+4 * Update KDE Software Compilation ports to 4.6.3makc2011-05-174-4/+102 * - Update KOffice to 2.3.3.avilla2011-04-134-8/+8 * The FreeBSD KDE Team is pleased to announce April updates for KDEavilla2011-04-073-4/+22 * - Update KOffice to 2.3.1.avilla2011-03-258-186/+76 * The FreeBSD KDE Team is pleased to announce KDE SC 4.6.1 and KDE PIMavilla2011-03-256-51/+200 * - Get Rid MD5 supportmiwi2011-03-1910-10/+0 * - Remove unnecessary PKGNAMEPREFIX declarationsunpoet2011-01-094-4/+0 * - The KDE FreeBSD team is proud to announce the release of KDE 4.5.5fluffy2011-01-082-4/+4 * KDE FreeBSD team presents KDE SC 4.5.4.makc2010-12-034-12/+4 * KDE FreeBSD team presents KDE SC 4.5.3.makc2010-11-043-6/+8 * Deprecate md5 in favour of sha256 checksums. md5 checksums will no longererwin2010-10-291-1/+1 * KDE FreeBSD team presents KDE SC 4.5.2.makc2010-10-065-24/+50 * Autotools update. Read ports/UPDATING 20100915 for details.ade2010-09-164-8/+4 * As previously advertised, remove the remaining ports that have nodougb2010-09-056-3266/+0 * KDE FreeBSD team presents KDE SC 4.5.1.makc2010-09-036-1002/+312 * Update KOffice l10n ports to 2.2.2makc2010-08-286-28/+12 * Update distinfo. The distfiles have been re-rolled for some reason.hrs2010-08-161-3/+3 * Deprecate ports that have been unfetchable for so long that theydougb2010-08-091-0/+3 * Present KDE SC 4.4.5 for FreeBSD.makc2010-06-303-11/+6 * - Update KOffice (and its l10n packs) to 2.2.0 releasefluffy2010-06-198-52/+84 * Present KDE SC 4.4.4 for FreeBSD.makc2010-06-023-6/+10 * Bounce PORTREVISION for gettext-related ports. Have fun, ya'll.ade2010-05-314-4/+4 * - Update KOffice to 2.1.2 releasefluffy2010-05-1110-120/+12 * - The FreeBSD KDE team is pleased to announce KDE SC 4.4.3 for FreeBSDfluffy2010-05-118-387/+422 * - update to 1.4.1dinoex2010-03-2810-8/+10 * Update to version 2010.1.0 of the 2010 fiscal yearlioux2010-03-022-17/+18 * Presenting KDE 4.3.5 for FreeBSD. The official release notes for thismiwi2010-02-074-8/+6 * - update to jpeg-8dinoex2010-02-0510-4/+10 * The KDE FreeBSD team is proud to announce the release of KOffice2 suite for F...fluffy2009-12-2213-960/+172 * The FreeBSD KDE is please to announce the release of KDE 4.3.4,miwi2009-12-022-6/+6 * The KDE FreeBSD team is proud to announce the release of KDE 4.3.3miwi2009-11-275-73/+23 * Update to 8.1.7. Multiple vulnerabilities which could cause thehrs2009-10-151-3/+3 * The FreeBSD KDE is please to announce the release of KDE 4.3.1,tabthorpe2009-09-025-9/+9 * clean upmakc2009-08-082-6/+0 * The KDE FreeBSD team is proud to announce the release of KDE 4.3.0miwi2009-08-058-82/+473 * - bump all port that indirectly depends on libjpeg and have not yet been bump...dinoex2009-07-3110-0/+10 * Upgrade to 20090702-0.thierry2009-07-082-5/+4 * Update to 8.1.6 and 9.1.2.hrs2009-06-181-3/+3 * The KDE FreeBSD team is pleased to announce KDE 4.2.4, the last bugfixmiwi2009-06-033-8/+6 * Update to 8.1.5. Two critical vulnerabilities have been fixed:hrs2009-05-131-3/+3 * Update KDE ports to 4.2.3makc2009-05-104-6/+12 * - Distfile updated without a version bump.araujo2009-04-192-6/+4 * The KDE FreeBSD team is proud to announce the release of KDE 4.2.2miwi2009-04-024-26/+33 * Update to 8.1.4. This version includes serious security fixes.hrs2009-03-291-3/+3 * Welcome to the new linux ports infrastructure which allows usingbsam2009-03-201-1/+1 * Update KDE to 4.2.1.makc2009-03-096-158/+676 * o Add DESKTOP_ENTRIES with entrylioux2009-03-031-1/+9 * o Do not rely on PORTDATA construct when the data files are notlioux2009-03-031-3/+9 * Update to version 2009.1.0 of the 2009 fiscal yearlioux2009-03-034-48/+97 * - Add all manpages for kde4-l10n*miwi2009-02-092-0/+70 * The KDE FreeBSD team is proud to announce the release of KDE 4.2.0miwi2009-02-096-140/+258 * kde@freebsd team is pleased to announce KDE 4.1.4, the last bugfix release in...makc2009-01-146-19/+19 * o Remove after repocopy/move tolioux2008-12-084-31/+0 * o Commit after repocopy.lioux2008-12-081-1/+1 * - Improve package naming according to language category naminglioux2008-12-081-1/+2 * - Improve package naming according to language category naminglioux2008-12-021-2/+3 * Update to Adobe Reader 8.1.3.hrs2008-11-081-3/+3 * Remove ports of Adobe Reader 7 and the localized versions because ofhrs2008-09-063-22/+0 * The KDE FreeBSD team is proud to announce the release of KDE 4.1.1miwi2008-09-034-18/+9 * The KDE FreeBSD team is proud to announce the releasemiwi2008-08-292-6/+6 * The KDE FreeBSD team is proud to announce the releasemiwi2008-08-184-20/+237 * The KDE FreeBSD team is proud to announce the release of KDE 4.1.0miwi2008-08-109-1869/+597 * Upgrade to 20080707.thierry2008-07-252-4/+4 * Update to 8.1.2 Security Update 1. Quoted from the advisory:hrs2008-07-211-3/+3 * Bump portrevision due to upgrade of devel/gettext.edwin2008-06-064-1/+4 * - Remove unneeded dependency from gtk12/gtk20 [1]miwi2008-04-201-1/+1 * Upgrade Esperanto (eo), Spanish (es), Galician (gl), Romanian (ro),thierry2008-04-173-4/+5 * Update to 8.1.2. Bug fixes and enhancements can be found athrs2008-04-141-3/+3 * - Distfile updated without a version bump.araujo2008-04-092-6/+4 * - Mark BROKEN: checksum mismatchpav2008-04-091-0/+2 * Distfile version update without a version bump. Update distinfo andlioux2008-03-162-3/+4 * Upgrade to 20080221-0.thierry2008-03-062-4/+4 * Update to version 2008.1.0 of the 2008 fiscal yearlioux2008-03-042-7/+7 * Add Adobe Reader 8.1.1 and localized versions (total 15hrs2008-01-053-0/+20 * Fix install target: add correct WRKSRClioux2007-12-161-1/+1 * Update to version 2.0lioux2007-12-122-8/+5 * Update to KDE 3.5.8lofi2007-10-308-20/+28 * Update to KDE 3.5.7 / KOffice 1.6.3lofi2007-07-0424-80/+40 * Upgrade to 20070510-0.thierry2007-06-274-8/+8 * - Upgrade to 20070411-0;thierry2007-06-134-7/+6 * - Welcome X.org 7.2 \o/.flz2007-05-2012-2/+12 * BROKEN: Size mismatchkris2007-04-201-0/+2 * - Remove FreeBSD 4.X support from unmaintained ports in categories startinggabor2007-04-201-13/+0 * Update to KDE 3.5.6 / KOffice 1.6.2lofi2007-03-1426-80/+82 * o Update DISTINFO sinze distfile has changed without a version bump:lioux2007-03-132-4/+4 * o Improve wrapper.sh script: remove jars after we have used themlioux2007-03-062-3/+15 * New port irpf version 2007.1.0: Programa do Imposto de Renda Pessoalioux2007-03-066-0/+154 * Upgrade to 20070206-0.thierry2007-02-138-36/+20 * Add Aspell Brazilian Portuguese dictionary.thierry2007-02-135-0/+30 * Update to 7.0.9. Various security vulnerabilities have been fixed.hrs2007-01-182-4/+4 * Update to KDE 3.5.5 / KOffice 1.6.1lofi2006-12-2026-144/+1279