Print this page
Code review comments from pmooney (sundry), and igork (screwups in zonecfg refactoring)


2100                 if (psettab.zone_importance[0] != '\0')
2101                         (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
2102                             pt_to_str(PT_IMPORTANCE), psettab.zone_importance);
2103                 (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
2104         }
2105 
2106         if ((err = zonecfg_setadminent(handle)) != Z_OK) {
2107                 zone_perror(zone, err, B_FALSE);
2108                 goto done;
2109         }
2110         while (zonecfg_getadminent(handle, &admintab) == Z_OK) {
2111                 (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
2112                     rt_to_str(RT_ADMIN));
2113                 export_prop(of, PT_USER, admintab.zone_admin_user);
2114                 export_prop(of, PT_AUTHS, admintab.zone_admin_auths);
2115                 (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
2116         }
2117 
2118         (void) zonecfg_endadminent(handle);
2119 
2120         if ((err = zonecfg_getsecflagsent(handle, &secflagstab)) != Z_OK) {
2121                 zone_perror(zone, err, B_FALSE);
2122                 goto done;
2123         }
2124 
2125         (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
2126             rt_to_str(RT_SECFLAGS));
2127         export_prop(of, PT_DEFAULT, secflagstab.zone_secflags_default);
2128         export_prop(of, PT_LOWER, secflagstab.zone_secflags_lower);
2129         export_prop(of, PT_UPPER, secflagstab.zone_secflags_upper);
2130         (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));

2131 
2132         /*
2133          * There is nothing to export for pcap since this resource is just
2134          * a container for an rctl alias.
2135          */
2136 
2137 done:
2138         if (need_to_close)
2139                 (void) fclose(of);
2140 }
2141 
2142 void
2143 exit_func(cmd_t *cmd)
2144 {
2145         int arg, answer;
2146         boolean_t arg_err = B_FALSE;
2147 
2148         optind = 0;
2149         while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) {
2150                 switch (arg) {


5607                 if (strlen(user.zone_admin_user) > 0 &&
5608                     strcmp(user.zone_admin_user, lookup.zone_admin_user) != 0)
5609                         continue;       /* no match */
5610                 output_auth(fp, &lookup);
5611                 output = B_TRUE;
5612         }
5613         (void) zonecfg_endadminent(handle);
5614         /*
5615          * If a property n/v pair was specified, warn the user if there was
5616          * nothing to output.
5617          */
5618         if (!output && cmd->cmd_prop_nv_pairs > 0)
5619                 (void) printf(gettext("No such %s resource.\n"),
5620                     rt_to_str(RT_ADMIN));
5621 }
5622 
5623 static void
5624 info_secflags(zone_dochandle_t handle, FILE *fp)
5625 {
5626         struct zone_secflagstab sftab;
5627         int err;
5628 
5629         if ((err = zonecfg_lookup_secflags(handle, &sftab)) != Z_OK) {
5630                 zone_perror(zone, err, B_TRUE);
5631                 return;
5632         }
5633 

5634         output_secflags(fp, &sftab);

5635 }
5636 
5637 void
5638 info_func(cmd_t *cmd)
5639 {
5640         FILE *fp = stdout;
5641         boolean_t need_to_close = B_FALSE;
5642         int type;
5643         int res1, res2;
5644         uint64_t swap_limit;
5645         uint64_t locked_limit;
5646 
5647         assert(cmd != NULL);
5648 
5649         if (initialize(B_TRUE) != Z_OK)
5650                 return;
5651 
5652         /* don't page error output */
5653         if (interactive_mode) {
5654                 if ((fp = pager_open()) != NULL)


6376         }
6377         while (zonecfg_getadminent(handle, &admintab) == Z_OK) {
6378                 check_reqd_prop(admintab.zone_admin_user, RT_ADMIN,
6379                     PT_USER, &ret_val);
6380                 check_reqd_prop(admintab.zone_admin_auths, RT_ADMIN,
6381                     PT_AUTHS, &ret_val);
6382                 if ((ret_val == Z_OK) && (getpwnam(admintab.zone_admin_user)
6383                     == NULL)) {
6384                         zerr(gettext("%s %s is not a valid username"),
6385                             pt_to_str(PT_USER),
6386                             admintab.zone_admin_user);
6387                         ret_val = Z_BAD_PROPERTY;
6388                 }
6389                 if ((ret_val == Z_OK) && (!zonecfg_valid_auths(
6390                     admintab.zone_admin_auths, zone))) {
6391                         ret_val = Z_BAD_PROPERTY;
6392                 }
6393         }
6394         (void) zonecfg_endadminent(handle);
6395 
6396         if ((err = zonecfg_getsecflagsent(handle, &secflagstab)) != Z_OK) {
6397                 zone_perror(zone, err, B_TRUE);
6398                 return;
6399         }
6400 
6401         /*
6402          * No properties are required, but any specified should be
6403          * valid
6404          */
6405         if (verify_secflags(&secflagstab) != B_TRUE) {
6406                 /* Error is reported from verify_secflags */
6407                 ret_val = Z_BAD_PROPERTY;
6408         }

6409 
6410         if (!global_scope) {
6411                 zerr(gettext("resource specification incomplete"));
6412                 saw_error = B_TRUE;
6413                 if (ret_val == Z_OK)
6414                         ret_val = Z_INSUFFICIENT_SPEC;
6415         }
6416 
6417         if (save) {
6418                 if (ret_val == Z_OK) {
6419                         if ((ret_val = zonecfg_save(handle)) == Z_OK) {
6420                                 need_to_commit = B_FALSE;
6421                                 (void) strlcpy(revert_zone, zone,
6422                                     sizeof (revert_zone));
6423                         }
6424                 } else {
6425                         zerr(gettext("Zone %s failed to verify"), zone);
6426                 }
6427         }
6428         if (ret_val != Z_OK)




2100                 if (psettab.zone_importance[0] != '\0')
2101                         (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET),
2102                             pt_to_str(PT_IMPORTANCE), psettab.zone_importance);
2103                 (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
2104         }
2105 
2106         if ((err = zonecfg_setadminent(handle)) != Z_OK) {
2107                 zone_perror(zone, err, B_FALSE);
2108                 goto done;
2109         }
2110         while (zonecfg_getadminent(handle, &admintab) == Z_OK) {
2111                 (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
2112                     rt_to_str(RT_ADMIN));
2113                 export_prop(of, PT_USER, admintab.zone_admin_user);
2114                 export_prop(of, PT_AUTHS, admintab.zone_admin_auths);
2115                 (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
2116         }
2117 
2118         (void) zonecfg_endadminent(handle);
2119 
2120         if (zonecfg_getsecflagsent(handle, &secflagstab) == Z_OK) {




2121                 (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
2122                     rt_to_str(RT_SECFLAGS));
2123                 export_prop(of, PT_DEFAULT, secflagstab.zone_secflags_default);
2124                 export_prop(of, PT_LOWER, secflagstab.zone_secflags_lower);
2125                 export_prop(of, PT_UPPER, secflagstab.zone_secflags_upper);
2126                 (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
2127         }
2128 
2129         /*
2130          * There is nothing to export for pcap since this resource is just
2131          * a container for an rctl alias.
2132          */
2133 
2134 done:
2135         if (need_to_close)
2136                 (void) fclose(of);
2137 }
2138 
2139 void
2140 exit_func(cmd_t *cmd)
2141 {
2142         int arg, answer;
2143         boolean_t arg_err = B_FALSE;
2144 
2145         optind = 0;
2146         while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) {
2147                 switch (arg) {


5604                 if (strlen(user.zone_admin_user) > 0 &&
5605                     strcmp(user.zone_admin_user, lookup.zone_admin_user) != 0)
5606                         continue;       /* no match */
5607                 output_auth(fp, &lookup);
5608                 output = B_TRUE;
5609         }
5610         (void) zonecfg_endadminent(handle);
5611         /*
5612          * If a property n/v pair was specified, warn the user if there was
5613          * nothing to output.
5614          */
5615         if (!output && cmd->cmd_prop_nv_pairs > 0)
5616                 (void) printf(gettext("No such %s resource.\n"),
5617                     rt_to_str(RT_ADMIN));
5618 }
5619 
5620 static void
5621 info_secflags(zone_dochandle_t handle, FILE *fp)
5622 {
5623         struct zone_secflagstab sftab;






5624 
5625         if (zonecfg_lookup_secflags(handle, &sftab) == Z_OK) {
5626                 output_secflags(fp, &sftab);
5627         }
5628 }
5629 
5630 void
5631 info_func(cmd_t *cmd)
5632 {
5633         FILE *fp = stdout;
5634         boolean_t need_to_close = B_FALSE;
5635         int type;
5636         int res1, res2;
5637         uint64_t swap_limit;
5638         uint64_t locked_limit;
5639 
5640         assert(cmd != NULL);
5641 
5642         if (initialize(B_TRUE) != Z_OK)
5643                 return;
5644 
5645         /* don't page error output */
5646         if (interactive_mode) {
5647                 if ((fp = pager_open()) != NULL)


6369         }
6370         while (zonecfg_getadminent(handle, &admintab) == Z_OK) {
6371                 check_reqd_prop(admintab.zone_admin_user, RT_ADMIN,
6372                     PT_USER, &ret_val);
6373                 check_reqd_prop(admintab.zone_admin_auths, RT_ADMIN,
6374                     PT_AUTHS, &ret_val);
6375                 if ((ret_val == Z_OK) && (getpwnam(admintab.zone_admin_user)
6376                     == NULL)) {
6377                         zerr(gettext("%s %s is not a valid username"),
6378                             pt_to_str(PT_USER),
6379                             admintab.zone_admin_user);
6380                         ret_val = Z_BAD_PROPERTY;
6381                 }
6382                 if ((ret_val == Z_OK) && (!zonecfg_valid_auths(
6383                     admintab.zone_admin_auths, zone))) {
6384                         ret_val = Z_BAD_PROPERTY;
6385                 }
6386         }
6387         (void) zonecfg_endadminent(handle);
6388 
6389         if (zonecfg_getsecflagsent(handle, &secflagstab) == Z_OK) {




6390                 /*
6391                  * No properties are required, but any specified should be
6392                  * valid
6393                  */
6394                 if (verify_secflags(&secflagstab) != B_TRUE) {
6395                         /* Error is reported from verify_secflags */
6396                         ret_val = Z_BAD_PROPERTY;
6397                 }
6398         }
6399 
6400         if (!global_scope) {
6401                 zerr(gettext("resource specification incomplete"));
6402                 saw_error = B_TRUE;
6403                 if (ret_val == Z_OK)
6404                         ret_val = Z_INSUFFICIENT_SPEC;
6405         }
6406 
6407         if (save) {
6408                 if (ret_val == Z_OK) {
6409                         if ((ret_val = zonecfg_save(handle)) == Z_OK) {
6410                                 need_to_commit = B_FALSE;
6411                                 (void) strlcpy(revert_zone, zone,
6412                                     sizeof (revert_zone));
6413                         }
6414                 } else {
6415                         zerr(gettext("Zone %s failed to verify"), zone);
6416                 }
6417         }
6418         if (ret_val != Z_OK)