1 17 package org.alfresco.filesys.smb.dcerpc.info; 18 19 import org.alfresco.filesys.smb.dcerpc.DCEBuffer; 20 import org.alfresco.filesys.smb.dcerpc.DCEBufferException; 21 import org.alfresco.filesys.smb.dcerpc.DCEReadable; 22 import org.alfresco.filesys.smb.dcerpc.DCEWriteable; 23 24 29 public class ShareInfo implements DCEWriteable, DCEReadable 30 { 31 32 34 public static final int InfoLevel0 = 0; 35 public static final int InfoLevel1 = 1; 36 public static final int InfoLevel2 = 2; 37 public static final int InfoLevel502 = 502; 38 public static final int InfoLevel1005 = 1005; 39 40 42 public static final int Disk = 0x00000000; 43 public static final int PrintQueue = 0x00000001; 44 public static final int Device = 0x00000002; 45 public static final int IPC = 0x00000003; 46 public static final int Hidden = 0x80000000; 47 48 50 public static final int Read = 0x01; 51 public static final int Write = 0x02; 52 public static final int Create = 0x04; 53 public static final int Execute = 0x08; 54 public static final int Delete = 0x10; 55 public static final int Attrib = 0x20; 56 public static final int Perm = 0x40; 57 public static final int All = 0x7F; 58 59 61 private int m_infoLevel; 62 63 65 private String m_name; 66 private int m_type; 67 private String m_comment; 68 69 private int m_permissions; 70 private int m_maxUsers; 71 private int m_curUsers; 72 private String m_path; 73 private String m_password; 74 75 private int m_flags; 76 77 80 public ShareInfo() 81 { 82 } 83 84 89 public ShareInfo(int lev) 90 { 91 m_infoLevel = lev; 92 } 93 94 102 public ShareInfo(int lev, String name, int typ, String comment) 103 { 104 m_infoLevel = lev; 105 m_name = name; 106 m_type = typ; 107 m_comment = comment; 108 } 109 110 115 public final int getInformationLevel() 116 { 117 return m_infoLevel; 118 } 119 120 125 public final String getName() 126 { 127 return m_name; 128 } 129 130 135 public final int getType() 136 { 137 return m_type; 138 } 139 140 145 public final int getFlags() 146 { 147 return m_flags; 148 } 149 150 155 public final boolean isHidden() 156 { 157 return (m_type & Hidden) != 0 ? true : false; 158 } 159 160 165 public final boolean isDisk() 166 { 167 return (m_type & 0x0000FFFF) == Disk ? true : false; 168 } 169 170 175 public final boolean isPrinter() 176 { 177 return (m_type & 0x0000FFFF) == PrintQueue ? true : false; 178 } 179 180 185 public final boolean isDevice() 186 { 187 return (m_type & 0x0000FFFF) == Device ? true : false; 188 } 189 190 195 public final boolean isNamedPipe() 196 { 197 return (m_type & 0x0000FFFF) == IPC ? true : false; 198 } 199 200 205 public final int getPermissions() 206 { 207 return m_permissions; 208 } 209 210 215 public final int getMaximumUsers() 216 { 217 return m_maxUsers; 218 } 219 220 225 public final int getCurrentUsers() 226 { 227 return m_curUsers; 228 } 229 230 235 public final String getPath() 236 { 237 return m_path; 238 } 239 240 245 public final String getPassword() 246 { 247 return m_password; 248 } 249 250 255 public final String getTypeAsString() 256 { 257 258 String typ = ""; 259 switch (getType() & 0xFF) 260 { 261 case Disk: 262 typ = "Disk"; 263 break; 264 case PrintQueue: 265 typ = "Printer"; 266 break; 267 case Device: 268 typ = "Device"; 269 break; 270 case IPC: 271 typ = "IPC"; 272 break; 273 } 274 275 return typ; 276 } 277 278 283 public final String getComment() 284 { 285 return m_comment; 286 } 287 288 293 public final void setInformationLevel(int lev) 294 { 295 m_infoLevel = lev; 296 } 297 298 303 public final void setType(int typ) 304 { 305 m_type = typ; 306 } 307 308 313 public final void setFlags(int flags) 314 { 315 m_flags = flags; 316 } 317 318 323 public final void setName(String name) 324 { 325 m_name = name; 326 } 327 328 333 public final void setComment(String str) 334 { 335 m_comment = str; 336 } 337 338 343 public final void setPermissions(int perm) 344 { 345 m_permissions = perm; 346 } 347 348 353 public final void setMaximumUsers(int maxUsers) 354 { 355 m_maxUsers = maxUsers; 356 } 357 358 363 public final void setCurrentUsers(int curUsers) 364 { 365 m_curUsers = curUsers; 366 } 367 368 373 public final void setPath(String path) 374 { 375 m_path = path; 376 } 377 378 381 protected final void clearStrings() 382 { 383 384 386 m_name = null; 387 m_comment = null; 388 m_path = null; 389 m_password = null; 390 } 391 392 398 public void readObject(DCEBuffer buf) throws DCEBufferException 399 { 400 401 403 clearStrings(); 404 405 407 switch (getInformationLevel()) 408 { 409 410 412 case InfoLevel0: 413 m_name = buf.getPointer() != 0 ? "" : null; 414 break; 415 416 418 case InfoLevel1: 419 m_name = buf.getPointer() != 0 ? "" : null; 420 m_type = buf.getInt(); 421 m_comment = buf.getPointer() != 0 ? "" : null; 422 break; 423 424 426 case InfoLevel2: 427 m_name = buf.getPointer() != 0 ? "" : null; 428 m_type = buf.getInt(); 429 m_comment = buf.getPointer() != 0 ? "" : null; 430 m_permissions = buf.getInt(); 431 m_maxUsers = buf.getInt(); 432 m_curUsers = buf.getInt(); 433 m_path = buf.getPointer() != 0 ? "" : null; 434 m_password = buf.getPointer() != 0 ? "" : null; 435 break; 436 437 439 case InfoLevel502: 440 m_name = buf.getPointer() != 0 ? "" : null; 441 m_type = buf.getInt(); 442 m_comment = buf.getPointer() != 0 ? "" : null; 443 m_permissions = buf.getInt(); 444 m_maxUsers = buf.getInt(); 445 m_curUsers = buf.getInt(); 446 m_path = buf.getPointer() != 0 ? "" : null; 447 m_password = buf.getPointer() != 0 ? "" : null; 448 449 buf.skipBytes(4); 451 break; 453 } 454 } 455 456 462 public void readStrings(DCEBuffer buf) throws DCEBufferException 463 { 464 465 467 switch (getInformationLevel()) 468 { 469 470 472 case InfoLevel0: 473 if (getName() != null) 474 m_name = buf.getString(DCEBuffer.ALIGN_INT); 475 break; 476 477 479 case InfoLevel1: 480 if (getName() != null) 481 m_name = buf.getString(DCEBuffer.ALIGN_INT); 482 if (getComment() != null) 483 m_comment = buf.getString(DCEBuffer.ALIGN_INT); 484 break; 485 486 488 case InfoLevel2: 489 case InfoLevel502: 490 if (getName() != null) 491 m_name = buf.getString(DCEBuffer.ALIGN_INT); 492 if (getComment() != null) 493 m_comment = buf.getString(DCEBuffer.ALIGN_INT); 494 if (getPath() != null) 495 m_path = buf.getString(DCEBuffer.ALIGN_INT); 496 if (getPassword() != null) 497 m_password = buf.getString(DCEBuffer.ALIGN_INT); 498 break; 499 } 500 } 501 502 508 public void writeObject(DCEBuffer buf, DCEBuffer strBuf) 509 { 510 511 513 switch (getInformationLevel()) 514 { 515 516 518 case InfoLevel0: 519 buf.putPointer(true); 520 strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true); 521 break; 522 523 525 case InfoLevel1: 526 buf.putPointer(true); 527 buf.putInt(getType()); 528 buf.putPointer(true); 529 530 strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true); 531 strBuf.putString(getComment() != null ? getComment() : "", DCEBuffer.ALIGN_INT, true); 532 break; 533 534 536 case InfoLevel2: 537 buf.putPointer(true); 538 buf.putInt(getType()); 539 buf.putPointer(true); 540 buf.putInt(getPermissions()); 541 buf.putInt(getMaximumUsers()); 542 buf.putInt(getCurrentUsers()); 543 buf.putPointer(getPath() != null); 544 buf.putPointer(getPassword() != null); 545 546 strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true); 547 strBuf.putString(getComment() != null ? getComment() : "", DCEBuffer.ALIGN_INT, true); 548 if (getPath() != null) 549 strBuf.putString(getPath(), DCEBuffer.ALIGN_INT, true); 550 if (getPassword() != null) 551 strBuf.putString(getPassword(), DCEBuffer.ALIGN_INT, true); 552 break; 553 554 556 case InfoLevel502: 557 buf.putPointer(true); 558 buf.putInt(getType()); 559 buf.putPointer(true); 560 buf.putInt(getPermissions()); 561 buf.putInt(getMaximumUsers()); 562 buf.putInt(getCurrentUsers()); 563 buf.putPointer(getPath() != null); 564 buf.putPointer(getPassword() != null); 565 buf.putInt(0); buf.putPointer(false); 568 strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true); 569 strBuf.putString(getComment() != null ? getComment() : "", DCEBuffer.ALIGN_INT, true); 570 if (getPath() != null) 571 strBuf.putString(getPath(), DCEBuffer.ALIGN_INT, true); 572 if (getPassword() != null) 573 strBuf.putString(getPassword(), DCEBuffer.ALIGN_INT, true); 574 break; 575 576 578 case InfoLevel1005: 579 buf.putInt(getFlags()); 580 break; 581 } 582 } 583 584 589 public String toString() 590 { 591 StringBuffer str = new StringBuffer (); 592 593 str.append("["); 594 str.append(getName()); 595 str.append(":"); 596 str.append(getInformationLevel()); 597 str.append(":"); 598 599 if (getInformationLevel() == 1) 600 { 601 str.append("0x"); 602 str.append(Integer.toHexString(getType())); 603 str.append(","); 604 str.append(getComment()); 605 } 606 607 str.append("]"); 608 return str.toString(); 609 } 610 } 611 | Popular Tags |