2013年11月28日星期四

pam_env.so

本邮件内容由第三方提供,如果您不想继续收到该邮件,可 点此退订
pam_env.so  阅读原文»

用户名:d伪装d 文章数:40 评论数:6
访问量:5192:4952:484:3 注册日期:2011-02-25



OS version:Red Hat Enterprise Linux Server release 6.4
Kernel version:2.6.32-358.el6.x86_64


-------------------------------------------------------------------------

准备工作:


[root@Zhai ~]# env | grep pam_env_test1
[root@Zhai ~]# env | grep pam_env_test2
[root@Zhai ~]# env | grep pam_env_test3
[root@Zhai ~]# env | grep pam_env_test4
[root@Zhai ~]# su - pam_test1
[pam_test1@Zhai ~]$ env | grep pam_env_test1
[pam_test1@Zhai ~]$ env | grep pam_env_test2
[pam_test1@Zhai ~]$ env | grep pam_env_test3
[pam_test1@Zhai ~]$ env | grep pam_env_test4

验证1:


[root@Zhai ~]# vi /etc/pam.d/su

auth required pam_unix.so
account required pam_unix.so
session required pam_env.so conffile=/etc/security/pam_env.conf

[root@Zhai ~]# vi /etc/security/pam_env.conf

pam_env_test1 DEFAULT=Zhai_kang
pam_env_test2 DEFAULT="Zhai_kang 2013"
pam_env_test3 DEFAULT="Zhai_kang 201311" OVERRIDE=${pam_env_test1}
pam_env_test4 DEFAULT=zhai_kang:201311\

082241560.jpg

验证2:


[root@Zhai ~]# cat /etc/security/pam_env.conf

pam_env_test1 DEFAULT=Zhai_kang
pam_env_test2 DEFAULT="Zhai_kang 2013"
pam_env_test3 DEFAULT="Zhai_kang 201311" OVERRIDE=${pam_env_test1}
pam_env_test4 DEFAULT=zhai_kang:201311\

[root@Zhai ~]# vi /etc/environment

pam_env_test4="----Zhai_kang V----"
pam_test5="Kang_Zhai 2013"

[root@Zhai ~]# vi /etc/pam.d/su

auth required pam_unix.so
account required pam_unix.so
session required pam_env.so conffile=/etc/security/pam_env.conf envfile=/etc/environment readenv=1

082427129.jpg

验证3:


[root@Zhai ~]# cat /etc/security/pam_env.conf

pam_env_test1 DEFAULT=Zhai_kang
pam_env_test2 DEFAULT="Zhai_kang 2013"
pam_env_test3 DEFAULT="Zhai_kang 201311" OVERRIDE=${pam_env_test1}
pam_env_test4 DEFAULT=zhai_kang:201311\

[root@Zhai ~]# cat /etc/environment

pam_env_test4="----Zhai_kang V----"
pam_test5="Kang_Zhai 2013"

[root@Zhai ~]# vi /etc/pam.d/su

auth required pam_unix.so
account required pam_unix.so
session required pam_env.so conffile=/etc/security/pam_env.conf envfile=/etc/environment readenv=1 user_envfile=.pam_environment user_readenv=1

[pam_test1@Zhai ~]$ vi .pam_environment

编程乐趣:C#实现12306自动登录(2013年11月27)  阅读原文»

编程乐趣:C#实现12306自动登录(2013年11月27)

依然使用IE9的捕获参数,做了一个12306的登录功能。参照了网上童鞋们的做法。
其他都和前面几篇读取余票、票价一样,不过登录要用到证书的问题,这个参考了一个网上的例子。
不过12306会随时变化,下面的登录不一定一直都能成功。如果12306有变化,大家可以根据变化对代码做修改。总之使用的方法不变,就是捕获参数和url,然后自己补充参数。
效果如下:
SouthEast
项目名称:Test12306AutoLogin;
环境:.net 4.0,Visual studio 2010;
项目图:
SouthEast
直接贴代码了。
核心代码如下,
信任证书代码:

   public class Messenger      {          public Messenger()          {          }          public void Register(string message, Action callback)          {              this.Register(message, callback, null);          }          public void Register<T>(string message, Action<T> callback)          {              this.Register(message, callback, typeof(T));          }          void Register(string message, Delegate callback, Type parameterType)          {              if (String.IsNullOrEmpty(message))                  throw new ArgumentException("'message' cannot be null or empty.");              if (callback == null)                  throw new ArgumentNullException("callback");              this.VerifyParameterType(message, parameterType);              _messageToActionsMap.AddAction(message, callback.Target, callback.Method, parameterType);          }          [Conditional("DEBUG")]          void VerifyParameterType(string message, Type parameterType)          {              Type previouslyRegisteredParameterType = null;              if (_messageToActionsMap.TryGetParameterType(message, out previouslyRegisteredParameterType))              {                  if (previouslyRegisteredParameterType != null && parameterType != null)                  {                      if (!previouslyRegisteredParameterType.Equals(parameterType))                          throw new InvalidOperationException(string.Format(                              "The registered action's parameter type is inconsistent with the previously registered actions for message '{0}'.\nExpected: {1}\nAdding: {2}",                              message,                              previouslyRegisteredParameterType.FullName,                              parameterType.FullName));                  }                  else                  {                      // One, or both, of previouslyRegisteredParameterType or callbackParameterType are null.                      if (previouslyRegisteredParameterType != parameterType)   // not both null?                      {                          throw new TargetParameterCountException(string.Format(                              "The registered action has a number of parameters inconsistent with the previously registered actions for message \"{0}\".\nExpected: {1}\nAdding: {2}",                              message,                              previouslyRegisteredParameterType == null ? 0 : 1,                              parameterType == null ? 0 : 1));                      }                  }              }          }          public void NotifyColleagues(string message, object parameter)          {              if (String.IsNullOrEmpty(message))                  throw new ArgumentException("'message' cannot be null or empty.");              Type registeredParameterType;              if (_messageToActionsMap.TryGetParameterType(message, out registeredParameterType))              {                  if (registeredParameterType == null)                      throw new TargetParameterCountException(string.Format("Cannot pass a parameter with message '{0}'. Registered action(s) expect no parameter.", message));              }              var actions = _messageToActionsMap.GetActions(message);              if (actions != null)                  actions.ForEach(action => action.DynamicInvoke(parameter));          }          public void NotifyColleagues(string message)          {              if (String.IsNullOrEmpty(message))                  throw new ArgumentException("'message' cannot be null or empty.");              Type registeredParameterType;              if (_messageToActionsMap.TryGetParameterType(message, out registeredParameterType))              {                  if (registeredParameterType != null)                      throw new TargetParameterCountException(string.Format("Must pass a parameter of type {0} with this message. Registered action(s) expect it.", registeredParameterType.FullName));              }              var actions = _messageToActionsMap.GetActions(message);              if (actions != null)                  actions.ForEach(action => action.DynamicInvoke());          }          private class MessageToActionsMap          {              internal MessageToActionsMap()              {              }              internal void AddAction(string message, object target, MethodInfo method, Type actionType)              {                  if (message == null)                      throw new ArgumentNullException("message");                  if (method == null)                      throw new ArgumentNullException("method");                  lock (_map)                  {                      if (!_map.ContainsKey(message))                          _map[message] = new List<WeakAction>();                      _map[message].Add(new WeakAction(target, method, actionType));                  }              }              internal List<Delegate> GetActions(string message)              {                  if (message == null)                      throw new ArgumentNullException("message");                  List<Delegate> actions;                  lock (_map)                  {                      if (!_map.ContainsKey(message))                          return null;                      List<WeakAction> weakActions = _map[message];                      actions = new List<Delegate>(weakActions.Count);                      for (int i = weakActions.Count - 1; i > -1; --i)                      {                          WeakAction weakAction = weakActions;                          if (weakAction == null)                              continue;                          Delegate action = weakAction.CreateAction();                          if (action != null)                          {                              actions.Add(action);                          }                          else                          {                              // The target object is dead, so get rid of the weak action.                              weakActions.Remove(weakAction);                          }                      }                      // Delete the list from the map if it is now empty.                      if (weakActions.Count == 0)                          _map.Remove(message);                  }                  // Reverse the list to ensure the callbacks are invoked in the order they were registered.                  actions.Reverse();                  return actions;              }              internal bool TryGetParameterType(string message, out Type parameterType)              {                  if (message == null)                      throw new ArgumentNullException("message");                  parameterType = null;                  List<WeakAction> weakActions;                  lock (_map)                  {                      if (!_map.TryGetValue(message, out weakActions) || weakActions.Count == 0)                          return false;                  }                  parameterType = weakActions[0].ParameterType;                  return true;              }              readonly Dictionary<string, List<WeakAction>> _map = new Dictionary<string, List<WeakAction>>();          }          private class WeakAction          {              internal WeakAction(object target, MethodInfo method, Type parameterType)              {                  if (target == null)                  {                      _targetRef = null;                  }                  else                  {                      _targetRef = new WeakReference(target);                  }                  _method = method;                  this.ParameterType = parameterType;                  if (parameterType == null)                  {                      _delegateType = typeof(Action);                  }                  else                  {                      _delegateType = typeof(Action<>).MakeGenericType(parameterType);                  }              }              internal Delegate CreateAction()              {                  // Rehydrate into a real Action object, so that the method can be invoked.                  if (_targetRef == null)                  {                      return Delegate.CreateDelegate(_delegateType, _method);                  }                  else                  {                      try                      {                          object target = _targetRef.Target;                          if (target != null)                              return Delegate.CreateDelegate(_delegateType, target, _method);                      }                      catch                     

阅读更多内容

没有评论:

发表评论

声明

转载有价值的IT博客,版权属原作者所有

标签

博客归档