Filter:   InfoImg
download SftpATTRS.cs
Language: C#
Copyright: (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
LOC: 218
Project Info
labmanager - A C# application for administ...bs...(labmanager)
Server: Google
Type: svn
...er\trunk\lib\SharpSSH\jsch\
   Buffer.cs
   Channel.cs
   Channel.old.cs
   ChannelDirectTCPIP.cs
   ChannelExec.cs
   ChannelForwardedTCPIP.cs
   ChannelSession.cs
   ChannelSftp.cs
   ChannelSftpOld.cs
   ChannelSftpStreamGet.cs
   ChannelSftpStreamPut.cs
   ChannelShell.cs
   ChannelSubsystem.cs
   ChannelX11.cs
   Cipher.cs
   Compression.cs
   DH.cs
   DHG1.cs
   DHGEX.cs
   ForwardedTCPIPDaemon.cs
   HASH.cs
   HostKey.cs
   HostKeyRepository.cs
   Identity.cs
   IdentityFile.cs
   IO.cs
   JSch.cs
   JSchAuthCancelException.cs
   JSchException.cs
   ...PartialAuthException.cs
   KeyExchange.cs
   KeyPair.cs
   KeyPairDSA.cs
   KeyPairGenDSA.cs
   KeyPairGenRSA.cs
   KeyPairRSA.cs
   KnownHosts.cs
   MAC.cs
   Packet.cs
   PortWatcher.cs
   Proxy.cs
   Random.cs
   Request.cs
   RequestExec.cs
   RequestPtyReq.cs
   RequestSftp.cs
   RequestShell.cs
   RequestSignal.cs
   RequestSubsystem.cs
   RequestWindowChange.cs
   RequestX11.cs
   ServerSocketFactory.cs
   Session.cs
   Session.old.cs
   SftpATTRS.cs
   SftpException.cs
   SftpProgressMonitor.cs
   SignatureDSA.cs
   SignatureRSA.cs
   SocketFactory.cs
   UIKeyboardInteractive.cs
   UserAuth.cs
   ...hKeyboardInteractive.cs
   UserAuthNone.cs
   UserAuthPassword.cs
   UserAuthPublicKey.cs
   UserInfo.cs
   Util.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
using System;
using System.Text;

namespace Tamir.SharpSsh.jsch
{
	/* -*-mode:java; c-basic-offset:2; -*- */
	/*
	Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	  1. Redistributions of source code must retain the above copyright notice,
		 this list of conditions and the following disclaimer.

	  2. Redistributions in binary form must reproduce the above copyright 
		 notice, this list of conditions and the following disclaimer in 
		 the documentation and/or other materials provided with the distribution.

	  3. The names of the authors may not be used to endorse or promote products
		 derived from this software without specific prior written permission.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
	FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
	INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
	INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
	LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
	OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
	LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
	NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
	EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	*/

	/*
	  uint32   flags
	  uint64   size           present only if flag SSH_FILEXFER_ATTR_SIZE
	  uint32   uid            present only if flag SSH_FILEXFER_ATTR_UIDGID
	  uint32   gid            present only if flag SSH_FILEXFER_ATTR_UIDGID
	  uint32   permissions    present only if flag SSH_FILEXFER_ATTR_PERMISSIONS
	  uint32   atime          present only if flag SSH_FILEXFER_ACMODTIME
	  uint32   mtime          present only if flag SSH_FILEXFER_ACMODTIME
	  uint32   extended_count present only if flag SSH_FILEXFER_ATTR_EXTENDED
	  string   extended_type
	  string   extended_data
		...      more extended data (extended_type - extended_data pairs),
				 so that number of pairs equals extended_count
	*/
	public class SftpATTRS 
	{

		static  int S_ISUID = 04000; // set user ID on execution
		static  int S_ISGID = 02000; // set group ID on execution
		static  int S_ISVTX = 01000; // sticky bit   ****** NOT DOCUMENTED *****

		static  int S_IRUSR = 00400; // read by owner
		static  int S_IWUSR = 00200; // write by owner
		static  int S_IXUSR = 00100; // execute/search by owner
		static  int S_IREAD = 00400; // read by owner
		static  int S_IWRITE= 00200; // write by owner
		static  int S_IEXEC = 00100; // execute/search by owner

		static  int S_IRGRP = 00040; // read by group
		static  int S_IWGRP = 00020; // write by group
		static  int S_IXGRP = 00010; // execute/search by group

		static  int S_IROTH = 00004; // read by others
		static  int S_IWOTH = 00002; // write by others
		static  int S_IXOTH = 00001; // execute/search by others

		private static int pmask = 0xFFF;

		public String getPermissionsString() 
		{
			StringBuilder buf = new StringBuilder(10);

			if(isDir()) buf.Append('d');
			else if(isLink()) buf.Append('l');
			else buf.Append('-');

			if((permissions & S_IRUSR)!=0) buf.Append('r');
			else buf.Append('-');

			if((permissions & S_IWUSR)!=0) buf.Append('w');
			else buf.Append('-');

			if((permissions & S_ISUID)!=0) buf.Append('s');
			else if ((permissions & S_IXUSR)!=0) buf.Append('x');
			else buf.Append('-');

			if((permissions & S_IRGRP)!=0) buf.Append('r');
			else buf.Append('-');

			if((permissions & S_IWGRP)!=0) buf.Append('w');
			else buf.Append('-');

			if((permissions & S_ISGID)!=0) buf.Append('s');
			else if((permissions & S_IXGRP)!=0) buf.Append('x');
			else buf.Append('-');

			if((permissions & S_IROTH) != 0) buf.Append('r');
			else buf.Append('-');

			if((permissions & S_IWOTH) != 0) buf.Append('w');
			else buf.Append('-');

			if((permissions & S_IXOTH) != 0) buf.Append('x');
			else buf.Append('-');
			return (buf.ToString());
		}

		public String  getAtimeString()
		{
			//SimpleDateFormat locale=new SimpleDateFormat();
			//return (locale.format(new Date(atime)));
			//[tamir] use Time_T2DateTime to convert t_time to DateTime
			DateTime d = Util.Time_T2DateTime((uint)atime);
			return d.ToShortDateString();
			
		}

		public String  getMtimeString()
		{
			//[tamir] use Time_T2DateTime to convert t_time to DateTime
			DateTime date= Util.Time_T2DateTime((uint)mtime);
			return (date.ToString());
		}

		public static  int SSH_FILEXFER_ATTR_SIZE=         0x00000001;
		public static  int SSH_FILEXFER_ATTR_UIDGID=       0x00000002;
		public static  int SSH_FILEXFER_ATTR_PERMISSIONS=  0x00000004;
		public static  int SSH_FILEXFER_ATTR_ACMODTIME=    0x00000008;
		public static  uint SSH_FILEXFER_ATTR_EXTENDED=     0x80000000;

		static  int S_IFDIR=0x4000;
		static  int S_IFLNK=0xa000;

		int flags=0;
		long size;
		internal int uid;
		internal int gid;
		int permissions;
		int atime;
		int mtime;
		String[] extended=null;

		private SftpATTRS()
		{
		}

		internal static SftpATTRS getATTR(Buffer buf)
		{
			SftpATTRS attr=new SftpATTRS();	
			attr.flags=buf.getInt();
			if((attr.flags&SSH_FILEXFER_ATTR_SIZE)!=0){ attr.size=buf.getLong(); }
			if((attr.flags&SSH_FILEXFER_ATTR_UIDGID)!=0)
			{
				attr.uid=buf.getInt(); attr.gid=buf.getInt();
			}
			if((attr.flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0)
			{ 
				attr.permissions=buf.getInt();
			}
			if((attr.flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0)
			{ 
				attr.atime=buf.getInt();
			}
			if((attr.flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0)
			{ 
				attr.mtime=buf.getInt(); 
			}
			if((attr.flags&SSH_FILEXFER_ATTR_EXTENDED)!=0)
			{
				int count=buf.getInt();
				if(count>0)
				{
					attr.extended=new String[count*2];
					for(int i=0; i<count; i++)
					{
						attr.extended[i*2]=Util.getString(buf.getString());
						attr.extended[i*2+1]=Util.getString(buf.getString());
					}
				}
			}
			return attr;
		} 

		internal int Length()
		{
			return length();
		}

		internal int length()
		{
			int len=4;

			if((flags&SSH_FILEXFER_ATTR_SIZE)!=0){ len+=8; }
			if((flags&SSH_FILEXFER_ATTR_UIDGID)!=0){ len+=8; }
			if((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0){ len+=4; }
			if((flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0){ len+=8; }
			if((flags&SSH_FILEXFER_ATTR_EXTENDED)!=0)
			{
				len+=4;
				int count=extended.Length/2;
				if(count>0)
				{
					for(int i=0; i<count; i++)
					{
						len+=4; len+=extended[i*2].Length;
						len+=4; len+=extended[i*2+1].Length;
					}
				}
			}
			return len;
		}

		internal void dump(Buffer buf)
		{
			buf.putInt(flags);
			if((flags&SSH_FILEXFER_ATTR_SIZE)!=0){ buf.putLong(size); }
			if((flags&SSH_FILEXFER_ATTR_UIDGID)!=0)
			{
				buf.putInt(uid); buf.putInt(gid);
			}
			if((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0)
			{ 
				buf.putInt(permissions);
			}
			if((flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0){ buf.putInt(atime); }
			if((flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0){ buf.putInt(mtime); }
			if((flags&SSH_FILEXFER_ATTR_EXTENDED)!=0)
			{
				int count=extended.Length/2;
				if(count>0)
				{
					for(int i=0; i<count; i++)
					{
						buf.putString(Util.getBytes(extended[i*2]));
						buf.putString(Util.getBytes(extended[i*2+1]));
					}
				}
			}
		}
		internal void setFLAGS(int flags)
		{
			this.flags=flags;
		}
		public void setSIZE(long size)
		{
			flags|=SSH_FILEXFER_ATTR_SIZE;
			this.size=size;
		}
		public void setUIDGID(int uid, int gid)
		{
			flags|=SSH_FILEXFER_ATTR_UIDGID;
			this.uid=uid;
			this.gid=gid;
		}
		public void setACMODTIME(int atime, int mtime)
		{
			flags|=SSH_FILEXFER_ATTR_ACMODTIME;
			this.atime=atime;
			this.mtime=mtime;
		}
		public void setPERMISSIONS(int permissions)
		{
			flags|=SSH_FILEXFER_ATTR_PERMISSIONS;
			permissions=(this.permissions&~pmask)|(permissions&pmask);
			this.permissions=permissions;
		}

		public bool isDir()
		{
			return ((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0 && 
				((permissions&S_IFDIR)==S_IFDIR));
		}      
		public bool isLink()
		{
			return ((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0 && 
				((permissions&S_IFLNK)==S_IFLNK));
		}
		public int getFlags() { return flags; }
		public long getSize() { return size; }
		public int getUId() { return uid; }
		public int getGId() { return gid; }
		public int getPermissions() { return permissions; }
		public int getATime() { return atime; }
		public int getMTime() { return mtime; }
		public String[] getExtended() { return extended; }

		public String toString() 
		{
			return (getPermissionsString()+" "+getUId()+" "+getGId()+" "+getSize()+" "+getMtimeString());
		}
		/*
		public String toString(){
		  return (((flags&SSH_FILEXFER_ATTR_SIZE)!=0) ? ("size:"+size+" ") : "")+
				 (((flags&SSH_FILEXFER_ATTR_UIDGID)!=0) ? ("uid:"+uid+",gid:"+gid+" ") : "")+
				 (((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0) ? ("permissions:0x"+Integer.toHexString(permissions)+" ") : "")+
				 (((flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0) ? ("atime:"+atime+",mtime:"+mtime+" ") : "")+
				 (((flags&SSH_FILEXFER_ATTR_EXTENDED)!=0) ? ("extended:?"+" ") : "");
		}
		*/
	}

}