示例#1
0
  private Map<NativeAttribute, String> buildPasswdSwitches(
      SolarisEntry entry, SolarisConnection conn) {
    Map<NativeAttribute, String> passwdSwitches =
        new EnumMap<NativeAttribute, String>(NativeAttribute.class);
    passwdSwitches.put(NativeAttribute.PWSTAT, "-f");
    // passwdSwitches.put(NativeAttribute.PW_LAST_CHANGE, null); // this is
    // not used attribute (see LoginsCommand and its SVIDRA counterpart).
    // TODO erase this comment.
    passwdSwitches.put(NativeAttribute.MIN_DAYS_BETWEEN_CHNG, "-n");
    passwdSwitches.put(NativeAttribute.MAX_DAYS_BETWEEN_CHNG, "-x");
    passwdSwitches.put(NativeAttribute.DAYS_BEFORE_TO_WARN, "-w");

    String lockFlag = null;
    Attribute lock = entry.searchForAttribute(NativeAttribute.LOCK);
    if (lock != null) {
      Object lockValue = AttributeUtil.getSingleValue(lock);
      if (lockValue == null) {
        throw new IllegalArgumentException("missing value for attribute LOCK");
      }
      boolean isLock = (Boolean) lockValue;
      if (isLock) {
        lockFlag = "-l";
      } else {
        // *unlocking* differs in Solaris 8,9 and in Solaris 10+:
        lockFlag = (conn.isVersionLT10()) ? "-df" : "-u";
        passwdSwitches.put(NativeAttribute.LOCK, lockFlag);
      }
    }
    if (lockFlag != null) {
      passwdSwitches.put(NativeAttribute.LOCK, lockFlag);
    }
    return passwdSwitches;
  }
示例#2
0
 @Override
 public String getRenameDirScript(SolarisEntry entry, String newName) {
   // @formatter:off
   String renameDir =
       "NEWNAME="
           + newName
           + "; "
           + "OLDNAME="
           + entry.getName()
           + "; "
           + "OLDDIR=`"
           + conn.buildCommand(true, "logins")
           + " -ox -l $NEWNAME | cut -d: -f6`; "
           + "OLDBASE=`basename $OLDDIR`; "
           + "if [ \"$OLDNAME\" = \"$OLDBASE\" ]; then\n"
           + "PARENTDIR=`dirname $OLDDIR`; "
           + "NEWDIR=`echo $PARENTDIR/$NEWNAME`; "
           + "if [ ! -s $NEWDIR ]; then "
           + conn.buildCommand(true, "chown")
           + " $NEWNAME $OLDDIR; "
           + conn.buildCommand(true, "mv")
           + " -f $OLDDIR $NEWDIR; "
           + "if [ $? -eq 0 ]; then\n"
           + conn.buildCommand(true, "usermod")
           + " -d $NEWDIR $NEWNAME; "
           + "fi; "
           + "fi; "
           + "fi";
   // @formatter:off
   return renameDir;
 }
示例#3
0
  @Override
  public void configurePasswordProperties(SolarisEntry entry, SolarisConnection conn) {
    Map<NativeAttribute, String> passwdSwitches = buildPasswdSwitches(entry, conn);
    final String cmdSwitches = CommandSwitches.formatCommandSwitches(entry, conn, passwdSwitches);
    if (cmdSwitches.length() == 0) {
      return; // no password related attribute present in the entry.
    }

    try {
      final String command = conn.buildCommand(true, "passwd", cmdSwitches, entry.getName());
      final String out = conn.executeCommand(command);
      final String loweredOut = out.toLowerCase();
      if (loweredOut.contains("usage:")
          || loweredOut.contains("password aging is disabled")
          || loweredOut.contains("command not found")) {
        throw new ConnectorException(
            "Error during configuration of password related attributes. Buffer content: <"
                + out
                + ">");
      }
    } catch (Exception ex) {
      throw ConnectorException.wrap(ex);
    }
  }