2 * This file is part of the OpenPTS project.
4 * The Initial Developer of the Original Code is International
5 * Business Machines Corporation. Portions created by IBM
6 * Corporation are Copyright (C) 2011 International Business
7 * Machines Corporation. All Rights Reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the Common Public License as published by
11 * IBM Corporation; either version 1 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * Common Public License for more details.
19 * You should have received a copy of the Common Public License
20 * along with this program; if not, a copy can be viewed at
21 * http://www.opensource.org/licenses/cpl1.0.php.
26 * \brief PTS collector command
27 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
28 * @author Olivier Valentin <olivier.valentin@us.ibm.com>
29 * @author Alexandre Ratchov <alexandre.ratchov@bull.net>
31 * cleanup 2011-07-06 SM
36 #include <sys/lockf.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
42 #include <sys/socketvar.h>
50 #include <sys/stat.h> // chmod
57 OPENPTS_PROPERTY *start = NULL;
58 OPENPTS_PROPERTY *end = NULL;
63 * TODO support single connection.
64 * TODO for multiple conenction, multiple ctxs are required.
65 * TODO disable remote connection
67 int collector2(OPENPTS_CONFIG *conf) {
70 OPENPTS_CONTEXT *ctx = NULL;
71 PTS_IF_M_Attribute *read_tlv = NULL;
74 rc = getRmSetDir(conf);
75 if (rc != PTS_SUCCESS) {
76 LOG(LOG_ERR, "collector() - getRmSetDir() was failed\n");
77 return PTS_INTERNAL_ERROR;
80 rc = getNewRmSetDir(conf);
81 if (rc != PTS_SUCCESS) {
83 DEBUG("collector() - getNewRmSetDir() was failed - never mind\n");
87 LOG(LOG_INFO, "start collector (System UUID=%s, RM UUID = %s)\n",
88 conf->uuid->str, conf->rm_uuid->str);
90 /* Collector <-> Verifier - handshake loop */
92 ctx = newPtsContext(conf);
94 addPropertiesFromConfig(conf, ctx);
100 /* read() will block forever unless STDIN was explicitly set to
101 be non-blocking or we receive an interrupt. even then wrapRead() will
102 ignore EAGAIN and EINTR and keep attempting to call read(). the only way
103 this could fail is if the other end of the connection closed, in which case
104 we should exit. if timeouts are required then poll() or select() can be
105 used on blocking file descriptors to listen for input. */
106 read_tlv = readPtsTlv(STDIN_FILENO); // ifm.c, malloc tlv
107 if (read_tlv == NULL) {
108 DEBUG("close IF-M PTS connection\n");
113 if (read_tlv->type == 0) {
114 LOG(LOG_ERR, "Bad TLV type received - quit");
118 if (read_tlv->length > 0 && read_tlv->value == NULL) {
119 LOG(LOG_ERR, "Malformed TLV message (ghost body) - quit");
123 DEBUG_IFM("IF-M read type = 0x%X, len %d\n",
128 switch (read_tlv->type) {
129 case OPENPTS_CAPABILITIES:
130 // TODO define CAPABILITIES structure
131 DEBUG("IF-M OPENPTS_CAPABILITIES\n");
133 if (read_tlv->length != sizeof(OPENPTS_IF_M_Capability)) { // TODO use defined name
134 LOG(LOG_ERR, "Bad PTS_CAPABILITIES, len = %d != %d\n",
135 read_tlv->length, sizeof(OPENPTS_IF_M_Capability));
139 OPENPTS_IF_M_Capability *cap;
140 cap = (OPENPTS_IF_M_Capability *) read_tlv->value;
143 /* get verifier's UUID */
144 ctx->uuid = xmalloc_assert(sizeof(PTS_UUID));
145 memcpy(ctx->uuid, &cap->platform_uuid, 16);
146 ctx->str_uuid = getStringOfUuid(ctx->uuid);
149 LOG(LOG_INFO, "verifier (UUID=%s)\n", ctx->str_uuid);
151 /* send PTS_CAPABILITIES msg. to verifier (=UUID) */
152 rc = writePtsTlv(ctx, STDOUT_FILENO, OPENPTS_CAPABILITIES);
154 LOG(LOG_ERR, "Send CAPABILITY answer failed - quit");
160 case DH_NONCE_PARAMETERS_REQUEST:
161 DEBUG("IF-M DH_NONCE_PARAMETERS_REQUEST\n");
163 if (read_tlv->length != 4) {
164 LOG(LOG_ERR, "Bad DH_NONCE_PARAMETERS_REQUEST, len = %d != 4\n", read_tlv->length);
168 ctx->nonce->req->reserved = read_tlv->value[0];
169 ctx->nonce->req->min_nonce_len = read_tlv->value[1];
171 ctx->nonce->req->dh_group_set = (read_tlv->value[2]<<8) | read_tlv->value[3];
173 rc = getDhResponce(ctx->nonce);
177 ctx, STDOUT_FILENO, DH_NONCE_PARAMETORS_RESPONSE);
179 LOG(LOG_ERR, "Send NONCE answer failed - quit");
184 case DH_NONCE_FINISH:
185 DEBUG("IF-M DH_NONCE_FINISH\n");
187 if (read_tlv->length != 152) { // TODO how to calc this size?
188 LOG(LOG_ERR, "Bad DH_NONCE_FINISH, len = %d != 152\n", read_tlv->length);
192 ctx->nonce->fin->reserved = read_tlv->value[0];
193 ctx->nonce->fin->nonce_length = read_tlv->value[1];
195 ctx->nonce->fin->selected_hash_alg = (read_tlv->value[2]<<8) | read_tlv->value[3];
198 ctx->nonce->fin->dh_initiator_public = xmalloc_assert(ctx->nonce->pubkey_length);
200 ctx->nonce->fin->dh_initiator_public,
202 ctx->nonce->pubkey_length);
205 ctx->nonce->fin->dh_initiator_nonce = xmalloc_assert(ctx->nonce->fin->nonce_length);
207 ctx->nonce->fin->dh_initiator_nonce,
208 &read_tlv->value[4 + ctx->nonce->pubkey_length],
209 ctx->nonce->fin->nonce_length);
211 rc = calcDhFin(ctx->nonce);
216 case REQUEST_RIMM_SET: // 5
217 DEBUG("IF-M REQUEST_RIMM_SET\n");
219 if (read_tlv->length != 0) {
220 LOG(LOG_ERR, "Bad REQUEST__RIMM_SET, len = %d != 0\n", read_tlv->length);
224 ctx, STDOUT_FILENO, RIMM_SET);
226 LOG(LOG_ERR, "Send RIMM_SET answer failed - quit");
231 case REQUEST_NEW_RIMM_SET:
232 DEBUG("IF-M REQUEST_NEW_RIMM_SET\n");
234 if (read_tlv->length != 0) {
235 LOG(LOG_ERR, "Bad REQUEST_NEW_RIMM_SET, len = %d != 0\n", read_tlv->length);
239 ctx, STDOUT_FILENO, NEW_RIMM_SET);
241 /* this will fail if NEW RM is missing */
242 DEBUG_IFM("Send NEW_RIMM_SET answer failed - quit");
247 case REQUEST_INTEGRITY_REPORT:
248 DEBUG("IF-M REQUEST_INTEGRITY_REPORT\n");
250 if (read_tlv->length != 0) {
251 LOG(LOG_ERR, "Bad REQUEST_INTEGRITY_REPORT, len = %d != 0\n", read_tlv->length);
254 rc = writePtsTlv(ctx, STDOUT_FILENO, INTEGRITY_REPORT);
256 LOG(LOG_ERR, "Send INTEGRITY_REPORT answer failed - quit");
261 case VERIFICATION_RESULT:
263 DEBUG_IFM("IF-M VERIFICATION_RESULT => terminate\n");
264 DEBUG_IFM("finish\n");
265 terminate = 1; // TODO add TERMINATE MSG
268 case REQUEST_AIDE_DATABASE:
269 LOG(LOG_INFO, "IF-M REQUEST_AIDE_DATABASE\n");
271 if (read_tlv->length != 0) {
272 LOG(LOG_ERR, "Bad REQUEST_AIDE_DATABASE, len = %d != 0\n", read_tlv->length);
275 rc = writePtsTlv(ctx, STDOUT_FILENO, AIDE_DATABASE);
277 LOG(LOG_ERR, "Send REQUEST_AIDE_DATABASE answer failed - quit");
283 case REQUEST_TPM_PUBKEY:
285 if (read_tlv->length != 0) {
286 LOG(LOG_ERR, "Bad REQUEST_TPM_PUBKEY, len = %d != 0\n", read_tlv->length);
289 rc = writePtsTlv(ctx, STDOUT_FILENO, TPM_PUBKEY); // ifm.c
291 LOG(LOG_ERR, "Send TPM_PUBKEY answer failed - quit");
298 if (read_tlv->length != 20) {
299 LOG(LOG_ERR, "Bad NONCE, len = %d != 20\n", read_tlv->length);
303 ctx->nonce->nonce_length = 20;
304 if (ctx->nonce->nonce != NULL) {
305 xfree(ctx->nonce->nonce);
307 ctx->nonce->nonce = xmalloc_assert(20);
308 memcpy(ctx->nonce->nonce, read_tlv->value, 20);
309 DEBUG_IFM("nonce[%d] : \n", ctx->nonce->nonce_length);
313 LOG(LOG_ERR, "verifier returns error, termnate\n");
317 LOG(LOG_ERR, "PTS IF-M type 0x%08x is not supported\n", read_tlv->type);
318 LOG(LOG_INFO, "send OPENPTS_ERROR msg to verifier, then terminate the conenction");
319 ctx->ifm_errno = PTS_UNRECOGNIZED_COMMAND;
320 if (ctx->ifm_strerror != NULL) {
321 xfree(ctx->ifm_strerror);
323 ctx->ifm_strerror = smalloc_assert("Unknown message type");
324 rc = writePtsTlv(ctx, STDOUT_FILENO, OPENPTS_ERROR); // ifm.c
330 if (read_tlv != NULL) {
331 freePtsTlv(read_tlv);
345 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_USAGE_1,
346 "OpenPTS Collector\n\n"
347 "Usage: ptsc [options] [command]\n\n"
348 "Commands: (foreground)\n"
349 " -i Initialize PTS collector\n"
350 " -t Self test (attestation)\n"
351 " -s Startup (selftest + timestamp)\n"
352 " -u Update the RM\n"
353 " -e Clear PTS collector\n"));
354 #ifdef CONFIG_AUTO_RM_UPDATE
355 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_USAGE_2,
356 " -U Update the RM (auto)\n"));
358 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_USAGE_3,
359 " -D Display the configuration\n"
363 " -h Show this help message\n"
364 " -v Verbose mode. Multiple -v options increase the verbosity.\n"
367 " -c configfile Set configuration file. defalt is %s\n"
368 " -P name=value Set properties.\n"
370 " -z Set the SRK secret to all zeros (20 bytes of zeros)\n"), PTSC_CONFIG_FILE);
381 #ifdef CONFIG_AUTO_RM_UPDATE
389 OPENPTS_PROPERTY *getPropertyFromArg(char *arg) {
393 OPENPTS_PROPERTY *prop;
395 if ((eq = strstr(arg, "=")) != NULL) {
401 prop = newProperty(name, value);
404 LOG(LOG_ERR, "bad property %s\n", arg);
410 #define LOCK_DIR "/var/ptsc/"
412 #define LOCK_DIR "/var/lib/openpts/"
414 #define LOCK_FILE LOCK_DIR "ptsc.lock"
419 void ptsc_lock(void) {
420 int fd, oldmask, oldgrp = 0;
421 struct group *grpent = NULL;
427 if (geteuid() == 0) {
428 // grpent = getgrnam(PTSC_GROUP_NAME);
430 // oldgrp = getegid();
431 // setegid(grpent->gr_gid);
433 buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
437 buf = xmalloc(buf_len);
439 LOG(LOG_ERR, "no memory");
443 rc = getgrnam_r(PTSC_GROUP_NAME, &grp, buf, buf_len, &grpent);
448 if (grpent == NULL) {
457 if (mkdir(LOCK_DIR, 0775) < 0 && errno != EEXIST) {
458 LOG(LOG_ERR, "mkdir(%s) fail", LOCK_DIR);
462 chmod(LOCK_DIR, 02775);
465 fd = open(LOCK_FILE, O_RDWR | O_CREAT | O_TRUNC, 0660);
467 LOG(LOG_ERR, "open(%s) fail", LOCK_DIR);
471 if (lockf(fd, F_LOCK, 0) < 0) {
472 LOG(LOG_ERR, "lockf(%s) fail", LOCK_DIR);
476 if (buf != NULL) xfree(buf);
482 static int preparePriv() {
483 int rc = PTS_SUCCESS;
484 struct group *ptsc_grp = NULL;
491 if ((ptscd_pwd = getpwnam_r(PTSCD_USER_NAME)) == NULL) {
492 LOG(LOG_ERR, "Looking up for user %s", PTSCD_USER_NAME);
498 // ptsc_grp = getgrnam(PTSC_GROUP_NAME); // TODO use getgrnam_r
499 // if (ptsc_grp == NULL) {
500 // LOG(LOG_ERR, "Looking up for group (name=%s) fail", PTSC_GROUP_NAME);
503 buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
507 buf = xmalloc(buf_len);
509 LOG(LOG_ERR, "no memory");
513 rc = getgrnam_r(PTSC_GROUP_NAME, &grp, buf, buf_len, &ptsc_grp);
515 LOG(LOG_ERR, "getgrnam_r(%s) fail", PTSC_GROUP_NAME);
519 if (ptsc_grp == NULL) {
520 LOG(LOG_ERR, "ptsc_grp == NULL");
526 rc = setgid(grp.gr_gid);
528 // TODO do not need for IF-M access (read only)
529 LOG(LOG_INFO, "Switching group (gid=%d) fail. %s\n", grp.gr_gid, strerror(errno));
530 // TODO 20110927 FAIL
536 if (setuid(ptscd_pwd->pw_uid) == -1) {
537 LOG(LOG_ERR, "Switching to user %s", PTSCD_USER_NAME);
544 if (buf != NULL) xfree(buf);
550 * dir group => PTSC_GROUP_NAME
552 * flag 0:read, 1:read/write
554 static int chmodDir(char *dirpath, int flag) {
555 int rc = PTS_SUCCESS;
556 struct group *ptsc_grp;
563 // ptsc_grp = getgrnam(PTSC_GROUP_NAME); // TODO use getgrnam_r
564 // if (ptsc_grp == NULL) {
565 // LOG(LOG_ERR, "Looking up for group %s", PTSC_GROUP_NAME);
568 buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
572 buf = xmalloc(buf_len);
574 LOG(LOG_ERR, "no memory");
578 rc = getgrnam_r(PTSC_GROUP_NAME, &grp, buf, buf_len, &ptsc_grp);
580 LOG(LOG_ERR, "getgrnam_r");
584 if (ptsc_grp == NULL) {
585 LOG(LOG_ERR, "ptsc_grp == NULL");
603 S_IRUSR | S_IWUSR | S_IXUSR |
612 S_IRUSR | S_IWUSR | S_IXUSR |
613 S_IRGRP | S_IWGRP | S_IXGRP);
621 if (buf != NULL) xfree(buf);
629 int main(int argc, char *argv[]) {
631 OPENPTS_CONFIG *conf = NULL;
632 char *config_filename = NULL;
633 int command = COMMAND_STATUS;
636 #ifdef CONFIG_AUTO_RM_UPDATE
639 // extern int logLocation;
640 // void setLogLocation(int ll);
642 /* properties by cmdline */
643 OPENPTS_PROPERTY *prop;
650 if (rc != PTS_SUCCESS) {
651 LOG(LOG_ERR, "preparePriv fail\n");
654 conf = newPtsConfig();
656 LOG(LOG_ERR, "internal error\n"); // TODO(munetoh)
662 setSyslogCommandName("ptsc");
665 while ((c = getopt(argc, argv, "ic:uUefDtsmvP:Rzh")) != EOF) {
668 command = COMMAND_INIT;
671 command = COMMAND_UPDATE;
674 #ifdef CONFIG_AUTO_RM_UPDATE
675 command = COMMAND_AUTO_UPDATE;
679 command = COMMAND_STATUS;
682 command = COMMAND_SELFTEST;
685 command = COMMAND_STARTUP;
688 command = COMMAND_CLEAR;
694 command = COMMAND_IFM;
695 /* not everything should go to syslog - on some systems
696 this could go to a log file - let default behaviour
697 in log.c decide this */
698 // setLogLocation(OPENPTS_LOG_SYSLOG, NULL);
699 // OK setLogLocation(OPENPTS_LOG_CONSOLE, NULL); // OK
700 // setLogLocation(OPENPTS_LOG_FILE, "/var/log/ptsc.log"); // OK call this before any out
703 config_filename = optarg;
709 #ifdef CONFIG_AUTO_RM_UPDATE
714 conf->srk_password_mode = 1;
717 prop = getPropertyFromArg(optarg);
745 /* Verbose & Logging */
746 if (command == COMMAND_IFM) {
747 /* Set IF-M log location, syslog or file(for DEBUG) */
748 setLogLocation(OPENPTS_LOG_SYSLOG, NULL);
749 // setVerbosity(0); // no console out
751 /* Set logging (location,filename) by ENV */
752 determineLogLocationByEnv();
753 //setLogLocation(OPENPTS_LOG_CONSOLE, NULL);
756 if (rc != PTS_SUCCESS) {
757 LOG(LOG_INFO, "preparePriv fail\n");
761 conf = newPtsConfig();
763 LOG(LOG_ERR, "internal error\n"); // TODO(munetoh)
767 /* set the DEBUG level, 1,2,3 */
768 if (getVerbosity() > 2) {
769 setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG | DEBUG_FSM_FLAG | DEBUG_CAL_FLAG );
770 } else if (getVerbosity() > 1) {
771 setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG);
772 } else if (getVerbosity() > 0) {
773 setDebugFlags(DEBUG_FLAG);
776 DEBUG("VERBOSITY (%d), DEBUG mode (0x%x)\n", getVerbosity(), getDebugFlags());
781 /* load config, /etc/ptsc.conf */
782 if (config_filename == NULL) {
783 // this goto stdout and bad with "-m"
784 // VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE, "Config file: %s\n"), PTSC_CONFIG_FILE);
785 rc = readPtsConfig(conf, PTSC_CONFIG_FILE);
786 if (rc != PTS_SUCCESS) {
787 DEBUG("readPtsConfig() failed\n");
791 // VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE, "Config file: %s\n"), config_filename);
792 rc = readPtsConfig(conf, config_filename);
793 if (rc != PTS_SUCCESS) {
794 DEBUG("readPtsConfig() failed\n");
801 /* Check initialization */
802 if (command != COMMAND_INIT) {
804 if (checkFile(conf->uuid->filename) != OPENPTS_FILE_EXISTS) {
806 LOG(LOG_ERR, "ptsc is not initialized yet");
808 "ptsc is not initialized yet.\n\n");
813 /* only do this when needed */
814 if (command != COMMAND_STATUS) {
816 if (checkDir(conf->ir_dir) != PTS_SUCCESS) {
817 rc = makeDir(conf->ir_dir);
818 if (rc != PTS_SUCCESS) {
819 LOG(LOG_ERR, "Can not create the dir to store IR, %s\n", conf->ir_dir);
822 rc = chmodDir(conf->ir_dir, 1);
823 if (rc != PTS_SUCCESS) {
824 LOG(LOG_ERR, "Can not create the dir to store IR, %s\n", conf->ir_dir);
830 /* initialize the PTS collector */
831 if (command == COMMAND_INIT) {
832 VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_INIT_RM, "Initializing Reference Manifest\n"));
833 rc = init(conf, prop_num, start, end);
838 /* Clear the PTS collector */
839 if (command == COMMAND_CLEAR) {
840 rc = clear(conf, force);
847 if (conf->rm_uuid == NULL) {
848 LOG(LOG_ERR, "rm_uuid is missing");
852 rc = readOpenptsUuidFile(conf->rm_uuid);
853 if (rc != PTS_SUCCESS) {
854 DEBUG("readOpenptsUuidFile(%s) failed\n",conf->rm_uuid->filename);
855 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAILED_READ_RM_UUID,
856 "Failed to read the Reference Manifest UUID file '%s':\n"
857 "Please ensure on the target that:\n"
858 " * ptsc has been initialized (ptsc -i)\n"
859 " * you (uid==%d) are allowed to attest (i.e. a member of group '%s')\n\n"),
860 conf->rm_uuid->filename, getuid(), PTSC_GROUP_NAME);
863 DEBUG("conf->str_rm_uuid : %s\n", conf->rm_uuid->str);
868 if (conf->newrm_uuid == NULL) {
869 LOG(LOG_ERR, "newrm_uuid is missing.");
873 rc = readOpenptsUuidFile(conf->newrm_uuid);
874 if (rc != PTS_SUCCESS) {
875 DEBUG("conf->str_newrm_uuid : missing (file:%s)\n", conf->newrm_uuid->filename);
878 DEBUG("conf->str_newrm_uuid : %s (for next boot)\n", conf->newrm_uuid->str);
882 /* load RSA PUB key */
883 // TODO single key => multiple keys?
885 LOG(LOG_TODO, "CONFIG_NO_TSS, no TPM_PUBKEY\n");
886 conf->pubkey_length = 0;
889 /* only do this when needed */
890 if (command != COMMAND_STATUS) {
894 conf->aik_storage_type, // TSS_PS_TYPE_SYSTEM,
895 conf->srk_password_mode,
896 conf->tpm_resetdalock,
897 conf->aik_storage_filename, // NULL,
899 &conf->pubkey_length,
901 if (rc != TSS_SUCCESS) {
902 LOG(LOG_ERR, "getTssPubKey() fail rc=0x%x srk password mode=%d, key =%s\n",
903 rc, conf->srk_password_mode, conf->uuid->str);
904 OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE,
905 "TSS communications failure. Is tcsd running?\n"));
913 #ifdef CONFIG_AUTO_RM_UPDATE
914 case COMMAND_AUTO_UPDATE:
915 /* update by command, but HUP is better */
916 VERBOSE(1, "Updating Reference Manifest\n");
917 //addDebugFlags(DEBUG_CAL_FLAG);
919 rc = update(conf, prop_num, start, end, remove);
920 if (rc != PTS_SUCCESS) {
921 LOG(LOG_ERR, "update was fail\n");
926 rc = printCollectorStatus(conf);
928 case COMMAND_SELFTEST:
929 rc = selftest(conf, prop_num, start, end);
930 if (rc == OPENPTS_SELFTEST_SUCCESS) {
931 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SUCCESS, "selftest - OK\n"));
932 LOG(LOG_INFO, "selftest - OK\n");
933 } else if (rc == OPENPTS_SELFTEST_RENEWED) {
934 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_RENEWED, "selftest - Renewed\n"));
935 LOG(LOG_INFO, "selftest - Renewed\n");
936 } else if (rc == OPENPTS_SELFTEST_FALLBACK) {
937 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FALLBACK, "selftest - fallback\n"));
938 LOG(LOG_INFO, "selftest - fallback\n");
939 } else if (rc == OPENPTS_SELFTEST_FAILED) {
940 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAIL, "selftest - fail\n"));
941 LOG(LOG_INFO, "selftest - fail\n");
943 LOG(LOG_ERR, "TBD\n");
946 case COMMAND_STARTUP:
947 rc = selftest(conf, prop_num, start, end);
948 if (rc == OPENPTS_SELFTEST_SUCCESS) {
949 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SUCCESS, "selftest - OK\n"));
950 LOG(LOG_INFO, "selftest - OK\n");
952 extendEvCollectorStart(conf); // collector.c
953 } else if (rc == OPENPTS_SELFTEST_RENEWED) {
954 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_RENEWED, "selftest - Renewed\n"));
955 LOG(LOG_INFO, "selftest - Renewed\n");
957 extendEvCollectorStart(conf);
958 } else if (rc == OPENPTS_SELFTEST_FALLBACK) {
959 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FALLBACK, "selftest - fallback\n"));
960 LOG(LOG_INFO, "selftest - fallback\n");
962 extendEvCollectorStart(conf);
963 } else if (rc == OPENPTS_SELFTEST_FAILED) {
964 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAIL, "selftest - fail\n"));
965 LOG(LOG_INFO, "selftest - fail\n");
966 if (conf->autoupdate == 1) {
967 LOG(LOG_ERR, "selftest failed, trying to generate a new manifest\n");
969 conf->rm_uuid->status = OPENPTS_UUID_FILENAME_ONLY;
970 if (conf->rm_uuid->uuid != NULL) freeUuid(conf->rm_uuid->uuid);
971 if (conf->rm_uuid->str != NULL) xfree(conf->rm_uuid->str);
972 if (conf->rm_uuid->time != NULL) xfree(conf->rm_uuid->time);
973 conf->rm_uuid->uuid = NULL;
974 conf->rm_uuid->str = NULL;
975 conf->rm_uuid->time = NULL;
977 /* gen new RM_UUID and RM */
978 rc = newrm(conf, prop_num, start, end);
979 if (rc != PTS_SUCCESS) {
980 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_FAIL,
981 "Failed to generated a reference manifest\n"));
982 LOG(LOG_INFO, "Failed to generated a reference manifest\n");
985 rc = selftest(conf, prop_num, start, end);
986 if (rc == OPENPTS_SELFTEST_SUCCESS) {
987 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SUCCESS, "selftest - OK\n"));
988 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_SUCCESS,
989 "Successfully generated the reference manifest\n"));
990 LOG(LOG_INFO, "selftest - OK\n");
991 LOG(LOG_INFO, "Successfully generated the reference manifest\n");
992 } else if (rc == OPENPTS_SELFTEST_RENEWED) {
993 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_RENEWED, "selftest - Renewed\n"));
994 LOG(LOG_INFO, "selftest - Renewed\n");
996 LOG(LOG_ERR, "TBD\n");
999 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_WONT,
1000 "selftest failed, keeping existing manifests as requested by configuration\n"));
1001 LOG(LOG_INFO, "selftest failed, keeping existing manifests as requested by configuration\n");
1004 LOG(LOG_ERR, "TBD\n");
1007 case COMMAND_UPDATE:
1009 conf->rm_uuid->status = OPENPTS_UUID_FILENAME_ONLY;
1010 if (conf->rm_uuid->uuid != NULL) freeUuid(conf->rm_uuid->uuid);
1011 if (conf->rm_uuid->str != NULL) xfree(conf->rm_uuid->str);
1012 if (conf->rm_uuid->time != NULL) xfree(conf->rm_uuid->time);
1013 conf->rm_uuid->uuid = NULL;
1014 conf->rm_uuid->str = NULL;
1015 conf->rm_uuid->time = NULL;
1017 /* gen new RM_UUID and RM */
1018 rc = newrm(conf, prop_num, start, end);
1019 if (rc != PTS_SUCCESS) {
1020 LOG(LOG_ERR, "newrm() fail\n");
1025 rc = selftest(conf, prop_num, start, end);
1026 if (rc == OPENPTS_SELFTEST_SUCCESS) {
1027 VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_SUCCESS,
1028 "Successfully generated the reference manifest\n"));
1029 } else if (rc == OPENPTS_SELFTEST_RENEWED) {
1030 LOG(LOG_TODO, "TBD\n");
1032 LOG(LOG_TODO, "TBD\n");
1036 /* run colelctor IF-M */
1037 rc = collector2(conf);
1040 LOG(LOG_ERR, "bad command\n");
1045 freePtsConfig(conf);