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 2012-01-04 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
55 OPENPTS_PROPERTY *start = NULL;
56 OPENPTS_PROPERTY *end = NULL;
61 * TODO support single connection.
62 * TODO for multiple conenction, multiple ctxs are required.
63 * TODO disable remote connection
65 int collector(OPENPTS_CONFIG *conf) {
68 OPENPTS_CONTEXT *ctx = NULL;
69 PTS_IF_M_Attribute *read_tlv = NULL;
72 rc = getRmSetDir(conf);
73 if (rc != PTS_SUCCESS) {
74 LOG(LOG_ERR, "collector() - getRmSetDir() was failed\n");
75 return PTS_INTERNAL_ERROR;
78 rc = getNewRmSetDir(conf);
79 if (rc != PTS_SUCCESS) {
81 DEBUG("collector() - getNewRmSetDir() was failed - never mind\n");
84 LOG(LOG_INFO, "start collector (System UUID=%s, RM UUID = %s)\n",
85 conf->uuid->str, conf->rm_uuid->str);
87 /* Collector <-> Verifier - handshake loop */
88 ctx = newPtsContext(conf);
90 addPropertiesFromConfig(conf, ctx);
96 /* read() will block forever unless STDIN was explicitly set to
97 be non-blocking or we receive an interrupt. even then wrapRead() will
98 ignore EAGAIN and EINTR and keep attempting to call read(). the only way
99 this could fail is if the other end of the connection closed, in which case
100 we should exit. if timeouts are required then poll() or select() can be
101 used on blocking file descriptors to listen for input. */
102 read_tlv = readPtsTlv(STDIN_FILENO); // ifm.c, malloc tlv
103 if (read_tlv == NULL) {
104 DEBUG("close IF-M PTS connection\n");
109 if (read_tlv->type == 0) {
110 LOG(LOG_ERR, "Bad TLV type received - quit");
114 if (read_tlv->length > 0 && read_tlv->value == NULL) {
115 LOG(LOG_ERR, "Malformed TLV message (ghost body) - quit");
119 DEBUG_IFM("IF-M read type = 0x%X, len %d\n",
124 switch (read_tlv->type) {
125 case OPENPTS_CAPABILITIES:
126 DEBUG("IF-M OPENPTS_CAPABILITIES\n");
128 if (read_tlv->length != sizeof(OPENPTS_IF_M_Capability)) { // TODO use defined name
129 LOG(LOG_ERR, "Bad PTS_CAPABILITIES, len = %d != %d\n",
130 read_tlv->length, sizeof(OPENPTS_IF_M_Capability));
134 OPENPTS_IF_M_Capability *cap;
135 cap = (OPENPTS_IF_M_Capability *) read_tlv->value;
138 /* get verifier's UUID */
139 ctx->uuid = xmalloc_assert(sizeof(PTS_UUID));
140 memcpy(ctx->uuid, &cap->platform_uuid, 16);
141 ctx->str_uuid = getStringOfUuid(ctx->uuid);
144 LOG(LOG_INFO, "verifier (UUID=%s)\n", ctx->str_uuid);
146 /* send PTS_CAPABILITIES msg. to verifier (=UUID) */
147 rc = writePtsTlv(ctx, STDOUT_FILENO, OPENPTS_CAPABILITIES);
149 LOG(LOG_ERR, "Send CAPABILITY answer failed - quit");
155 case DH_NONCE_PARAMETERS_REQUEST:
156 DEBUG("IF-M DH_NONCE_PARAMETERS_REQUEST\n");
158 if (read_tlv->length != 4) {
159 LOG(LOG_ERR, "Bad DH_NONCE_PARAMETERS_REQUEST, len = %d != 4\n", read_tlv->length);
163 ctx->nonce->req->reserved = read_tlv->value[0];
164 ctx->nonce->req->min_nonce_len = read_tlv->value[1];
166 ctx->nonce->req->dh_group_set = (read_tlv->value[2]<<8) | read_tlv->value[3];
168 rc = getDhResponce(ctx->nonce);
172 ctx, STDOUT_FILENO, DH_NONCE_PARAMETORS_RESPONSE);
174 LOG(LOG_ERR, "Send NONCE answer failed - quit");
179 case DH_NONCE_FINISH:
180 DEBUG("IF-M DH_NONCE_FINISH\n");
182 if (read_tlv->length != 152) { // TODO how to calc this size?
183 LOG(LOG_ERR, "Bad DH_NONCE_FINISH, len = %d != 152\n", read_tlv->length);
187 ctx->nonce->fin->reserved = read_tlv->value[0];
188 ctx->nonce->fin->nonce_length = read_tlv->value[1];
190 ctx->nonce->fin->selected_hash_alg = (read_tlv->value[2]<<8) | read_tlv->value[3];
193 ctx->nonce->fin->dh_initiator_public = xmalloc_assert(ctx->nonce->pubkey_length);
195 ctx->nonce->fin->dh_initiator_public,
197 ctx->nonce->pubkey_length);
200 ctx->nonce->fin->dh_initiator_nonce = xmalloc_assert(ctx->nonce->fin->nonce_length);
202 ctx->nonce->fin->dh_initiator_nonce,
203 &read_tlv->value[4 + ctx->nonce->pubkey_length],
204 ctx->nonce->fin->nonce_length);
206 rc = calcDhFin(ctx->nonce);
211 case REQUEST_RIMM_SET: // 5
212 DEBUG("IF-M REQUEST_RIMM_SET\n");
214 if (read_tlv->length != 0) {
215 LOG(LOG_ERR, "Bad REQUEST__RIMM_SET, len = %d != 0\n", read_tlv->length);
219 ctx, STDOUT_FILENO, RIMM_SET);
221 LOG(LOG_ERR, "Send RIMM_SET answer failed - quit");
226 case REQUEST_NEW_RIMM_SET:
227 DEBUG("IF-M REQUEST_NEW_RIMM_SET\n");
229 if (read_tlv->length != 0) {
230 LOG(LOG_ERR, "Bad REQUEST_NEW_RIMM_SET, len = %d != 0\n", read_tlv->length);
234 ctx, STDOUT_FILENO, NEW_RIMM_SET);
236 /* this will fail if NEW RM is missing */
237 DEBUG_IFM("Send NEW_RIMM_SET answer failed - quit");
242 case REQUEST_INTEGRITY_REPORT:
243 DEBUG("IF-M REQUEST_INTEGRITY_REPORT\n");
245 if (read_tlv->length != 0) {
246 LOG(LOG_ERR, "Bad REQUEST_INTEGRITY_REPORT, len = %d != 0\n", read_tlv->length);
249 rc = writePtsTlv(ctx, STDOUT_FILENO, INTEGRITY_REPORT);
251 LOG(LOG_ERR, "Send INTEGRITY_REPORT answer failed - quit");
256 case VERIFICATION_RESULT:
258 DEBUG_IFM("IF-M VERIFICATION_RESULT => terminate\n");
259 DEBUG_IFM("finish\n");
260 terminate = 1; // TODO add TERMINATE MSG
263 case REQUEST_AIDE_DATABASE:
264 LOG(LOG_INFO, "IF-M REQUEST_AIDE_DATABASE\n");
266 if (read_tlv->length != 0) {
267 LOG(LOG_ERR, "Bad REQUEST_AIDE_DATABASE, len = %d != 0\n", read_tlv->length);
270 rc = writePtsTlv(ctx, STDOUT_FILENO, AIDE_DATABASE);
272 LOG(LOG_ERR, "Send REQUEST_AIDE_DATABASE answer failed - quit");
278 case REQUEST_TPM_PUBKEY:
280 if (read_tlv->length != 0) {
281 LOG(LOG_ERR, "Bad REQUEST_TPM_PUBKEY, len = %d != 0\n", read_tlv->length);
284 rc = writePtsTlv(ctx, STDOUT_FILENO, TPM_PUBKEY); // ifm.c
286 LOG(LOG_ERR, "Send TPM_PUBKEY answer failed - quit");
293 if (read_tlv->length != 20) {
294 LOG(LOG_ERR, "Bad NONCE, len = %d != 20\n", read_tlv->length);
298 ctx->nonce->nonce_length = 20;
299 if (ctx->nonce->nonce != NULL) {
300 xfree(ctx->nonce->nonce);
302 ctx->nonce->nonce = xmalloc_assert(20);
303 memcpy(ctx->nonce->nonce, read_tlv->value, 20);
304 DEBUG_IFM("nonce[%d] : \n", ctx->nonce->nonce_length);
308 LOG(LOG_ERR, "verifier returns error, termnate\n");
312 LOG(LOG_ERR, "PTS IF-M type 0x%08x is not supported\n", read_tlv->type);
313 LOG(LOG_INFO, "send OPENPTS_ERROR msg to verifier, then terminate the conenction");
314 ctx->ifm_errno = PTS_UNRECOGNIZED_COMMAND;
315 if (ctx->ifm_strerror != NULL) {
316 xfree(ctx->ifm_strerror);
318 ctx->ifm_strerror = smalloc_assert("Unknown message type");
319 rc = writePtsTlv(ctx, STDOUT_FILENO, OPENPTS_ERROR); // ifm.c
325 if (read_tlv != NULL) {
326 freePtsTlv(read_tlv);
340 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_USAGE_1,
341 "OpenPTS Collector\n\n"
342 "Usage: ptsc [options] [command]\n\n"
343 "Commands: (foreground)\n"
344 " -i Initialize PTS collector\n"
345 " -t Self test (attestation)\n"
346 " -s Startup (selftest + timestamp)\n"
347 " -u Update the RM\n"
348 " -e Clear PTS collector\n"));
349 #ifdef CONFIG_AUTO_RM_UPDATE
350 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_USAGE_2,
351 " -U Update the RM (auto)\n"));
353 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_USAGE_3,
354 " -D Display the configuration\n"
358 " -h Show this help message\n"
359 " -v Verbose mode. Multiple -v options increase the verbosity.\n"
362 " -c configfile Set configuration file. defalt is %s\n"
363 " -P name=value Set properties.\n"
365 " -z Set the SRK secret to all zeros (20 bytes of zeros)\n"), PTSC_CONFIG_FILE);
376 #ifdef CONFIG_AUTO_RM_UPDATE
384 OPENPTS_PROPERTY *getPropertyFromArg(char *arg) {
388 OPENPTS_PROPERTY *prop;
390 if ((eq = strstr(arg, "=")) != NULL) {
396 prop = newProperty(name, value);
399 LOG(LOG_ERR, "bad property %s\n", arg);
405 #define LOCK_DIR "/var/ptsc/"
407 #define LOCK_DIR "/var/lib/openpts/"
409 #define LOCK_FILE LOCK_DIR "ptsc.lock"
416 void ptsc_lock(void) {
417 int fd, oldmask, oldgrp = 0;
418 struct group *grpent = NULL;
424 if (geteuid() == 0) {
425 // grpent = getgrnam(PTSC_GROUP_NAME);
427 // oldgrp = getegid();
428 // setegid(grpent->gr_gid);
430 buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
434 buf = xmalloc(buf_len);
436 LOG(LOG_ERR, "no memory");
440 rc = getgrnam_r(PTSC_GROUP_NAME, &grp, buf, buf_len, &grpent);
442 LOG(LOG_ERR, "getgrnam_r() fail");
445 if (grpent == NULL) {
446 LOG(LOG_ERR, "grpent is null");
454 if (mkdir(LOCK_DIR, 0775) < 0 && errno != EEXIST) {
455 LOG(LOG_ERR, "mkdir(%s) fail", LOCK_DIR);
459 chmod(LOCK_DIR, 02775);
462 fd = open(LOCK_FILE, O_RDWR | O_CREAT | O_TRUNC, 0660);
464 LOG(LOG_ERR, "open(%s) fail", LOCK_DIR);
468 if (lockf(fd, F_LOCK, 0) < 0) {
469 LOG(LOG_ERR, "lockf(%s) fail", LOCK_DIR);
473 if (buf != NULL) xfree(buf);
479 static int preparePriv() {
480 int rc = PTS_SUCCESS;
481 struct group *ptsc_grp = NULL;
488 if ((ptscd_pwd = getpwnam_r(PTSCD_USER_NAME)) == NULL) {
489 LOG(LOG_ERR, "Looking up for user %s", PTSCD_USER_NAME);
495 buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
499 buf = xmalloc(buf_len);
501 LOG(LOG_ERR, "no memory");
505 rc = getgrnam_r(PTSC_GROUP_NAME, &grp, buf, buf_len, &ptsc_grp);
507 LOG(LOG_ERR, "getgrnam_r(%s) fail", PTSC_GROUP_NAME);
511 if (ptsc_grp == NULL) {
512 LOG(LOG_ERR, "ptsc_grp == NULL");
518 rc = setgid(grp.gr_gid);
520 // TODO do not need for IF-M access (read only)
521 LOG(LOG_INFO, "Switching group (gid=%d) fail. %s\n", grp.gr_gid, strerror(errno));
527 if (setuid(ptscd_pwd->pw_uid) == -1) {
528 LOG(LOG_ERR, "Switching to user %s", PTSCD_USER_NAME);
535 if (buf != NULL) xfree(buf);
541 * dir group => PTSC_GROUP_NAME
543 * flag 0:read, 1:read/write
545 static int chmodDir(char *dirpath, int flag) {
546 int rc = PTS_SUCCESS;
547 struct group *ptsc_grp;
554 buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
558 buf = xmalloc(buf_len);
560 LOG(LOG_ERR, "no memory");
564 rc = getgrnam_r(PTSC_GROUP_NAME, &grp, buf, buf_len, &ptsc_grp);
566 LOG(LOG_ERR, "getgrnam_r");
570 if (ptsc_grp == NULL) {
571 LOG(LOG_ERR, "ptsc_grp == NULL");
589 S_IRUSR | S_IWUSR | S_IXUSR |
598 S_IRUSR | S_IWUSR | S_IXUSR |
599 S_IRGRP | S_IWGRP | S_IXGRP);
607 if (buf != NULL) xfree(buf);
615 int main(int argc, char *argv[]) {
617 OPENPTS_CONFIG *conf = NULL;
618 char *config_filename = NULL;
619 int command = COMMAND_STATUS;
622 #ifdef CONFIG_AUTO_RM_UPDATE
626 /* properties by cmdline */
627 OPENPTS_PROPERTY *prop;
631 setSyslogCommandName("ptsc");
634 while ((c = getopt(argc, argv, "ic:uUefDtsmvP:Rzh")) != EOF) {
637 command = COMMAND_INIT;
640 command = COMMAND_UPDATE;
643 #ifdef CONFIG_AUTO_RM_UPDATE
644 command = COMMAND_AUTO_UPDATE;
648 command = COMMAND_STATUS;
651 command = COMMAND_SELFTEST;
654 command = COMMAND_STARTUP;
657 command = COMMAND_CLEAR;
663 command = COMMAND_IFM;
664 /* not everything should go to syslog - on some systems
665 this could go to a log file - let default behaviour
666 in log.c decide this */
669 config_filename = optarg;
675 #ifdef CONFIG_AUTO_RM_UPDATE
680 conf->srk_password_mode = 1;
683 prop = getPropertyFromArg(optarg);
711 /* Verbose & Logging */
712 if (command == COMMAND_IFM) {
713 /* Set IF-M log location, syslog or file(for DEBUG) */
714 setLogLocation(OPENPTS_LOG_SYSLOG, NULL);
716 /* Set logging (location,filename) by ENV */
717 determineLogLocationByEnv();
721 if (rc != PTS_SUCCESS) {
722 LOG(LOG_INFO, "preparePriv fail\n");
726 conf = newPtsConfig();
728 LOG(LOG_ERR, "internal error\n"); // TODO(munetoh)
732 /* set the DEBUG level, 1,2,3 */
733 if (getVerbosity() > 2) {
734 setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG | DEBUG_FSM_FLAG | DEBUG_CAL_FLAG);
735 } else if (getVerbosity() > 1) {
736 setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG);
737 } else if (getVerbosity() > 0) {
738 setDebugFlags(DEBUG_FLAG);
741 DEBUG("VERBOSITY (%d), DEBUG mode (0x%x)\n", getVerbosity(), getDebugFlags());
746 /* load config, /etc/ptsc.conf */
747 if (config_filename == NULL) {
748 // this goto stdout and bad with "-m"
749 VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE,
750 "Config file: %s\n"), PTSC_CONFIG_FILE);
751 rc = readPtsConfig(conf, PTSC_CONFIG_FILE);
752 if (rc != PTS_SUCCESS) {
753 DEBUG("readPtsConfig() failed\n");
757 VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE,
758 "Config file: %s\n"), config_filename);
759 rc = readPtsConfig(conf, config_filename);
760 if (rc != PTS_SUCCESS) {
761 DEBUG("readPtsConfig() failed\n");
768 /* Check initialization */
769 if (command != COMMAND_INIT) {
771 if (checkFile(conf->uuid->filename) != OPENPTS_FILE_EXISTS) {
773 LOG(LOG_ERR, "ptsc is not initialized yet");
774 ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_NOT_INITIALIZED,
775 "ptsc is not initialized yet.\n\n"));
780 /* only do this when needed */
781 if (command != COMMAND_STATUS) {
783 if (checkDir(conf->ir_dir) != PTS_SUCCESS) {
784 rc = makeDir(conf->ir_dir);
785 if (rc != PTS_SUCCESS) {
786 LOG(LOG_ERR, "Can not create the dir to store IR, %s\n", conf->ir_dir);
789 rc = chmodDir(conf->ir_dir, 1);
790 if (rc != PTS_SUCCESS) {
791 LOG(LOG_ERR, "Can not create the dir to store IR, %s\n", conf->ir_dir);
797 /* initialize the PTS collector */
798 if (command == COMMAND_INIT) {
799 VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_INIT_RM, "Initializing Reference Manifest\n"));
800 rc = init(conf, prop_num, start, end);
805 /* Clear the PTS collector */
806 if (command == COMMAND_CLEAR) {
807 rc = clear(conf, force);
814 if (conf->rm_uuid == NULL) {
815 LOG(LOG_ERR, "rm_uuid is missing");
819 rc = readOpenptsUuidFile(conf->rm_uuid);
820 if (rc != PTS_SUCCESS) {
821 DEBUG("readOpenptsUuidFile(%s) failed\n", conf->rm_uuid->filename);
822 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAILED_READ_RM_UUID,
823 "Failed to read the Reference Manifest UUID file '%s':\n"
824 "Please ensure on the target that:\n"
825 " * ptsc has been initialized (ptsc -i)\n"
826 " * you (uid==%d) are allowed to attest (i.e. a member of group '%s')\n\n"),
827 conf->rm_uuid->filename, getuid(), PTSC_GROUP_NAME);
830 DEBUG("conf->str_rm_uuid : %s\n", conf->rm_uuid->str);
835 if (conf->newrm_uuid == NULL) {
836 LOG(LOG_ERR, "newrm_uuid is missing.");
840 rc = readOpenptsUuidFile(conf->newrm_uuid);
841 if (rc != PTS_SUCCESS) {
842 DEBUG("conf->str_newrm_uuid : missing (file:%s)\n", conf->newrm_uuid->filename);
845 DEBUG("conf->str_newrm_uuid : %s (for next boot)\n", conf->newrm_uuid->str);
849 /* load RSA PUB key */
850 // TODO single key => multiple keys?
852 LOG(LOG_TODO, "CONFIG_NO_TSS, no TPM_PUBKEY\n");
853 conf->pubkey_length = 0;
856 /* only do this when needed */
857 if (command != COMMAND_STATUS) {
861 conf->aik_storage_type, // TSS_PS_TYPE_SYSTEM,
862 conf->srk_password_mode,
863 conf->tpm_resetdalock,
864 conf->aik_storage_filename, // NULL,
866 &conf->pubkey_length,
868 if (rc != TSS_SUCCESS) {
869 LOG(LOG_ERR, "getTssPubKey() fail rc=0x%x srk password mode=%d, key =%s\n",
870 rc, conf->srk_password_mode, conf->uuid->str);
871 OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE,
872 "TSS communications failure. Is tcsd running?\n"));
880 #ifdef CONFIG_AUTO_RM_UPDATE
881 case COMMAND_AUTO_UPDATE:
882 /* update by command, but HUP is better */
883 VERBOSE(1, "Updating Reference Manifest\n");
885 rc = update(conf, prop_num, start, end, remove);
886 if (rc != PTS_SUCCESS) {
887 LOG(LOG_ERR, "update was fail\n");
892 rc = printCollectorStatus(conf);
894 case COMMAND_SELFTEST:
895 rc = selftest(conf, prop_num, start, end);
896 if (rc == OPENPTS_SELFTEST_SUCCESS) {
897 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SUCCESS, "selftest - OK\n"));
898 LOG(LOG_INFO, "selftest - OK\n");
899 } else if (rc == OPENPTS_SELFTEST_RENEWED) {
900 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_RENEWED, "selftest - Renewed\n"));
901 LOG(LOG_INFO, "selftest - Renewed\n");
902 } else if (rc == OPENPTS_SELFTEST_FALLBACK) {
903 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FALLBACK, "selftest - fallback\n"));
904 LOG(LOG_INFO, "selftest - fallback\n");
905 } else if (rc == OPENPTS_SELFTEST_FAILED) {
906 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAIL, "selftest - fail\n"));
907 LOG(LOG_INFO, "selftest - fail\n");
909 LOG(LOG_ERR, "TBD\n");
912 case COMMAND_STARTUP:
913 rc = selftest(conf, prop_num, start, end);
914 if (rc == OPENPTS_SELFTEST_SUCCESS) {
915 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SUCCESS, "selftest - OK\n"));
916 LOG(LOG_INFO, "selftest - OK\n");
918 extendEvCollectorStart(conf); // collector.c
919 } else if (rc == OPENPTS_SELFTEST_RENEWED) {
920 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_RENEWED, "selftest - Renewed\n"));
921 LOG(LOG_INFO, "selftest - Renewed\n");
923 extendEvCollectorStart(conf);
924 } else if (rc == OPENPTS_SELFTEST_FALLBACK) {
925 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FALLBACK, "selftest - fallback\n"));
926 LOG(LOG_INFO, "selftest - fallback\n");
928 extendEvCollectorStart(conf);
929 } else if (rc == OPENPTS_SELFTEST_FAILED) {
930 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAIL, "selftest - fail\n"));
931 LOG(LOG_INFO, "selftest - fail\n");
932 if (conf->autoupdate == 1) {
933 LOG(LOG_ERR, "selftest failed, trying to generate a new manifest\n");
935 conf->rm_uuid->status = OPENPTS_UUID_FILENAME_ONLY;
936 if (conf->rm_uuid->uuid != NULL) freeUuid(conf->rm_uuid->uuid);
937 if (conf->rm_uuid->str != NULL) xfree(conf->rm_uuid->str);
938 if (conf->rm_uuid->time != NULL) xfree(conf->rm_uuid->time);
939 conf->rm_uuid->uuid = NULL;
940 conf->rm_uuid->str = NULL;
941 conf->rm_uuid->time = NULL;
943 /* gen new RM_UUID and RM */
944 rc = newrm(conf, prop_num, start, end);
945 if (rc != PTS_SUCCESS) {
946 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_FAIL,
947 "Failed to generated a reference manifest\n"));
948 LOG(LOG_INFO, "Failed to generated a reference manifest\n");
951 rc = selftest(conf, prop_num, start, end);
952 if (rc == OPENPTS_SELFTEST_SUCCESS) {
953 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SUCCESS, "selftest - OK\n"));
954 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_SUCCESS,
955 "Successfully generated the reference manifest\n"));
956 LOG(LOG_INFO, "selftest - OK\n");
957 LOG(LOG_INFO, "Successfully generated the reference manifest\n");
958 } else if (rc == OPENPTS_SELFTEST_RENEWED) {
959 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_RENEWED, "selftest - Renewed\n"));
960 LOG(LOG_INFO, "selftest - Renewed\n");
962 LOG(LOG_ERR, "TBD\n");
965 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_WONT,
966 "selftest failed, keeping existing manifests as requested by configuration\n"));
967 LOG(LOG_INFO, "selftest failed, keeping existing manifests as requested by configuration\n");
970 LOG(LOG_ERR, "TBD\n");
975 conf->rm_uuid->status = OPENPTS_UUID_FILENAME_ONLY;
976 if (conf->rm_uuid->uuid != NULL) freeUuid(conf->rm_uuid->uuid);
977 if (conf->rm_uuid->str != NULL) xfree(conf->rm_uuid->str);
978 if (conf->rm_uuid->time != NULL) xfree(conf->rm_uuid->time);
979 conf->rm_uuid->uuid = NULL;
980 conf->rm_uuid->str = NULL;
981 conf->rm_uuid->time = NULL;
983 /* gen new RM_UUID and RM */
984 rc = newrm(conf, prop_num, start, end);
985 if (rc != PTS_SUCCESS) {
986 LOG(LOG_ERR, "newrm() fail\n");
991 rc = selftest(conf, prop_num, start, end);
992 if (rc == OPENPTS_SELFTEST_SUCCESS) {
993 VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_SUCCESS,
994 "Successfully generated the reference manifest\n"));
995 } else if (rc == OPENPTS_SELFTEST_RENEWED) {
996 LOG(LOG_TODO, "TBD\n");
998 LOG(LOG_TODO, "TBD\n");
1002 /* run colelctor IF-M */
1003 rc = collector(conf);
1006 LOG(LOG_ERR, "bad command\n");
1011 freePtsConfig(conf);
1013 if (rc != PTS_SUCCESS) {
1014 LOG(LOG_ERR, "ptsc exit. rc = %d", rc);