File indexing completed on 2024-05-05 05:48:31
0001 /* 0002 CT Host Header 0003 -------------------------------------------------------------------- 0004 SPDX-FileCopyrightText: 1999 Gary Meyer <gary@meyer.net> 0005 -------------------------------------------------------------------- 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <QList> 0012 #include <QString> 0013 0014 #include "ctSaveStatus.h" 0015 0016 class CTTask; 0017 class CTVariable; 0018 class CTCron; 0019 class CTInitializationError; 0020 class CrontabWidget; 0021 0022 struct passwd; 0023 0024 /** 0025 * The host machine, or computer (encapsulation of crontab files on the 0026 * host). 0027 * 0028 * If the user is the root user, the cron vector will have a member for 0029 * each user of the host plus one for the system crontab. 0030 * 0031 * If the user is a non-root user, there will be only one member in the 0032 * cron vector. 0033 */ 0034 class CTHost 0035 { 0036 public: 0037 /** 0038 * Constructs the user(s), scheduled tasks, and environment variables 0039 * from crontab files. 0040 */ 0041 CTHost(const QString &cronBinary, CTInitializationError &ctInitializationError); 0042 0043 /** 0044 * Destroys the user(s), scheduled tasks, and environment variable 0045 * objects. Does not make any changes to the crontab files. Any unapplied 0046 * changes are consequently "cancelled." 0047 */ 0048 ~CTHost(); 0049 0050 /** 0051 * Apply changes. 0052 * return an empty string if no problem ocurred. 0053 */ 0054 CTSaveStatus save(CrontabWidget *mCrontabWidget); 0055 0056 /** 0057 * Cancel changes. 0058 */ 0059 void cancel(); 0060 0061 /** 0062 * Indicates whether or not dirty. 0063 */ 0064 bool isDirty(); 0065 0066 /** 0067 * Indicates whether or not the user is the root user. 0068 */ 0069 bool isRootUser() const; 0070 0071 CTCron *findCurrentUserCron() const; 0072 CTCron *findSystemCron() const; 0073 CTCron *findUserCron(const QString &userLogin) const; 0074 0075 CTCron *findCronContaining(CTTask *ctTask) const; 0076 CTCron *findCronContaining(CTVariable *ctVariable) const; 0077 0078 /** 0079 * User(s). 0080 * 0081 * If the user is the root user, the cron vector will have a member for 0082 * each user of the host plus one for the system crontab. 0083 * 0084 * If the user is a non-root user, there will be only one member in the 0085 * cron vector. 0086 */ 0087 QList<CTCron *> mCrons; 0088 0089 private: 0090 /** 0091 * Copy construction not allowed. 0092 */ 0093 CTHost(const CTHost &source); 0094 0095 /** 0096 * Assignment not allowed 0097 */ 0098 CTHost &operator=(const CTHost &source); 0099 0100 /** 0101 * Factory create a cron table. Appends to the end of cron. 0102 */ 0103 CTCron *createSystemCron(); 0104 QString createCTCron(const struct passwd *password); 0105 0106 /** 0107 * Check /etc/cron.allow, /etc/cron.deny 0108 */ 0109 bool allowDeny(char *name); 0110 0111 QString mCrontabBinary; 0112 }; 0113